Ways to hook final trigger_hurt

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

Ways to hook final trigger_hurt

#1

Post by Raheem » 6 years ago

Hello,

Here i'm going to speak a little about trigger_hurt and how to catch it when it happens at end of the map, we are speaking about the final trigger_hurt that should kill all players except who escaped.

First let's take a general overview how zombie escape map works?
  • There is many scenarios like:

    First you press a button and then the targeted func_tracktrain or func_vehicle comes through the path_track then players enter inside the moving entity and they travels till players touch a regoin that defined as trigger_multiple and when this trigger_multiple is touched it will activate the trigger_hurt.

    Another idea is that the trigger_hurt is called by a button not trigger_multiple. Like after player go to safe zone they press a button and the trigger_hurt then activated through this button.

So to hook trigger_hurt, you will need to hook when player touching trigger_multiple or when player press the button that should activate the trigger_hurt.

Another idea is to check if any player touched a trigger_hurt with high damage, this means it's the final trigger_hurt.

So let's discuss possible ways:

1. Touching trigger_hurt with High Damage:
    1. #include <zombie_escape>
    2.  
    3. #define MIN_DAMAGE 9000
    4.  
    5. // Variables
    6. new bool:g_bCalledTrigger, g_iTriggerHurtForward
    7.  
    8. public plugin_init()
    9. {
    10.     register_plugin("trigger_hurt Listener", "1.0", "Raheem")
    11.    
    12.     // Here we register touching any trigger_hurt
    13.     RegisterHam(Ham_Touch, "trigger_hurt", "Fw_TouchTrigger_Post", 1)
    14.    
    15.     g_iTriggerHurtForward = CreateMultiForward("trigger_hurt", ET_IGNORE)
    16. }
    17.  
    18. public ze_game_started()
    19. {
    20.     g_bCalledTrigger = false
    21. }
    22.  
    23. public Fw_TouchTrigger_Post(iEnt, id)
    24. {
    25.     if(!is_user_alive(id) || !pev_valid(iEnt))
    26.         return HAM_IGNORED
    27.    
    28.     if (pev(iEnt, pev_dmg) > MIN_DAMAGE)
    29.     {
    30.         if (!g_bCalled)
    31.         {
    32.             ExecuteForward(g_iTriggerHurtForward)
    33.             g_bCalled = true
    34.         }
    35.     }
    36.  
    37.     return HAM_IGNORED
    38. }
Forward Test:
    1. #include <zombie_escape>
    2.  
    3. forward trigger_hurt();
    4.  
    5. public plugin_init()
    6. {
    7.     register_plugin("trigger_hurt Listener Test", "1.0", "Raheem")
    8. }
    9.  
    10. public trigger_hurt()
    11. {
    12.     ze_colored_print(0, "Final Damage Triggered!")
    13. }
2. If player touching trigger_multiple and touching the moving entity:
    1. /*
    2. *   This will hook the trigger_hurt when it's activated.
    3. *   What i know is that trigger_hurt can be activated via button or trigger_multiple
    4. *   This method is good for maps that conatin trains..etc
    5. *   Also we will hook which using trigger_multiple only
    6. *
    7. *   If user is touching the train and this player touched trigger_multiple then the trigger_hurt will be called.
    8. *   In fact the trigger_hurt will be called once trigger_multiple is touched by player but we will tie it with train also. Away to avoid hardcode every map.
    9. */
    10.  
    11. #include "zombie_escape.inc"
    12.  
    13. // Add all moving entities
    14. new const g_szEntities[][] =
    15. {
    16.     "func_tracktrain",
    17.     "func_vehicle"
    18. }
    19.  
    20. new Float:g_flLastTouched[33], g_iMaxPlayers, bool:g_bCalled, g_iTriggerHurtForward
    21.  
    22. public plugin_init()
    23. {
    24.     register_plugin("Hook Trigger Hurt", "1.0", "Raheem")
    25.    
    26.     for(new iEnt = 0; iEnt <= charsmax(g_szEntities); iEnt++)
    27.     {
    28.         RegisterHam(Ham_Touch, g_szEntities[iEnt], "Fw_TouchMoving_Pre", 0)
    29.     }
    30.    
    31.     RegisterHam(Ham_Touch, "trigger_multiple", "Fw_TouchTriggerMultiple_Pre", 0)
    32.    
    33.     g_iMaxPlayers = get_member_game(m_nMaxPlayers)
    34.    
    35.     g_iTriggerHurtForward = CreateMultiForward("trigger_hurt", ET_IGNORE)
    36. }
    37.  
    38. public ze_game_started()
    39. {
    40.     g_bCalled = false
    41. }
    42.  
    43. public Fw_TouchTriggerMultiple_Pre(iEnt, id)
    44. {
    45.     // Here player touching trigger_multiple
    46.     // Let's check first if he is touching also the train or not
    47.     if (TouchingMovingVehicle())
    48.     {
    49.         // Player in vehicle and he touched trigger_multiple
    50.         if (!g_bCalled)
    51.         {
    52.             // Here we execute our forward
    53.             ExecuteForward(g_iTriggerHurtForward)
    54.             g_bCalled = true
    55.         }
    56.     }
    57. }
    58.  
    59. public Fw_TouchMoving_Pre(iEnt, id)
    60. {
    61.     if (!is_user_connected(id))
    62.         return HAM_IGNORED;
    63.    
    64.     g_flLastTouched[id] = get_gametime()
    65.    
    66.     return HAM_IGNORED;
    67. }
    68.  
    69. stock TouchingMovingVehicle()
    70. {
    71.     // Check if anyone touching our moving trians or not
    72.     for(new id = 1; id <= g_iMaxPlayers; id++)
    73.     {
    74.         if (!is_user_alive(id))
    75.             continue;
    76.        
    77.         if (g_flLastTouched[id] + 0.1 >= get_gametime()) /* For more accurecy lower 0.1 to for example 0.01*/
    78.         {
    79.             return true;
    80.         }
    81.     }
    82.    
    83.     return false;
    84. }
Forward Test:
    1. #include <zombie_escape>
    2.  
    3. forward trigger_hurt();
    4.  
    5. public plugin_init()
    6. {
    7.     register_plugin("trigger_hurt Listener Test", "1.0", "Raheem")
    8. }
    9.  
    10. public trigger_hurt()
    11. {
    12.     ze_colored_print(0, "Final Damage Triggered!")
    13. }
3. If trigger_hurt is activated via button then hook this button and when someone press it.

4. We can combine the 1, 2 in one plugin, to make somehow general idea:
    1. /*
    2. *   This will hook the trigger_hurt when it's activated.
    3. *   What i know is that trigger_hurt can be activated via button or trigger_multiple
    4. *   This method is good for maps that conatin trains..etc
    5. *   Also we will hook which using trigger_multiple only
    6. *
    7. *   If user is touching the train and this player touched trigger_multiple then the trigger_hurt will be called.
    8. *   In fact the trigger_hurt will be called once trigger_multiple is touched by player but we will tie it with train also. Away to avoid hardcode every map.
    9. */
    10.  
    11. #include "zombie_escape.inc"
    12.  
    13. #define MIN_DAMAGE 9000
    14.  
    15. // Add all moving entities
    16. new const g_szEntities[][] =
    17. {
    18.     "func_tracktrain",
    19.     "func_vehicle"
    20. }
    21.  
    22. new Float:g_flLastTouched[33], g_iMaxPlayers, bool:g_bCalled, g_iTriggerHurtForward
    23.  
    24. public plugin_init()
    25. {
    26.     register_plugin("Hook Trigger Hurt", "1.0", "Raheem")
    27.    
    28.     for(new iEnt = 0; iEnt <= charsmax(g_szEntities); iEnt++)
    29.     {
    30.         RegisterHam(Ham_Touch, g_szEntities[iEnt], "Fw_TouchMoving_Pre", 0)
    31.     }
    32.    
    33.     RegisterHam(Ham_Touch, "trigger_multiple", "Fw_TouchTriggerMultiple_Pre", 0)
    34.    
    35.     // Here we register touching any trigger_hurt
    36.     RegisterHam(Ham_Touch, "trigger_hurt", "Fw_TouchTrigger_Post", 1)
    37.    
    38.     g_iMaxPlayers = get_member_game(m_nMaxPlayers)
    39.    
    40.     g_iTriggerHurtForward = CreateMultiForward("trigger_hurt", ET_IGNORE)
    41. }
    42.  
    43. public ze_game_started()
    44. {
    45.     g_bCalled = false
    46. }
    47.  
    48. public Fw_TouchTriggerMultiple_Pre(iEnt, id)
    49. {
    50.     // Here player touching trigger_multiple
    51.     // Let's check first if he is touching also the train or not
    52.     if (TouchingMovingVehicle())
    53.     {
    54.         // Player in vehicle and he touched trigger_multiple
    55.         if (!g_bCalled)
    56.         {
    57.             // Here we execute our forward
    58.             ExecuteForward(g_iTriggerHurtForward)
    59.             g_bCalled = true
    60.         }
    61.     }
    62. }
    63.  
    64. public Fw_TouchTrigger_Post(iEnt, id)
    65. {
    66.     if(!is_user_alive(id) || !pev_valid(iEnt))
    67.         return HAM_IGNORED
    68.    
    69.     if (pev(iEnt, pev_dmg) > MIN_DAMAGE)
    70.     {
    71.         if (!g_bCalled)
    72.         {
    73.             ExecuteForward(g_iTriggerHurtForward)
    74.             g_bCalled = true
    75.         }
    76.     }
    77.  
    78.     return HAM_IGNORED
    79. }
    80.  
    81. public Fw_TouchMoving_Pre(iEnt, id)
    82. {
    83.     if (!is_user_connected(id))
    84.         return HAM_IGNORED;
    85.    
    86.     g_flLastTouched[id] = get_gametime()
    87.    
    88.     return HAM_IGNORED;
    89. }
    90.  
    91. stock TouchingMovingVehicle()
    92. {
    93.     // Check if anyone touching our moving trians or not
    94.     for(new id = 1; id <= g_iMaxPlayers; id++)
    95.     {
    96.         if (!is_user_alive(id))
    97.             continue;
    98.        
    99.         if (g_flLastTouched[id] + 0.1 >= get_gametime()) /* For more accurecy lower 0.1 to for example 0.01*/
    100.         {
    101.             return true;
    102.         }
    103.     }
    104.    
    105.     return false;
    106. }
Forward Test:
    1. #include <zombie_escape>
    2.  
    3. forward trigger_hurt();
    4.  
    5. public plugin_init()
    6. {
    7.     register_plugin("trigger_hurt Listener Test", "1.0", "Raheem")
    8. }
    9.  
    10. public trigger_hurt()
    11. {
    12.     ze_colored_print(0, "Final Damage Triggered!")
    13. }
This is all ways how to detect the end round trigger_hurt that should kill all players that touching it or it's zone.
The final combined code is a very good approach to hook this event, it's success can be 95% so it looks nice to be used.


Why i need to listen to this event?
  • Maybe it's useful in some cases. and you maybe need to make somethings when it's called or after it's called.
    Basacilly i thought in this because i was trying to write a code that if some zombies not died with this trigger_hurt at the round end then i'll give them a chance 20 seconds to try if they failed i'll slay them. I must know how to hook the final trigger_hurt in order we can give him the chance and do all our code.
That's all i know for now, hope it help you :)
He who fails to plan is planning to fail

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 0 guests