In this topic i'll show you how can you detect the touching of weaponbox/armoury_entity event using ReAPI hookchains.
1. You need to register the hookchain:
- RegisterHookChain(RG_CBasePlayer_HasRestrictItem, "Fw_HasRestrictItem_Pre", 0)
- It's called in 3 events:
- When a player buying items.
- When the player touches with a weaponbox or armoury_entity.
- When a entity game_player_equip to player gives item.
- You can note that i registred the hookchain in pre case, so we can control the return value and be able to block the pickup event.
2. Let's discuss
Fw_HasRestrictItem_Pre
header:
- public Fw_HasRestrictItem_Pre(id, ItemID:iItem, ItemRestType:iType)
- iItem --> The item that player touched (It's in cssdk_const.inc)
- /**
- * Constant items
- */
- enum ItemID
- {
- ITEM_NONE = -1,
- ITEM_SHIELDGUN,
- ITEM_P228,
- ITEM_GLOCK,
- ITEM_SCOUT,
- ITEM_HEGRENADE,
- ITEM_XM1014,
- ITEM_C4,
- ITEM_MAC10,
- ITEM_AUG,
- ITEM_SMOKEGRENADE,
- ITEM_ELITE,
- ITEM_FIVESEVEN,
- ITEM_UMP45,
- ITEM_SG550,
- ITEM_GALIL,
- ITEM_FAMAS,
- ITEM_USP,
- ITEM_GLOCK18,
- ITEM_AWP,
- ITEM_MP5N,
- ITEM_M249,
- ITEM_M3,
- ITEM_M4A1,
- ITEM_TMP,
- ITEM_G3SG1,
- ITEM_FLASHBANG,
- ITEM_DEAGLE,
- ITEM_SG552,
- ITEM_AK47,
- ITEM_KNIFE,
- ITEM_P90,
- ITEM_NVG,
- ITEM_DEFUSEKIT,
- ITEM_KEVLAR,
- ITEM_ASSAULT,
- ITEM_LONGJUMP,
- ITEM_SODACAN,
- ITEM_HEALTHKIT,
- ITEM_ANTIDOTE,
- ITEM_BATTERY
- };
- /**
- * For RG_CBasePlayer_HasRestrictItem
- */
- enum ItemRestType
- {
- ITEM_TYPE_BUYING, // When a player is buying items
- ITEM_TYPE_TOUCHED, // When the player touches a weaponbox or armoury_entity
- ITEM_TYPE_EQUIPPED // When an entity game_player_equip gives item to player or default items on player spawn
- };
- Code to block pickup HE Grenade:
- #include <amxmodx>
- #include <reapi>
- #define ITEM_TO_BLOCK ITEM_HEGRENADE
- public plugin_init()
- {
- register_plugin("Block HE Grenade Pickup", "1.0", "Raheem")
- /*
- * This can hook 3 types of events:
- *
- * 1. When a player buying items.
- * 2. When the player touches with a weaponbox or armoury_entity.
- * 3. When a entity game_player_equip to player gives item.
- */
- RegisterHookChain(RG_CBasePlayer_HasRestrictItem, "Fw_HasRestrictItem_Pre", 0)
- }
- /*
- * id - Player index
- * iItem - Item id (It's ITEM_NONE, ITEM_SHIELDGUN and etc...)
- * iType:
- * 0 = ITEM_TYPE_BUYING // When a player buying items.
- * 1 = ITEM_TYPE_TOUCHED // When the player touches with a weaponbox or armoury_entity.
- * 2 = ITEM_TYPE_EQUIPPED // When a entity game_player_equip to player gives item.
- *
- * You can find in cssdk_const.inc enum ItemRestType
- * Check also enum ItemID for weapons ids
- */
- public Fw_HasRestrictItem_Pre(id, ItemID:iItem, ItemRestType:iType)
- {
- // Hook only player touching
- if (iType == ITEM_TYPE_TOUCHED)
- {
- // Check if player not VIP and iItem is Armor
- if (iItem == ITEM_TO_BLOCK)
- {
- // Print center message and exist from the real function, no give
- client_print(id, print_center, "You can't pickup HE grenade!")
- // Set the hookchain return (must set the return, if you just returned HC_SUPERCEDE it will not work)
- SetHookChainReturn(ATYPE_BOOL, HC_SUPERCEDE) // HC_SUPERCEDE = true
- // Useless to use return, we already returned using SetHookChainReturn
- //return HC_SUPERCEDE
- }
- }
- // No problem with this, will work normally
- return HC_CONTINUE
- }
BLOCKED?
That's ALL, hope you find this useful. Any problem comment down