diff --git a/ZombieManager/scripting/ZombieManager.sp b/ZombieManager/scripting/ZombieManager.sp index 21c6075c..0918f246 100644 --- a/ZombieManager/scripting/ZombieManager.sp +++ b/ZombieManager/scripting/ZombieManager.sp @@ -5,12 +5,18 @@ #include #include #include +#include #tryinclude bool g_bTestRound; bool g_bAdminTestRound; bool g_bMotherZM[MAXPLAYERS + 1] = { false, ...}; +bool g_bZHP[MAXPLAYERS + 1] = { false, ... }; +Handle g_hCookieZHP = null; +int g_iZHPMax[MAXPLAYERS + 1]; +int g_iZShield[MAXPLAYERS + 1]; + bool g_Plugin_entWatch; int g_iAFKTime; @@ -20,7 +26,7 @@ public Plugin myinfo = name = "Zombie Manager", author = "Dogan", description = "Tools to manage testround and zombies", - version = "1.3.0", + version = "2.0.0", url = "" }; @@ -32,16 +38,22 @@ public void OnPluginStart() RegAdminCmd("sm_testround", Command_Testround, ADMFLAG_GENERIC, "Toggle to enable/disable a test round."); CreateTimer(20.0, Timer_MessageTestRound, _, TIMER_REPEAT); + CreateTimer(0.2, Timer_HandleHPShield, _, TIMER_REPEAT); // health_regen_interval = 0.2 HookEvent("round_start", OnRoundStart); HookEvent("player_spawn", OnClientSpawn); HookEvent("player_team", OnPlayerTeam); + HookEvent("player_hurt", OnPlayerHurt); ConVar cvar; HookConVarChange((cvar = CreateConVar("sm_player_afk_time", "120", "AFK Time in seconds after which a player won't turn into a motherzombie")), Cvar_AFKTime); g_iAFKTime = cvar.IntValue; delete cvar; + RegConsoleCmd("sm_zhp", OnToggleZHP, "Toggle blocking Zombie HP and Shield display"); + g_hCookieZHP = RegClientCookie("zhp_blocked", "are zombie hp and shield display blocked", CookieAccess_Protected); + SetCookieMenuItem(MenuHandler_CookieMenu, 0, "Zombie HP Shield Display"); + AutoExecConfig(true, "plugin.ZombieManager"); AddMultiTargetFilter("@mzombie", Filter_Motherzombies, "Mother Zombies", false); @@ -71,6 +83,93 @@ public void OnPluginEnd() RemoveMultiTargetFilter("@mzombie", Filter_Motherzombies); } +public Action OnToggleZHP(int client, int args) +{ + ToggleZHP(client); + return Plugin_Handled; +} + +public void ToggleZHP(int client) +{ + g_bZHP[client] = !g_bZHP[client]; + + SetClientCookie(client, g_hCookieZHP, g_bZHP[client] ? "1" : ""); + CPrintToChat(client, "{lightgreen}[ZR] {yellow}%s", g_bZHP[client] ? "Zombie HP and Shield display disabled." : "Zombie HP and Shield display enabled."); +} + +public void OnClientCookiesCached(int client) +{ + char sBuffer[2]; + + GetClientCookie(client, g_hCookieZHP, sBuffer, sizeof(sBuffer)); + if(sBuffer[0] != '\0') + g_bZHP[client] = true; + else + g_bZHP[client] = false; +} + +public void OnClientDisconnect(int client) +{ + g_bZHP[client] = false; + g_iZHPMax[client] = 0; + g_iZShield[client] = 0; +} + +public void ShowSettingsMenu(int client) +{ + Menu menu = new Menu(MenuHandler_MainMenu); + + menu.SetTitle("Zombie HP Shield Display Settings", client); + + char sBuffer[128]; + + Format(sBuffer, sizeof(sBuffer), "Zombie HP and Shield Display: %s", g_bZHP[client] ? "Disabled" : "Enabled"); + menu.AddItem("0", sBuffer); + + menu.ExitBackButton = true; + + menu.Display(client, MENU_TIME_FOREVER); +} + +public void MenuHandler_CookieMenu(int client, CookieMenuAction action, any info, char[] buffer, int maxlen) +{ + switch(action) + { + case(CookieMenuAction_DisplayOption): + { + Format(buffer, maxlen, "Zombie HP Shield Display", client); + } + case(CookieMenuAction_SelectOption): + { + ShowSettingsMenu(client); + } + } +} + +public int MenuHandler_MainMenu(Menu menu, MenuAction action, int client, int selection) +{ + switch(action) + { + case(MenuAction_Select): + { + switch(selection) + { + case(0): ToggleZHP(client); + } + + ShowSettingsMenu(client); + } + case(MenuAction_Cancel): + { + ShowCookieMenu(client); + } + case(MenuAction_End): + { + delete menu; + } + } +} + public void Cvar_AFKTime(ConVar convar, const char[] oldValue, const char[] newValue) { g_iAFKTime = convar.IntValue; @@ -84,6 +183,8 @@ public void OnRoundStart(Event hEvent, const char[] sName, bool bDontBroadcast) for(int i = 1; i <= MaxClients; i++) { g_bMotherZM[i] = false; + g_iZHPMax[i] = 0; + g_iZShield[i] = 0; } } @@ -120,6 +221,8 @@ public Action ZR_OnClientMotherZombieEligible(int client) public void ZR_OnClientInfected(int client, int attacker, bool motherInfect, bool respawnOverride, bool respawn) { g_bMotherZM[client] = motherInfect; + + g_iZHPMax[client] = GetClientHealth(client); } public Action ZR_OnInfectCountdown() @@ -134,6 +237,7 @@ public void OnClientSpawn(Event hEvent, const char[] sName, bool bDontBroadcast) { int client = GetClientOfUserId(hEvent.GetInt("userid")); + g_iZShield[client] = 0; g_bMotherZM[client] = false; } @@ -144,6 +248,23 @@ public Action OnPlayerTeam(Event event, const char[] name, bool dontBroadcast) g_bMotherZM[client] = false; } +public Action OnPlayerHurt(Event event, const char[] name, bool dontBroadcast) +{ + int client = GetClientOfUserId(GetEventInt(event, "userid")); + int damage = GetEventInt(event, "dmg_health"); + + if(!IsClientInGame(client) || !IsPlayerAlive(client) || !ZR_IsClientZombie(client)) + return Plugin_Continue; + + if(g_iZShield[client] > 0) + { + g_iZShield[client] = g_iZShield[client] - damage; + SetEntityHealth(client, g_iZHPMax[client]); + } + + return Plugin_Continue; +} + public bool Filter_Motherzombies(const char[] sPattern, Handle hClients, int client) { for(int i = 1; i <= MaxClients; i++) @@ -261,4 +382,48 @@ public Action Timer_MessageTestRound(Handle timer) } return Plugin_Continue; +} + +public Action Timer_HandleHPShield(Handle timer) +{ + char sNemesis[32]; + GetConVarString(FindConVar("sm_info_message_file"), sNemesis, sizeof(sNemesis)); + bool bNemesis = StrEqual(sNemesis, "nemesis"); + + for(int i = 1; i <= MaxClients; i++) + { + if(!IsClientInGame(i) || !IsPlayerAlive(i) || !ZR_IsClientZombie(i)) + continue; + + bool bHasItem; + #if defined entWatch_core_included + if(g_Plugin_entWatch) + bHasItem = EW_ClientHasItem(i); + #endif + + if(bHasItem) + g_iZShield[i] = 0; //zombies with items + else if(GetClientHealth(i) >= g_iZHPMax[i] && bNemesis) + g_iZShield[i] = 0; //disable for now on nemesis + //g_iZShield[i] = g_iZShield[i] + 12; // health_regen_amount = 12 + else if(GetClientHealth(i) >= g_iZHPMax[i] && !bNemesis) + g_iZShield[i] = g_iZShield[i] + 6; // health_regen_amount = 6 + + UpdateHintMessage(i, bHasItem); + } + + return Plugin_Continue; +} + +public void UpdateHintMessage(int client, bool bHasItem) +{ + bool bVote = IsVoteInProgress(); + + if(g_bZHP[client] || bVote) + return; + + if(g_iZShield[client] <= 0 || bHasItem) + PrintHintText(client, "HP: %d - Shield: none", GetClientHealth(client)); + else + PrintHintText(client, "HP: %d - Shield: %d", GetClientHealth(client), g_iZShield[client]); } \ No newline at end of file