Author Topic: Giving A Player A Item  (Read 1928 times)

How would I Make my mod (Killstreaks) make it when the client gets the matching kills, it gives them a item?

This little piece of code will check if the player has a slot for the new item. If they do, it will give them the item. Also it's not my code, I can't remember where I got it.

Code: [Select]
for(%a=0;%a<%client.player.getDatablock().maxTools;%a++)
{
%tool = %player.tool[%a];
if(!isObject(tool))
{
%client.player.tool[%a] = nametoID(gunItem); //Edit the items name in here...
%client.weaponcount++;
messageclient(%client,'MsgItemPickup','',%a,nametoID(gunItem); //Edit the items name in here... x2
}
}

Edit: Fixed.
« Last Edit: February 18, 2013, 12:44:27 AM by Honorabl3 »

Change if(%tool == 0) to if(!isObject(%tool)).

Also, 'msgitempickup' should be 'MsgItemPickup'. Tagged strings are case-sensitive.

Change if(%tool == 0) to if(!isObject(%tool)).

Also, 'msgitempickup' should be 'MsgItemPickup'. Tagged strings are case-sensitive.
This little piece of code will check if the player has a slot for the new item. If they do, it will give them the item. Also it's not my code, I can't remember where I got it.

Code: [Select]
for(%a=0;%a<%client.player.getDatablock().maxTools;%a++)
{
%tool = %player.tool[%a];
if(!isObject(tool))
{
%client.player.tool[%a] = nametoID(gunItem); //Edit the items name in here...
%client.weaponcount++;
messageclient(%client,'MsgItemPickup','',%a,nametoID(gunItem); //Edit the items name in here... x2
}
}

Edit: Fixed.

Ok, where would I put this compared to this?
Code: [Select]
                                messageAll('',"\c3"@%killer.name@"\c6 has \c0FOUR KILLS IN A ROW\c6!");
And yes I have all the brackets and kill check junk it the rest. My iPad wouldn't let me copy it all.

Code: [Select]
if(%yourifstatement) //Change this if statement to match the one where message all is shown..
{
messageAll('',"\c3"@%killer.name@"\c6 has \c0FOUR KILLS IN A ROW\c6!"); //The "for" goes next to the original message.

for(%a=0;%a<%client.player.getDatablock().maxTools;%a++)
{
%tool = %player.tool[%a];
if(!isObject(%tool))
{
%client.player.tool[%a] = nametoID(gunItem); //Edit the items name in here...
%client.weaponcount++;
messageclient(%client,'MsgItemPickup','',%a,nametoID(gunItem); //Edit the items name in here... x2
             break;
}
}
}
« Last Edit: February 19, 2013, 02:43:22 PM by Honorabl3 »

Code: [Select]
if(!isObject(tool))
Should be
if(!isObject(%tool))

Oh, and wouldn't you need a break in there to stop it from filling in all your blank inventory spaces?
« Last Edit: February 19, 2013, 08:28:07 AM by boodals 2 »

Oh, and wouldn't you need a break in there to stop it from filling in all your blank inventory spaces?
Yes you would.

Oh, and wouldn't you need a break in there to stop it from filling in all your blank inventory spaces?

Where would i put these "spaces"?


Honorabl3's latest edited code seems fine. Haven't tested though.

Here's an optimized version of the above in function form.

Code: [Select]
function player::addItem( %this, %tool )
{
if ( !isObject( %tool ) )
{
return;
}

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

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

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

break;
}
}
}
« Last Edit: February 22, 2013, 03:03:46 AM by Port »

Here's an optimized version of the above in function form.

Code: [Select]
function player::addItem( %this, %tool )
{
if ( !isObject( %tool ) )
{
return;
}

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

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

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

break;
}
}
}

Unknown command "get datablock"... how to fix?

Unknown command "get datablock"... how to fix?
Post the full error and/or how you're using this.

Post the full error and/or how you're using this.

I had a command on a GUI to make this function go.

function player::addItem( %this, %tool )
{
   if ( !isObject( %tool ) )
   {
      return;
   }

   %tool = %item.getID(gunItem);<---Where I thought you would put the item   %slots = %this.getDataBlock().maxTools;

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

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

         break;
      }
   }
}

I had a command on a GUI to make this function go.
Yeah, you're apparently trying to call this on the client side, and I guess not even calling it as a method? Also, getID doesn't work like that. It's a method of %item, which is a variable. Copy-paste and guesswork will only get you so far.