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:
- #include <zombie_escape>
- #define MIN_DAMAGE 9000
- // Variables
- new bool:g_bCalledTrigger, g_iTriggerHurtForward
- public plugin_init()
- {
- register_plugin("trigger_hurt Listener", "1.0", "Raheem")
- // Here we register touching any trigger_hurt
- RegisterHam(Ham_Touch, "trigger_hurt", "Fw_TouchTrigger_Post", 1)
- g_iTriggerHurtForward = CreateMultiForward("trigger_hurt", ET_IGNORE)
- }
- public ze_game_started()
- {
- g_bCalledTrigger = false
- }
- public Fw_TouchTrigger_Post(iEnt, id)
- {
- if(!is_user_alive(id) || !pev_valid(iEnt))
- return HAM_IGNORED
- if (pev(iEnt, pev_dmg) > MIN_DAMAGE)
- {
- if (!g_bCalled)
- {
- ExecuteForward(g_iTriggerHurtForward)
- g_bCalled = true
- }
- }
- return HAM_IGNORED
- }
- #include <zombie_escape>
- forward trigger_hurt();
- public plugin_init()
- {
- register_plugin("trigger_hurt Listener Test", "1.0", "Raheem")
- }
- public trigger_hurt()
- {
- ze_colored_print(0, "Final Damage Triggered!")
- }
- /*
- * This will hook the trigger_hurt when it's activated.
- * What i know is that trigger_hurt can be activated via button or trigger_multiple
- * This method is good for maps that conatin trains..etc
- * Also we will hook which using trigger_multiple only
- *
- * If user is touching the train and this player touched trigger_multiple then the trigger_hurt will be called.
- * 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.
- */
- #include "zombie_escape.inc"
- // Add all moving entities
- new const g_szEntities[][] =
- {
- "func_tracktrain",
- "func_vehicle"
- }
- new Float:g_flLastTouched[33], g_iMaxPlayers, bool:g_bCalled, g_iTriggerHurtForward
- public plugin_init()
- {
- register_plugin("Hook Trigger Hurt", "1.0", "Raheem")
- for(new iEnt = 0; iEnt <= charsmax(g_szEntities); iEnt++)
- {
- RegisterHam(Ham_Touch, g_szEntities[iEnt], "Fw_TouchMoving_Pre", 0)
- }
- RegisterHam(Ham_Touch, "trigger_multiple", "Fw_TouchTriggerMultiple_Pre", 0)
- g_iMaxPlayers = get_member_game(m_nMaxPlayers)
- g_iTriggerHurtForward = CreateMultiForward("trigger_hurt", ET_IGNORE)
- }
- public ze_game_started()
- {
- g_bCalled = false
- }
- public Fw_TouchTriggerMultiple_Pre(iEnt, id)
- {
- // Here player touching trigger_multiple
- // Let's check first if he is touching also the train or not
- if (TouchingMovingVehicle())
- {
- // Player in vehicle and he touched trigger_multiple
- if (!g_bCalled)
- {
- // Here we execute our forward
- ExecuteForward(g_iTriggerHurtForward)
- g_bCalled = true
- }
- }
- }
- public Fw_TouchMoving_Pre(iEnt, id)
- {
- if (!is_user_connected(id))
- return HAM_IGNORED;
- g_flLastTouched[id] = get_gametime()
- return HAM_IGNORED;
- }
- stock TouchingMovingVehicle()
- {
- // Check if anyone touching our moving trians or not
- for(new id = 1; id <= g_iMaxPlayers; id++)
- {
- if (!is_user_alive(id))
- continue;
- if (g_flLastTouched[id] + 0.1 >= get_gametime()) /* For more accurecy lower 0.1 to for example 0.01*/
- {
- return true;
- }
- }
- return false;
- }
- #include <zombie_escape>
- forward trigger_hurt();
- public plugin_init()
- {
- register_plugin("trigger_hurt Listener Test", "1.0", "Raheem")
- }
- public trigger_hurt()
- {
- ze_colored_print(0, "Final Damage Triggered!")
- }
4. We can combine the 1, 2 in one plugin, to make somehow general idea:
- /*
- * This will hook the trigger_hurt when it's activated.
- * What i know is that trigger_hurt can be activated via button or trigger_multiple
- * This method is good for maps that conatin trains..etc
- * Also we will hook which using trigger_multiple only
- *
- * If user is touching the train and this player touched trigger_multiple then the trigger_hurt will be called.
- * 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.
- */
- #include "zombie_escape.inc"
- #define MIN_DAMAGE 9000
- // Add all moving entities
- new const g_szEntities[][] =
- {
- "func_tracktrain",
- "func_vehicle"
- }
- new Float:g_flLastTouched[33], g_iMaxPlayers, bool:g_bCalled, g_iTriggerHurtForward
- public plugin_init()
- {
- register_plugin("Hook Trigger Hurt", "1.0", "Raheem")
- for(new iEnt = 0; iEnt <= charsmax(g_szEntities); iEnt++)
- {
- RegisterHam(Ham_Touch, g_szEntities[iEnt], "Fw_TouchMoving_Pre", 0)
- }
- RegisterHam(Ham_Touch, "trigger_multiple", "Fw_TouchTriggerMultiple_Pre", 0)
- // Here we register touching any trigger_hurt
- RegisterHam(Ham_Touch, "trigger_hurt", "Fw_TouchTrigger_Post", 1)
- g_iMaxPlayers = get_member_game(m_nMaxPlayers)
- g_iTriggerHurtForward = CreateMultiForward("trigger_hurt", ET_IGNORE)
- }
- public ze_game_started()
- {
- g_bCalled = false
- }
- public Fw_TouchTriggerMultiple_Pre(iEnt, id)
- {
- // Here player touching trigger_multiple
- // Let's check first if he is touching also the train or not
- if (TouchingMovingVehicle())
- {
- // Player in vehicle and he touched trigger_multiple
- if (!g_bCalled)
- {
- // Here we execute our forward
- ExecuteForward(g_iTriggerHurtForward)
- g_bCalled = true
- }
- }
- }
- public Fw_TouchTrigger_Post(iEnt, id)
- {
- if(!is_user_alive(id) || !pev_valid(iEnt))
- return HAM_IGNORED
- if (pev(iEnt, pev_dmg) > MIN_DAMAGE)
- {
- if (!g_bCalled)
- {
- ExecuteForward(g_iTriggerHurtForward)
- g_bCalled = true
- }
- }
- return HAM_IGNORED
- }
- public Fw_TouchMoving_Pre(iEnt, id)
- {
- if (!is_user_connected(id))
- return HAM_IGNORED;
- g_flLastTouched[id] = get_gametime()
- return HAM_IGNORED;
- }
- stock TouchingMovingVehicle()
- {
- // Check if anyone touching our moving trians or not
- for(new id = 1; id <= g_iMaxPlayers; id++)
- {
- if (!is_user_alive(id))
- continue;
- if (g_flLastTouched[id] + 0.1 >= get_gametime()) /* For more accurecy lower 0.1 to for example 0.01*/
- {
- return true;
- }
- }
- return false;
- }
- #include <zombie_escape>
- forward trigger_hurt();
- public plugin_init()
- {
- register_plugin("trigger_hurt Listener Test", "1.0", "Raheem")
- }
- public trigger_hurt()
- {
- ze_colored_print(0, "Final Damage Triggered!")
- }
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.