Author Topic: ripping the event_addItem to use in a function  (Read 3039 times)

I know the ui name, and the datablock name, how would i rip this code to make it so i can use it in a function to add whatever to an inventory?

Code: [Select]
registerOutputEvent("Player", "addItem", "datablock ItemData", 1);

function Player::addItem(%player,%image,%client)
{
   for(%i = 0; %i < %player.getDatablock().maxTools; %i++)
   {
      %tool = %player.tool[%i];
      if(%tool == 0)
      {
         %player.tool[%i] = %image;
         %player.weaponCount++;
         messageClient(%client,'MsgItemPickup','',%i,%image);
         break;
      }
   }
}
« Last Edit: January 06, 2015, 09:48:52 PM by Waru »

transmitDatablocks();
I think that is right NOT sure.

%client.player.tool0 = fistItem.getID();
messageClient(%client, 'MsgItemPickup', '', 0, %client.player.tool[0]);

this works for me, but it doesn't have the same calculations for how many tools the client has like additem.

transmitDatablocks();
I think that is right NOT sure.
wtf

Anyway you can use the function from your post like this
Code: [Select]
%player.addItem(%image,%client);%image is the datablock name of the weapon "image"
%player and %client are self explanatory.

wtf

Anyway you can use the function from your post like this
Code: [Select]
%player.addItem(%image,%client);%image is the datablock name of the weapon "image"
%player and %client are self explanatory.

So if I wanted to add a sword to my inventory, it would be %player.addItem(%SwordImage,%client);?

So if I wanted to add a sword to my inventory, it would be %player.addItem(%SwordImage,%client);?
No because you haven't defined what %SwordImage is, define it or just put the sword image's name in there.

Don't do images. Do items for the event, since the slots use ItemData stuff instead of the imageData.

Example: nameToID(SwordItem)

Since this event cannot do name strings, it must have a nameToID.

Don't do images. Do items for the event, since the slots use ItemData stuff instead of the imageData.

Example: nameToID(SwordItem)

Since this event cannot do name strings, it must have a nameToID.
lol I realized that while helping him write the script.
you can also just use SwordItem.getId()

transmitDatablocks();
I think that is right NOT sure.
wtf
Take a look at the Subject, OP changed questions.
Quote
Re: way to load an addon with datablocks without restarting server?
As a suggestion, never change the subject in coding help, it can really get confusing such as in this case right here.

As a suggestion, never change the subject in coding help, it can really get confusing such as in this case right here.

haha. sorry. I would be spamming the coding help board if i didn't just change the subject because I have a lot of questions.

now i have

Code: [Select]
function serverCmdAddSword(%client)
{
    if(isObject(%client.player))
    {
        %player = %client.player;
        %player.addItem(SwordItem.getID(),%client);
    }
}

but how would i get the "sword" part of
Code: [Select]
%player.addItem(SwordItem.getID(),%client);to be a variable?

Take a look at the Subject, OP changed questions.As a suggestion, never change the subject in coding help, it can really get confusing such as in this case right here.
Don't overwrite the original question either. Post new questions as a new reply
Also, don't lock coding help threads. Someone could come along with a better solution, but they can't post it if you locked the thread
« Last Edit: January 07, 2015, 12:24:44 AM by Headcrab Zombie »

now i have

Code: [Select]
function serverCmdAddSword(%client)
{
    if(isObject(%client.player))
    {
        %player = %client.player;
        %player.addItem(SwordItem.getID(),%client);
    }
}

but how would i get the "sword" part of
Code: [Select]
%player.addItem(SwordItem.getID(),%client);to be a variable?

You don't need to turn the "sword" into a variable if that's the only thing your function will add.
Also on a preference level you should either do if(isObject(%player = %client.player)) or put the %player = %client.player; before the if and just use %player

Using ID.getID() will have errors in the console if it is missing. Maybe have a check inside the addItem function to see if the item event exists, and hoping the class is an ItemData.

You don't need to turn the "sword" into a variable if that's the only thing your function will add.

It isn't the only thing my function will add.

that's why i need it to be a variable.