From dd024b6e5f2fd50086dc6a635fb1302e59cb8f89 Mon Sep 17 00:00:00 2001 From: BotoX Date: Tue, 7 Aug 2018 22:39:17 +0200 Subject: [PATCH] update Spectate --- Spectate/scripting/Spectate.sp | 42 +++++++++++++++++++++++- Spectate/scripting/include/loghelper.inc | 1 + 2 files changed, 42 insertions(+), 1 deletion(-) create mode 120000 Spectate/scripting/include/loghelper.inc diff --git a/Spectate/scripting/Spectate.sp b/Spectate/scripting/Spectate.sp index e7ab6d1e..930de372 100644 --- a/Spectate/scripting/Spectate.sp +++ b/Spectate/scripting/Spectate.sp @@ -1,10 +1,12 @@ #pragma semicolon 1 -#pragma newdecls required #include #include #include #include +#include "loghelper.inc" + +#pragma newdecls required public Plugin myinfo = { @@ -37,9 +39,15 @@ public void OnPluginStart() RegConsoleCmd("sm_spectate", Command_Spectate, "Spectate a player."); RegConsoleCmd("sm_spec", Command_Spectate, "Spectate a player."); + AddCommandListener(Command_SpectateViaConsole, "spectate"); AddCommandListener(Command_GoTo, "spec_goto"); } +public void OnMapStart() +{ + GetTeams(); +} + public void OnClientSettingsChanged(int client) { static char sSpecMode[8]; @@ -87,6 +95,9 @@ public Action Command_Spectate(int client, int argc) { if (GetClientTeam(client) != CS_TEAM_SPECTATOR) { + if ((IsPlayerAlive(client) && ZR_IsClientHuman(client)) && GetTeamClientCount(CS_TEAM_T) > 0 && GetTeamAliveClientCount(CS_TEAM_T) > 0) + LogPlayerEvent(client, "triggered", "switch_to_spec"); + ForcePlayerSuicide(client); ChangeClientTeam(client, CS_TEAM_SPECTATOR); } @@ -109,6 +120,9 @@ public Action Command_Spectate(int client, int argc) if (GetClientTeam(client) != CS_TEAM_SPECTATOR) { + if ((IsPlayerAlive(client) && ZR_IsClientHuman(client)) && GetTeamClientCount(CS_TEAM_T) > 0 && GetTeamAliveClientCount(CS_TEAM_T) > 0) + LogPlayerEvent(client, "triggered", "switch_to_spec"); + ForcePlayerSuicide(client); ChangeClientTeam(client, CS_TEAM_SPECTATOR); } @@ -128,6 +142,14 @@ public Action Command_Spectate(int client, int argc) return Plugin_Handled; } +public Action Command_SpectateViaConsole(int client, char[] command, int args) +{ + if ((IsPlayerAlive(client) && ZR_IsClientHuman(client)) && GetTeamClientCount(CS_TEAM_T) > 0 && GetTeamAliveClientCount(CS_TEAM_T) > 0) + LogPlayerEvent(client, "triggered", "switch_to_spec"); + + return Plugin_Continue; +} + // Fix spec_goto crash exploit public Action Command_GoTo(int client, const char[] command, int argc) { @@ -149,3 +171,21 @@ public Action Command_GoTo(int client, const char[] command, int argc) return Plugin_Continue; } + +stock int GetTeamAliveClientCount(int iTeam) +{ + int ret = 0; + + for (int i = 1; i <= MaxClients; i++) + { + if (!IsClientInGame(i) || GetClientTeam(i) != iTeam) + continue; + + if (!IsPlayerAlive(i)) + continue; + + ret++; + } + + return ret; +} diff --git a/Spectate/scripting/include/loghelper.inc b/Spectate/scripting/include/loghelper.inc new file mode 120000 index 00000000..db569458 --- /dev/null +++ b/Spectate/scripting/include/loghelper.inc @@ -0,0 +1 @@ +../../../includes/loghelper.inc \ No newline at end of file