Hook touching weaponbox/armoury_entity using ReAPI

Helping Topics
Post Reply
User avatar
Raheem
Mod Developer
Mod Developer
Posts: 2214
Joined: 7 years ago
Contact:

Hook touching weaponbox/armoury_entity using ReAPI

#1

Post by Raheem » 5 years ago

Hello,

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: - When this function called HasRestrictItem?
  • It's called in 3 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.
- We are interested in: When the player touches with a weaponbox or armoury_entity.

- 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: - id --> is the player who touched the weaponbox or armoury_entity.
- iItem --> The item that player touched (It's in cssdk_const.inc)
    1. /**
    2. * Constant items
    3. */
    4. enum ItemID
    5. {
    6.     ITEM_NONE = -1,
    7.     ITEM_SHIELDGUN,
    8.     ITEM_P228,
    9.     ITEM_GLOCK,
    10.     ITEM_SCOUT,
    11.     ITEM_HEGRENADE,
    12.     ITEM_XM1014,
    13.     ITEM_C4,
    14.     ITEM_MAC10,
    15.     ITEM_AUG,
    16.     ITEM_SMOKEGRENADE,
    17.     ITEM_ELITE,
    18.     ITEM_FIVESEVEN,
    19.     ITEM_UMP45,
    20.     ITEM_SG550,
    21.     ITEM_GALIL,
    22.     ITEM_FAMAS,
    23.     ITEM_USP,
    24.     ITEM_GLOCK18,
    25.     ITEM_AWP,
    26.     ITEM_MP5N,
    27.     ITEM_M249,
    28.     ITEM_M3,
    29.     ITEM_M4A1,
    30.     ITEM_TMP,
    31.     ITEM_G3SG1,
    32.     ITEM_FLASHBANG,
    33.     ITEM_DEAGLE,
    34.     ITEM_SG552,
    35.     ITEM_AK47,
    36.     ITEM_KNIFE,
    37.     ITEM_P90,
    38.     ITEM_NVG,
    39.     ITEM_DEFUSEKIT,
    40.     ITEM_KEVLAR,
    41.     ITEM_ASSAULT,
    42.     ITEM_LONGJUMP,
    43.     ITEM_SODACAN,
    44.     ITEM_HEALTHKIT,
    45.     ITEM_ANTIDOTE,
    46.     ITEM_BATTERY
    47. };
- iType --> The type of event (Buy, touch, or equip? can be found in cssdk_const.inc)
    1. /**
    2. * For RG_CBasePlayer_HasRestrictItem
    3. */
    4. enum ItemRestType
    5. {
    6.     ITEM_TYPE_BUYING,  // When a player is buying items
    7.     ITEM_TYPE_TOUCHED, // When the player touches a weaponbox or armoury_entity
    8.     ITEM_TYPE_EQUIPPED // When an entity game_player_equip gives item to player or default items on player spawn
    9. };
3. You can block any item pickup:

- Code to block pickup HE Grenade:
    1. #include <amxmodx>
    2. #include <reapi>
    3.  
    4. #define ITEM_TO_BLOCK ITEM_HEGRENADE
    5.  
    6. public plugin_init()
    7. {
    8.     register_plugin("Block HE Grenade Pickup", "1.0", "Raheem")
    9.    
    10.     /*
    11.     *   This can hook 3 types of events:
    12.     *
    13.     *   1. When a player buying items.
    14.     *   2. When the player touches with a weaponbox or armoury_entity.
    15.     *   3. When a entity game_player_equip to player gives item.
    16.     */
    17.     RegisterHookChain(RG_CBasePlayer_HasRestrictItem, "Fw_HasRestrictItem_Pre", 0)
    18. }
    19.  
    20. /*
    21. *   id - Player index
    22. *   iItem - Item id (It's ITEM_NONE, ITEM_SHIELDGUN and etc...)
    23. *   iType:
    24. *           0 = ITEM_TYPE_BUYING    // When a player buying items.
    25. *           1 = ITEM_TYPE_TOUCHED   // When the player touches with a weaponbox or armoury_entity.
    26. *           2 = ITEM_TYPE_EQUIPPED  // When a entity game_player_equip to player gives item.
    27. *
    28. *   You can find in cssdk_const.inc enum ItemRestType
    29. *   Check also enum ItemID for weapons ids
    30. */  
    31. public Fw_HasRestrictItem_Pre(id, ItemID:iItem, ItemRestType:iType)
    32. {
    33.     // Hook only player touching
    34.     if (iType == ITEM_TYPE_TOUCHED)
    35.     {
    36.         // Check if player not VIP and iItem is Armor
    37.         if (iItem == ITEM_TO_BLOCK)
    38.         {
    39.             // Print center message and exist from the real function, no give
    40.             client_print(id, print_center, "You can't pickup HE grenade!")
    41.            
    42.             // Set the hookchain return (must set the return, if you just returned HC_SUPERCEDE it will not work)
    43.             SetHookChainReturn(ATYPE_BOOL, HC_SUPERCEDE) // HC_SUPERCEDE = true
    44.            
    45.             // Useless to use return, we already returned using SetHookChainReturn
    46.             //return HC_SUPERCEDE
    47.         }
    48.     }
    49.    
    50.     // No problem with this, will work normally
    51.     return HC_CONTINUE
    52. }
IMPORTANT: Please use SetHookChainReturn() to return HC_SUPERCEDE, and don't use return HC_SUPERCEDE. For HC_CONTINUE use it normally like: return HC_CONTINUE.

BLOCKED?
  • Blocked.png

That's ALL, hope you find this useful. Any problem comment down :)
He who fails to plan is planning to fail

User avatar
z0h1r-LK
Mod Developer
Mod Developer
Morocco
Posts: 476
Joined: 5 years ago
Location: The Red City ❤
Contact:

#2

Post by z0h1r-LK » 1 year ago

Nice tutorial ♥

Post Reply

Create an account or sign in to join the discussion

You need to be a member in order to post a reply

Create an account

Not a member? register to join our community
Members can start their own topics & subscribe to topics
It’s free and only takes a minute

Register

Sign in

Who is online

Users browsing this forum: No registered users and 2 guests