Detect weapon change with CurWeapon event filtered :
PHP Code:
#include <amxmodx>
enum _:CurWeapon_Structure {
CurWeapon_IsActive = 1,
CurWeapon_WeaponID,
CurWeapon_ClipAmmo
}
const MAX_PLAYERS = 32
new g_iCurWeapon[MAX_PLAYERS+1]
public plugin_init()
{
register_event("CurWeapon", "Event_CurWeapon", "be", "1=1")
}
public Event_CurWeapon( id )
{
new iCurWeapon = read_data( CurWeapon_WeaponID )
if( g_iCurWeapon[id] != iCurWeapon )
{
// player has switch from CSW_[ g_iCurWeapon[id] ] to CSW_[ iCurWeapon ]
g_iCurWeapon[id] = iCurWeapon
}
}
You could consider hamsandwich :
PHP Code:
#include <amxmodx>
#include <cstrike>
#include <hamsandwich>
const EXTRAOFFSET_WEAPON = 4
const m_pPlayer = 41
const EXTRAOFFSET_PLAYER = 5
const m_pLastItem = 375
public plugin_init()
{
new szWeaponName[32]
for(new i=CSW_P228; i<=CSW_P90; i++)
{
if( get_weaponname(i, szWeaponName, charsmax(szWeaponName)) )
{
RegisterHam(Ham_Item_Deploy, szWeaponName, "Weapon_Deploy_Post", 1)
}
}
}
public Weapon_Deploy_Post( iWeapon )
{
new bHasDeployed
GetOrigHamReturnInteger(bHasDeployed)
if( bHasDeployed )
{
new id = get_pdata_cbase(iWeapon, m_pPlayer, EXTRAOFFSET_WEAPON)
new CSW_ID = cs_get_weapon_id(iWeapon)
new iLastWeapon = get_pdata_cbase(id, m_pLastItem, EXTRAOFFSET_PLAYER)
if( iLastWeapon > 0 )
{
new iLastWeaponCSW_ID = cs_get_weapon_id(iLastWeapon)
}
// player has switch from CSW_[ iLastWeaponCSW_ID ] weapon entity [ iLastWeapon ] to CSW_[ CSW_ID ] weapon entity iWeapon
}
}
__________________