Author Topic: Help with adding a tool to a player  (Read 567 times)

I've tried calling the addItem event from a script and in the console, but  I haven't found a way to give  a tool to a client. I looked at another topic, and tried using this:
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 ++;
}
}

function utdmAddWeapon(%client, %itemData)
{
%max = %client.player.getDatablock().maxTools;
for(%i=0;%i<%max;%i++)
{
if(!%client.player.slot[%i])
{
%client.forceEquip(%client, %i, %itemData.getId());
break;
}
}
}
Sorry about the uneven indentation. I copied this from my phone.
%itemData is the ItemData datablock.. Example: GunItem or gc_rpg7Item.
So can somebody please help me make it work?
I suspect that
Code: [Select]
%client.forceEquip  should  not  have a %client as  the first argument.
« Last Edit: April 27, 2013, 09:35:42 AM by hammereditor² »

Ah, that's my code :)

Code: [Select]
%client.forceEquip(0,nameToID(hammerItem));
You need to convert the item's name to an ID for some reason.

Ah, that's my code :)

Code: [Select]
%client.forceEquip(0,nameToID(hammerItem));
You need to convert the item's name to an ID for some reason.
Thank you; it adds the item!
But, unfortunately, even with the loop in utdmAddWeapon(), it just shoves the weapon into the first slot.
The loop doesn't seem to be working. It's not finding an empty slot.
So how do I know if a slot is empty? Will it show up as %client.player.tool[7] == 0?

Change this:
Code: [Select]
if(!%client.player.slot[%i])
to this:
Code: [Select]
if(!isObject(%client.player.tool[%i]))

Change this:
Code: [Select]
if(!%client.player.slot[%i])
to this:
Code: [Select]
if(!isObject(%client.player.tool[%i]))
Nvm, I fixed it myself.