Also, some people keep hooking FM_Touch or pfn_touch when we know those forwards are called very ofen and are bad to hook for servers performances.
I've decided to use engine register_touch system rather than hooking Ham_Touch because engine is also filtering the toucher so it is better for performances.
With ham you would need to check toucher index range to be sure it is a player.
If in your plugin you are creating custom weaponbox or armouries, first make sure you use "weaponbox" and "armoury_entity" as classes to create entities and then you can set your custom class name, that custom name you gonna use in register_touch.
I've put some comments in code.
If you have more questions i gonna answer later in thread, and put back important answer in main post.
Last, if you want to block pickup, return PLUGIN_HANDLED, if you want to let the game decide, return PLUGIN_CONTINUE.
Code: Select all
#include < amxmodx >
#include < engine >
#include < hamsandwich >
#include < cstrike >
const XO_CWEAPONBOX = 4;
new const m_rgpPlayerItems_CWeaponBox[6] = {34,35,...};
public plugin_init()
{
new const PLAYER_CLASS[] = "player";
register_touch("armoury_entity", PLAYER_CLASS, "OnPlayerTouchArmoury");
register_touch("weaponbox", PLAYER_CLASS, "OnPlayerTouchWeaponBox");
register_touch("weapon_shield", PLAYER_CLASS, "OnPlayerTouchShield");
}
public OnPlayerTouchArmoury(ent, id)
{
new iId = cs_get_armoury_type(ent);
// player 'id' is gonna pickup armoury 'ent' weapon type 'iId'
// games may not give it if already owns weapon or armor
// note : iId can hold non weapon type : CSW_VEST and CSW_VESTHELM
// Weapons type that don't exist in armouries : famas, galil, ump45, sg550, all pistols, knife, c4
}
public OnPlayerTouchWeaponBox(ent, id)
{
new iId = GetWeaponBoxWeaponType( ent );
// player 'id' is gonna touch weaponbox 'ent' and be possibliy given weapon type 'iId'
// games may not give it if already owns weapon
// you may want to restrict all except c4, then :
// if( iId != CSW_C4 )
// {
// return PLUGIN_HANDLED;
// }
// return PLUGIN_CONTINUE;
}
public OnPlayerTouchShield(ent, id)
{
// player gonna possibly pickup a shield
}
GetWeaponBoxWeaponType( ent )
{
new weapon;
for(new i = 1; i<= 5; i++)
{
weapon = get_pdata_cbase(ent, m_rgpPlayerItems_CWeaponBox[i], XO_CWEAPONBOX);
if( weapon > 0 )
{
return cs_get_weapon_id(weapon);
}
}
return 0;
} 