Spectate: adding forward

This commit is contained in:
neon 2018-11-21 00:24:07 +01:00
parent 3db6438022
commit e01da92b94
2 changed files with 34 additions and 3 deletions

View File

@ -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);

View File

@ -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;
}
}