Author Topic: Add to the player's inventory?  (Read 749 times)

%client.dump() seems to no longer be working for me. So, I'd like to ask: Is there a function that is part of %client.player that will allow me to add a tool/weapon to a certain slot?

Not by default. This is what I use:

Code: [Select]
function GameConnection::forceEquip(%this,%slot,%item)
{
%player = %this.player;
if(!isObject(%player))
return;

if(!isObject(%item))
%item = 0;

%oldTool = %player.tool[%slot];
%player.tool[%slot] = %item;

messageClient(%this,'MsgItemPickup','',%slot,%item);

if(!isObject(%oldTool))
%player.weaponCount ++;
}

Thanks.

Edit: Doesn't seem to work properly. It only shows the item in the player's inventory, it doesn't allow it to be used.
« Last Edit: February 22, 2012, 03:32:10 AM by Kaphonaits »

You did it like this? %client.forceEquip(3,nameToID(hammerItem));

You did it like this? %client.forceEquip(3,nameToID(hammerItem));
I believe names are resolved to object IDs before code is executed, making nameToID a needless extra step in this case.

Should be using .getID() instead of nameToID anyways.

I believe names are resolved to object IDs before code is executed, making nameToID a needless extra step in this case.
I seem to remember that this was a strange case in which you do need to use nameToID because you're just setting it to a variable. Try it with and without nameToId and see what happens. Pretty sure it works when using nameToID.

Should be using .getID() instead of nameToID anyways.
That causes errors if the item doesn't exist.

That causes errors if the item doesn't exist.
Don't use it with something that doesn't exist.

Don't use it with something that doesn't exist.
Or use nameToID and not have to do that? Logic.
I seem to remember that this was a strange case in which you do need to use nameToID because you're just setting it to a variable. Try it with and without nameToId and see what happens. Pretty sure it works when using nameToID.
That causes errors if the item doesn't exist.
500% sure that names will not work because the datablock IDs are what are used for the UI tables and such, so that's why you need to provide a datablock ID when using network functions. I haven't tried before though, it could work.

500% sure that names will not work because the datablock IDs are what are used for the UI tables and such, so that's why you need to provide a datablock ID when using network functions. I haven't tried before though, it could work.
Correct.

Or use nameToID and not have to do that? Logic.
Right, so instead of having an error come up to tell you the item doesn't exist, just do something to not have informative console lines.

Either one wont get you your result if the item doesn't exist.
The funniest part is the "not have to do that" part. Why would you want to call nameToID on something that doesn't exist on purpose?
« Last Edit: February 23, 2012, 12:09:35 AM by Chrono »

You did it like this? %client.forceEquip(3,nameToID(hammerItem));
I wasn't aware nameToID had to be used, or getID for that matter. It works now. Thanks.

Locked.