Author Topic: Player::giveTool not functioning (oddly)  (Read 711 times)

   function Player::giveTool(%this,%image)
   {
      if(getWordCount(%image) == 1)
      {
         for(%i = 0; %i < %this.getDatablock().maxTools; %i++)
         {
            %tool = %this.tool[%i];
            talk(%tool);
            if(!%tool)
            {
               %this.tool[%i] = %image;
               %this.weaponCount++;
               messageClient(%this.client,'MsgItemPickup','',%i,%image.getID());
               break;
            }
         }
      }
      else
      {
         for(%j=0;%j<getWordCount(%image);%j++)
         {
            %img = getWord(%image,%j);
            for(%i = 0; %i < %this.getDatablock().maxTools; %i++)
            {
               %tool = %this.tool[%i];
               if(!%tool)
               {
                  %this.tool[%i] = %img;
                  %this.weaponCount++;
                  messageClient(%this.client,'MsgItemPickup','',%i,%img.getID());
                  break;
               }
            }
         }
      }
   }


There are no console errors. Though when I call
findclientbyname(brian).player.giveTool("hammerItem");
it does not work.

edit: adding in the messageClient .getID(), it makes it so it appears in my tools, but opening it nothing shows up in my hand.
« Last Edit: October 14, 2013, 08:49:42 PM by 0xBRIANSMITH »

%this.tool[%i] = %img.tool.getID();
it all has to be a tool

I'm not sure what your function is doing exactly but this is what I use to give players tools.

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

%item = (isObject(%item) ? %item.getID() : 0);

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

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

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

function Player::giveTool(%this, %tool) {
   if (!isObject(%tool) || %tool.getClassName() !$= "ItemData") {
      error("ERROR: Invalid tool given.");
   }

   %tool = %tool.getID();
   %slots = %this.getDataBlock().maxTools;

   for (%i = 0; %i < %slots; %i++) {
      if (!isObject(%this.tool[%i])) {
         %this.tool[%i] = %tool;

         if (isObject(%this.client)) {
            messageClient(%this.client, 'MsgItemPickup', '', %i, %tool, true);
         }

         return true;
      }
   }

   return false;
}