How do I give someone an item via the console?

Author Topic: How do I give someone an item via the console?  (Read 908 times)

That's all.
It can be adding it to their inventory and/or just making them temporarily holding it, just tell me how.

Adding it to their inventory may or may not be complicated based on add-ons present.
If you have the addItem event, you can just do findClientByName("name").player.addItem(gunItem);
I don't quite remember the few lines you have to do otherwise. Might also be able to use the ::pickup code or whatever it is.

As for temporarily holding, findClientByName("name").player.mountImage(gunImage,0);

findclientbyname("name").player.mountImage(<image datablock>, 0); will put the item in their hand.
findclientbyname("name").player.playThread(1, armReadyRight); will raise the right hand.

Once they close their inventory or switch away they wont be holding the item anymore though. This should put an item in someone's inventory, however there may be a less complicated way:

findclientbyname("name").player.tool[<inventory slot>] = nameToID("<item datablock name>");
messageClient(findclientbyname("name"), 'MsgItemPickup', '', <inventory slot>, nameToID("<item datablock name>"));

you also should increment %pl.weaponCount iirc

maybe mocha can post the onCollision code? ill pm him

The addItem event foolishly uses the %client variable as the last parameter on the event when being delcared like this: Player::addItem(%player, %image, %client). This causes anyone who wants to use it outside of the event to have to do %player.addItem(wrenchItem, %player.client);

This is how I go about adding items to players:
Code: [Select]
for(%i = 0; %i < %this.getDatablock().maxTools; %i++)
{
%tool = %this.tool[%i];
if(%tool == 0)
{
%this.tool[%i] = %item;
%this.weaponCount++;
messageClient(%cl, 'MsgItemPickup', '', %i, %item);
break;
}
}
If you don't understand what that's doing I'll explain. It does a for loop for the amount of slots the player's playerType data has and looks for a slot that doesn't have an item in it (%tool being 0). If it finds one, it sets the tool to be that item data and uses messageClient so the client knows it has the item.

%this being the player object.
« Last Edit: June 13, 2017, 01:53:19 PM by Crøwn »

findclientbyname("name").player.mountImage(<image datablock>, 0); will put the item in their hand.
findclientbyname("name").player.playThread(1, armReadyRight); will raise the right hand.
I'll use this.