It works fine it because of your usage. You can't use it on the weaponbox entity. You have to use it on the weapon itself. So you need to search for the actually weapon entity index.
Code:
#include <amxmodx>
#include <fakemeta>
#include <cstrike>
new g_hTouch = 0
public plugin_init()
{
g_hTouch = register_forward(FM_Touch, "onTouch")
}
public plugin_end()
{
if(g_hTouch) {
unregister_forward(FM_Touch, g_hTouch)
g_hTouch = 0
}
}
public onTouch(eid, pid)
{
if(!eid) return FMRES_IGNORED
if(isWeapon(eid))
{
new ent = FindEntityByOwner(eid)
if(ent)
{
server_print("[AMXX] cs_get_weapon_id(%d) = %d", eid, cs_get_weapon_id(ent))
}
}
return FMRES_IGNORED
}
stock FindEntityByOwner(owner)
{
new i;
for(i = get_maxplayers() + 1; i < global_get(glb_maxEntities); i++)
{
if(pev(i, pev_owner) == owner)
{
break;
}
}
return i;
}
stock bool:isWeapon(ent_id)
{
static pStr
static sBuffer[11] // sizeof("weaponbox") + 1
pev(ent_id, pev_classname, pStr, sBuffer, sizeof(sBuffer)-1)
server_print("%s", sBuffer);
return bool:equal(sBuffer, "weaponbox")
}
__________________