Author Topic: Compiled my coding questions into one topic for less spam. Updated:1/3/11  (Read 918 times)

How do i add a weapon to a player's inventory:

%p being a player object of course.

%p.tool[%slot] = nameToId(%item.getDataBlock());

%p.weaponCount++;

messageClient(%p.client,'MsgItemPickup','',%slot,nameToId(%item.getDataBlock()));

Code: [Select]
function player::setItem( %this, %index, %item )
{
%item = %item.getID();

%this.weaponCount += ( !isObject( %this.tool[ %index ] ) );
%this.tool[ %index ] = %item.;

messageClient( %this.client, 'MsgItemPickup', '', %index, %item );
}

function player::addItem( %this, %item )
{
%item = %item.getID();
%cnt = %player.getDataBlock().maxTools;

for ( %i = 0 ; %i < %cnt ; %i++ )
{
if ( !isObject( %this.tool[ %i ] ) )
{
%this.tool[ %i ] = %item;
%this.weaponCount++;
messageClient( %this.client, 'MsgItemPickup', '', %i, %item );
return true;
}
}
}