Spectate: fix roundend bug

This commit is contained in:
Dogan 2019-11-11 00:16:20 +01:00
parent 27a9b2abeb
commit 2a0a3d39ee

View File

@ -10,6 +10,8 @@
Handle g_hFwd_SpectateByCommand; Handle g_hFwd_SpectateByCommand;
bool g_bRoundEnd;
public Plugin myinfo = public Plugin myinfo =
{ {
name = "Spectate", name = "Spectate",
@ -46,6 +48,9 @@ public void OnPluginStart()
AddCommandListener(Command_Goto, "spec_goto"); AddCommandListener(Command_Goto, "spec_goto");
g_hFwd_SpectateByCommand = CreateGlobalForward("OnPlayerSwitchedToSpectateByCommand", ET_Ignore, Param_Cell); g_hFwd_SpectateByCommand = CreateGlobalForward("OnPlayerSwitchedToSpectateByCommand", ET_Ignore, Param_Cell);
HookEvent("round_start", OnRoundStart, EventHookMode_Post);
HookEvent("round_end", OnRoundEnd, EventHookMode_Pre);
} }
public void OnMapStart() public void OnMapStart()
@ -53,6 +58,16 @@ public void OnMapStart()
GetTeams(); GetTeams();
} }
public void OnRoundStart(Event hEvent, const char[] sName, bool bDontBroadcast)
{
g_bRoundEnd = false;
}
public void OnRoundEnd(Event hEvent, const char[] sName, bool bDontBroadcast)
{
g_bRoundEnd = true;
}
public void OnClientSettingsChanged(int client) public void OnClientSettingsChanged(int client)
{ {
static char sSpecMode[8]; static char sSpecMode[8];
@ -100,7 +115,7 @@ public Action Command_Spectate(int client, int argc)
{ {
if (GetClientTeam(client) != CS_TEAM_SPECTATOR) if (GetClientTeam(client) != CS_TEAM_SPECTATOR)
{ {
if ((IsPlayerAlive(client) && ZR_IsClientHuman(client)) && GetTeamAliveClientCount(CS_TEAM_T) > 0) if ((IsPlayerAlive(client) && ZR_IsClientHuman(client)) && GetTeamAliveClientCount(CS_TEAM_T) > 0 && !g_bRoundEnd)
LogPlayerEvent(client, "triggered", "switch_to_spec"); LogPlayerEvent(client, "triggered", "switch_to_spec");
Call_StartForward(g_hFwd_SpectateByCommand); Call_StartForward(g_hFwd_SpectateByCommand);
@ -130,7 +145,7 @@ public Action Command_Spectate(int client, int argc)
if (GetClientTeam(client) != CS_TEAM_SPECTATOR) if (GetClientTeam(client) != CS_TEAM_SPECTATOR)
{ {
if ((IsPlayerAlive(client) && ZR_IsClientHuman(client)) && GetTeamAliveClientCount(CS_TEAM_T) > 0) if ((IsPlayerAlive(client) && ZR_IsClientHuman(client)) && GetTeamAliveClientCount(CS_TEAM_T) > 0 && !g_bRoundEnd)
LogPlayerEvent(client, "triggered", "switch_to_spec"); LogPlayerEvent(client, "triggered", "switch_to_spec");
Call_StartForward(g_hFwd_SpectateByCommand); Call_StartForward(g_hFwd_SpectateByCommand);
@ -160,7 +175,7 @@ public Action Command_Spectate(int client, int argc)
public Action Command_Suicide(int client, char[] command, int args) public Action Command_Suicide(int client, char[] command, int args)
{ {
if ((IsPlayerAlive(client) && ZR_IsClientHuman(client)) && GetTeamAliveClientCount(CS_TEAM_T) > 0) if ((IsPlayerAlive(client) && ZR_IsClientHuman(client)) && GetTeamAliveClientCount(CS_TEAM_T) > 0 && !g_bRoundEnd)
LogPlayerEvent(client, "triggered", "switch_to_spec"); LogPlayerEvent(client, "triggered", "switch_to_spec");
return Plugin_Continue; return Plugin_Continue;