I tried getting the weapon entity index the simplest way using find_ent_by_owner(), but this was returning 0 because the owner of the weapon is not yet established when the WeapPickup event is called. You could use WeapPickup with a 0.1 delay via set_task(), which works, but I don't like the idea of calling set_task() over and over again.
There are probably simpler ways, but this is what I threw together
PHP Code:
#include <amxmodx>
#include <hamsandwich>
#include <engine>
#include <cstrike>
new const Version [] = "0.1";
new const m_rgpPlayerItems_CWeaponBox[ 6 ] = { 34 , 35 , ... };
const XO_WEAPONBOX = 4;
new g_TouchedWeaponbox[ MAX_PLAYERS + 1 ];
public plugin_init()
{
register_plugin( "Weapon Pickup" , Version , "bugsy" );
register_touch( "weaponbox" , "player" , "PlayerTouchWeaponbox" );
RegisterHam( Ham_AddPlayerItem , "player", "AddPlayerItem" );
}
public PlayerTouchWeaponbox( iWeaponbox , iPlayer )
{
new iWeapon;
for ( new iSlot = 1 ; iSlot <= 2 ; iSlot++ )
{
if ( ( iWeapon = get_pdata_cbase( iWeaponbox , m_rgpPlayerItems_CWeaponBox[ iSlot ] , XO_WEAPONBOX ) ) > 0 )
break;
}
g_TouchedWeaponbox[ iPlayer ] = iWeapon;
}
public AddPlayerItem( id , iWeaponEntity )
{
if ( g_TouchedWeaponbox[ id ] == iWeaponEntity )
{
new szName[ 32 ] , szWeaponName[ 24 ] , iWeaponID = cs_get_weapon_id( iWeaponEntity );
get_user_name( id , szName , charsmax( szName ) );
get_weaponname( iWeaponID , szWeaponName , charsmax( szWeaponName ) );
client_print( 0 , print_chat , "%s picked up %s weapon, CSW_ id = %d, entity id = %d" , szName , szWeaponName[ 7 ] , iWeaponID , iWeaponEntity );
g_TouchedWeaponbox[ id ] = 0;
}
}
__________________