443 lines
11 KiB
SourcePawn
443 lines
11 KiB
SourcePawn
#pragma semicolon 1
|
|
|
|
#include <sourcemod>
|
|
#include <cstrike>
|
|
#include <multicolors>
|
|
#include <zombiereloaded>
|
|
#include <AFKManager>
|
|
#include <clientprefs>
|
|
#tryinclude <entWatch_core>
|
|
|
|
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_bShield;
|
|
|
|
bool g_Plugin_entWatch;
|
|
|
|
int g_iAFKTime;
|
|
|
|
public Plugin myinfo =
|
|
{
|
|
name = "Zombie Manager",
|
|
author = "Dogan",
|
|
description = "Tools to manage testround and zombies",
|
|
version = "2.0.0",
|
|
url = ""
|
|
};
|
|
|
|
public void OnPluginStart()
|
|
{
|
|
g_bTestRound = false;
|
|
g_bAdminTestRound = false;
|
|
|
|
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;
|
|
HookConVarChange((cvar = CreateConVar("sm_zombieshield", "1", "1 = Zombie Shield activated, 0 = Zombie Shield deactivated", FCVAR_NONE, true, 0.0, true, 1.0)), Cvar_ZombieShield);
|
|
g_bShield = cvar.BoolValue;
|
|
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);
|
|
RegConsoleCmd("sm_mzombie", Command_DisplayMotherzombies, "Current Mother Zombies");
|
|
RegConsoleCmd("sm_mzombies", Command_DisplayMotherzombies, "Current Mother Zombies");
|
|
}
|
|
|
|
public void OnAllPluginsLoaded()
|
|
{
|
|
g_Plugin_entWatch = LibraryExists("entWatch-core");
|
|
}
|
|
|
|
public void OnLibraryAdded(const char[] name)
|
|
{
|
|
if(StrEqual(name, "entWatch-core"))
|
|
g_Plugin_entWatch = true;
|
|
}
|
|
|
|
public void OnLibraryRemoved(const char[] name)
|
|
{
|
|
if(StrEqual(name, "entWatch-core"))
|
|
g_Plugin_entWatch = false;
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
public void Cvar_ZombieShield(ConVar convar, const char[] oldValue, const char[] newValue)
|
|
{
|
|
g_bShield = convar.BoolValue;
|
|
}
|
|
|
|
public void OnRoundStart(Event hEvent, const char[] sName, bool bDontBroadcast)
|
|
{
|
|
g_bTestRound = false;
|
|
g_bAdminTestRound = false;
|
|
|
|
for(int i = 1; i <= MaxClients; i++)
|
|
{
|
|
g_bMotherZM[i] = false;
|
|
g_iZHPMax[i] = 0;
|
|
g_iZShield[i] = 0;
|
|
}
|
|
}
|
|
|
|
public void ZR_OnClientHumanPost(int client, bool respawn, bool protect)
|
|
{
|
|
g_bMotherZM[client] = false;
|
|
}
|
|
|
|
public Action ZR_OnClientInfect(int &client, int &attacker, bool &motherInfect, bool &respawnOverride, bool &respawn)
|
|
{
|
|
if(g_bTestRound)
|
|
return Plugin_Handled;
|
|
|
|
return Plugin_Continue;
|
|
}
|
|
|
|
public Action ZR_OnClientMotherZombieEligible(int client)
|
|
{
|
|
bool bHasItem;
|
|
#if defined entWatch_core_included
|
|
if(g_Plugin_entWatch)
|
|
bHasItem = EW_ClientHasItem(client);
|
|
#endif
|
|
|
|
char sAuthID[32];
|
|
GetClientAuthId(client, AuthId_Steam2, sAuthID, sizeof(sAuthID)); //autism bot
|
|
|
|
if(GetClientIdleTime(client) > g_iAFKTime || IsFakeClient(client) || bHasItem || StrEqual(sAuthID, "STEAM_0:1:60189040"))
|
|
return Plugin_Handled;
|
|
|
|
return Plugin_Continue;
|
|
}
|
|
|
|
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()
|
|
{
|
|
if(g_bTestRound)
|
|
return Plugin_Handled;
|
|
|
|
return Plugin_Continue;
|
|
}
|
|
|
|
public void OnClientSpawn(Event hEvent, const char[] sName, bool bDontBroadcast)
|
|
{
|
|
int client = GetClientOfUserId(hEvent.GetInt("userid"));
|
|
|
|
g_iZShield[client] = 0;
|
|
g_bMotherZM[client] = false;
|
|
}
|
|
|
|
public Action OnPlayerTeam(Event event, const char[] name, bool dontBroadcast)
|
|
{
|
|
int client = GetClientOfUserId(GetEventInt(event, "userid"));
|
|
|
|
g_bMotherZM[client] = false;
|
|
}
|
|
|
|
public Action OnPlayerHurt(Event event, const char[] name, bool dontBroadcast)
|
|
{
|
|
int client = GetClientOfUserId(GetEventInt(event, "userid"));
|
|
int attacker = GetClientOfUserId(GetEventInt(event, "attacker"));
|
|
int damage = GetEventInt(event, "dmg_health");
|
|
|
|
if(!IsClientInGame(client) || !IsPlayerAlive(client) || !ZR_IsClientZombie(client) || GetClientHealth(client) <= g_iZHPMax[client])
|
|
{
|
|
g_iZShield[client] = 0;
|
|
return Plugin_Continue;
|
|
}
|
|
|
|
if(g_iZShield[client] > 0 && attacker != 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++)
|
|
{
|
|
if(IsClientInGame(i) && !IsFakeClient(i))
|
|
{
|
|
if(g_bMotherZM[i])
|
|
PushArrayCell(hClients, i);
|
|
}
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
public Action Command_DisplayMotherzombies(int client, int args)
|
|
{
|
|
char aBuf[1024];
|
|
char aBuf2[MAX_NAME_LENGTH];
|
|
|
|
for(int i = 1; i <= MaxClients; i++)
|
|
{
|
|
if(IsClientInGame(i) && !IsFakeClient(i))
|
|
{
|
|
if(g_bMotherZM[i])
|
|
{
|
|
GetClientName(i, aBuf2, sizeof(aBuf2));
|
|
StrCat(aBuf, sizeof(aBuf), aBuf2);
|
|
StrCat(aBuf, sizeof(aBuf), ", ");
|
|
}
|
|
}
|
|
}
|
|
|
|
if(strlen(aBuf))
|
|
{
|
|
aBuf[strlen(aBuf) - 2] = 0;
|
|
ReplyToCommand(client, "[SM] Current Mother Zombies: %s", aBuf);
|
|
}
|
|
else
|
|
ReplyToCommand(client, "[SM] Current Mother Zombies: none");
|
|
|
|
return Plugin_Handled;
|
|
}
|
|
|
|
public Action Command_Testround(int client, int args)
|
|
{
|
|
/*if(GetClientTeam(client) == CS_TEAM_SPECTATOR)
|
|
{
|
|
ReplyToCommand(client, "[SM] Please join a Team first.");
|
|
return Plugin_Handled;
|
|
}
|
|
|
|
if(!IsPlayerAlive(client))
|
|
{
|
|
ReplyToCommand(client, "[SM] Please respawn yourself first.");
|
|
return Plugin_Handled;
|
|
}*/
|
|
|
|
ToggleTestRound(client);
|
|
return Plugin_Handled;
|
|
}
|
|
|
|
public void ToggleTestRound(int client)
|
|
{
|
|
g_bAdminTestRound = !g_bAdminTestRound;
|
|
|
|
if(g_bTestRound)
|
|
{
|
|
g_bTestRound = false;
|
|
|
|
ReplyToCommand(client, "[SM] Deactivated this Test Round.");
|
|
CPrintToChatAll("[SM] %N deactivated this Test Round!", client);
|
|
LogAction(client, -1, "\"%L\" deactivated this Test Round.", client);
|
|
}
|
|
else
|
|
{
|
|
g_bTestRound = true;
|
|
|
|
ReplyToCommand(client, "[SM] Activated a Test Round.");
|
|
CPrintToChatAll("[SM] %N activated a Test Round!", client);
|
|
LogAction(client, -1, "\"%L\" activated a Test Round.", client);
|
|
|
|
for(int i = 1; i <= MaxClients; i++)
|
|
{
|
|
if(IsClientInGame(i) && IsPlayerAlive(i) && ZR_IsClientZombie(i))
|
|
{
|
|
ZR_HumanClient(i, false, false);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public Action CS_OnTerminateRound(float &delay, CSRoundEndReason &reason)
|
|
{
|
|
if(g_bTestRound)
|
|
return Plugin_Handled;
|
|
|
|
return Plugin_Continue;
|
|
}
|
|
|
|
public Action ZR_OnClientRespawn(int &client, ZR_RespawnCondition &condition)
|
|
{
|
|
if(g_bTestRound)
|
|
condition = ZR_Respawn_Human;
|
|
|
|
return Plugin_Changed;
|
|
}
|
|
|
|
public Action Timer_MessageTestRound(Handle timer)
|
|
{
|
|
if(g_bTestRound)
|
|
{
|
|
CPrintToChatAll("{cyan}[UNLOZE] {red}This is a Test Round!");
|
|
CPrintToChatAll("{cyan}[UNLOZE] {red}This is a Test Round!");
|
|
CPrintToChatAll("{cyan}[UNLOZE] {red}This is a Test Round!");
|
|
}
|
|
|
|
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(!g_bShield)
|
|
g_iZShield[i] = 0; //disabled by convar
|
|
else if(bHasItem)
|
|
g_iZShield[i] = 0; //zombies with items
|
|
else if(GetClientHealth(i) >= g_iZHPMax[i] && bNemesis)
|
|
g_iZShield[i] = 0; //disabled 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", GetClientHealth(client));
|
|
else
|
|
PrintHintText(client, "HP: %d - Shield: %d", GetClientHealth(client), g_iZShield[client]);
|
|
} |