Blockland Forums > Modification Help
Add to the player's inventory?
Kaphonaits:
%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?
Greek2me:
Not by default. This is what I use:
--- Code: ---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 ++;
}
--- End code ---
Kaphonaits:
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.
Greek2me:
You did it like this? %client.forceEquip(3,nameToID(hammerItem));
Slicksilver:
--- Quote from: Greek2me on February 22, 2012, 07:44:22 PM ---You did it like this? %client.forceEquip(3,nameToID(hammerItem));
--- End quote ---
I believe names are resolved to object IDs before code is executed, making nameToID a needless extra step in this case.