diff --git a/Spectate/include/Spectate.inc b/Spectate/include/Spectate.inc new file mode 100644 index 0000000..c041831 --- /dev/null +++ b/Spectate/include/Spectate.inc @@ -0,0 +1,10 @@ +#if defined _Spectate_included + #endinput +#endif +#define _Spectate_included +/** + * Called when a client switches to spec by sm_spectate. + * + * @param client Client index of the caller. + */ +forward void OnPlayerSwitchedToSpectateByCommand(int client); \ No newline at end of file diff --git a/Spectate/scripting/Spectate.sp b/Spectate/scripting/Spectate.sp index 930de37..b94f48f 100644 --- a/Spectate/scripting/Spectate.sp +++ b/Spectate/scripting/Spectate.sp @@ -8,6 +8,8 @@ #pragma newdecls required +Handle g_hFwd_SpectateByCommand; + public Plugin myinfo = { name = "Spectate", @@ -41,6 +43,9 @@ public void OnPluginStart() AddCommandListener(Command_SpectateViaConsole, "spectate"); AddCommandListener(Command_GoTo, "spec_goto"); + AddCommandListener(Command_Kill, "kill"); + + g_hFwd_SpectateByCommand = CreateGlobalForward("OnPlayerSwitchedToSpectateByCommand", ET_Ignore, Param_Cell); } public void OnMapStart() @@ -95,9 +100,14 @@ 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) + 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"); + } + Call_StartForward(g_hFwd_SpectateByCommand); + Call_PushCell(client); + Call_Finish(); ForcePlayerSuicide(client); ChangeClientTeam(client, CS_TEAM_SPECTATOR); } @@ -120,9 +130,12 @@ 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) + 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"); + Call_StartForward(g_hFwd_SpectateByCommand); + Call_PushCell(client); + Call_Finish(); ForcePlayerSuicide(client); ChangeClientTeam(client, CS_TEAM_SPECTATOR); } @@ -150,6 +163,14 @@ public Action Command_SpectateViaConsole(int client, char[] command, int args) return Plugin_Continue; } +public Action Command_Kill(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) { @@ -188,4 +209,4 @@ stock int GetTeamAliveClientCount(int iTeam) } return ret; -} +} \ No newline at end of file