Author Topic: Add Item To Inventory By Server Command  (Read 1524 times)

Can Someone Help Me Code A Script That Will Let Me Type: /weapon ak47, And It'll Add The ak47 to my Inventory

It'd be easier if you typed the datablock name of the image, such as /weapon ak47Image. Otherwise I think you would need to do a loop through every weapon to check if the ui name matched up. Someone correct me if I'm wrong though, as I'm not fully sure about this.

Also, Talking With Caps On Every Letter Doesn't Make Your Grammar Look Better, It's Actually Quite Annoying In My Opinion.

srry its, a habit... and yea it would be easier

It'd be easier if you typed the datablock name of the image, such as /weapon ak47Image. Otherwise I think you would need to do a loop through every weapon to check if the ui name matched up. Someone correct me if I'm wrong though, as I'm not fully sure about this.
You could try a few things to do this.
1. Attempt to find an image by adding "image" or "item" to the end of what was entered.
2. Looping through all datablocks and creating an array containing the uinames of all items.

could be better but here's the jist of it:

Code: [Select]
function serverCmdWeapon(%client, %uiName)
{
   %player = %client.player;
   if(!isObject(%client.player) || %uiName $= "")
      return;

   for(%i = 0; %i < DataBlockGroup.getCount(); %i++)
   {
      %obj = DataBlockGroup.getObject(%i);

      if(%obj.getClassName() $= "ItemData" && strStr(strlwr(%obj.uiName), strlwr(%uiName)) != -1)
      {
         %item = %obj;
         break;
      }
   }

   if(!isObject(%item)) //item not found
      return;

   for(%i = 0; %i < %player.dataBlock.maxTools; %i++)
   {
      if(%player.tool[%i] == %item)
         return;

      if(!%player.tool[%i])
      {
         %slot = %i;
         break;
      }
   }

   if(%slot $= "") //no tool slots available
      return;

   %player.tool[%slot] = %item;
   messageClient(%client, 'MsgItemPickup', "", %slot, %item);
}

use as /weapon shotgun, /weapon rocket etc.