From f9106793ba400cce63179a0e902699da9e7877a5 Mon Sep 17 00:00:00 2001 From: neon <> Date: Fri, 17 Aug 2018 14:11:39 +0200 Subject: [PATCH] zr_maphhooks: added to git --- zr_maphooks/scripting/zr_maphooks.sp | 102 +++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 zr_maphooks/scripting/zr_maphooks.sp diff --git a/zr_maphooks/scripting/zr_maphooks.sp b/zr_maphooks/scripting/zr_maphooks.sp new file mode 100644 index 00000000..47c25625 --- /dev/null +++ b/zr_maphooks/scripting/zr_maphooks.sp @@ -0,0 +1,102 @@ +#pragma semicolon 1 + +#include +#include +#include + +ConVar g_CVar_ZRInfectKill; +ConVar g_CVar_PlayerShotHook; +ConVar g_CVar_PlayerShotCount; + +bool g_bPlayerShotHook; +bool g_bZRInfectKill; + +int g_PlayerShotCount; + +int g_PlayerShotCurrent[MAXPLAYERS + 1] = {0, ...}; + +public void OnPluginStart() +{ + g_CVar_ZRInfectKill = CreateConVar("zr_shotinfectkill", "1", "Enable the game_playerdie/kill entities to be triggered by ZR.", 0, true, 0.0, true, 1.0); + g_bZRInfectKill = g_CVar_ZRInfectKill.BoolValue; + g_CVar_ZRInfectKill.AddChangeHook(OnConVarChanged); + + g_CVar_PlayerShotHook = CreateConVar("zr_playershothook", "1", "Enable the usage of the game_playershot entity.", 0, true, 0.0, true, 1.0); + g_bPlayerShotHook = g_CVar_PlayerShotHook.BoolValue; + g_CVar_PlayerShotHook.AddChangeHook(OnConVarChanged); + + g_CVar_PlayerShotCount = CreateConVar("zr_playershotcount", "1", "Bullet count required per game_playershot call.", 0, true, 1.0); + g_PlayerShotCount = g_CVar_PlayerShotCount.IntValue; + g_CVar_PlayerShotCount.AddChangeHook(OnConVarChanged); + + HookEvent("player_hurt", EventPlayerHurt); +} + +public void OnConVarChanged(ConVar convar, const char[] oldValue, const char[] newValue) +{ + if(convar == g_CVar_ZRInfectKill) + g_bZRInfectKill = g_CVar_ZRInfectKill.BoolValue; + + else if(convar == g_CVar_PlayerShotHook) + g_bPlayerShotHook = g_CVar_PlayerShotHook.BoolValue; + + else if(convar == g_CVar_PlayerShotCount) + g_PlayerShotCount = g_CVar_PlayerShotCount.IntValue; +} + +public int ZR_OnClientInfected(int client, int attacker, bool motherInfect, bool respawnOverride, bool respawn) +{ + if(g_bZRInfectKill && !motherInfect) + { + int entity = INVALID_ENT_REFERENCE; + while((entity = FindEntityByClassname(entity, "trigger_brush")) != INVALID_ENT_REFERENCE) + { + static char sTargetname[64]; + GetEntPropString(entity, Prop_Data, "m_iName", sTargetname, sizeof(sTargetname)); + + if(client > 0 && StrEqual(sTargetname, "game_playerdie")) + AcceptEntityInput(entity, "Use", client, client); + else if(attacker > 0 && StrEqual(sTargetname, "game_playerkill")) + AcceptEntityInput(entity, "Use", attacker, attacker); + } + } +} + +public Action EventPlayerHurt(Handle event, const char[] name, bool dontBroadcast) +{ + if(g_bPlayerShotHook) + { + int attacker = GetClientOfUserId(GetEventInt(event, "attacker")); + + if(attacker <= 0) + return Plugin_Continue; + + if(g_PlayerShotCount > 1) + { + g_PlayerShotCurrent[attacker] = g_PlayerShotCurrent[attacker] + 1; + if(g_PlayerShotCurrent[attacker] >= g_PlayerShotCount) + { + g_PlayerShotCurrent[attacker] = 0; + FirePlayerShot(attacker); + } + } + else + { + FirePlayerShot(attacker); + } + } + return Plugin_Continue; +} + +void FirePlayerShot(int client) +{ + int entity = INVALID_ENT_REFERENCE; + while((entity = FindEntityByClassname(entity, "trigger_brush")) != INVALID_ENT_REFERENCE) + { + static char sTargetname[64]; + GetEntPropString(entity, Prop_Data, "m_iName", sTargetname, sizeof(sTargetname)); + + if(StrEqual(sTargetname, "game_playershot")) + AcceptEntityInput(entity, "Use", client, client); + } +} \ No newline at end of file