diff --git a/Spectate/scripting/Spectate.sp b/Spectate/scripting/Spectate.sp index e7ab6d1e..e48f5107 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,11 @@ 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 && GetTeamAliveClientCount(CS_TEAM_CT) > 0) + { + LogPlayerEvent(client, "triggered", "switch_to_spec"); + } + ForcePlayerSuicide(client); ChangeClientTeam(client, CS_TEAM_SPECTATOR); } @@ -109,6 +122,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 && GetTeamAliveClientCount(CS_TEAM_CT) > 0) + LogPlayerEvent(client, "triggered", "switch_to_spec"); + ForcePlayerSuicide(client); ChangeClientTeam(client, CS_TEAM_SPECTATOR); } @@ -128,6 +144,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 +173,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; +} \ No newline at end of file