Mapchooser: fix rtv playercount update.

That if statement in OnPlayerChangedTeam made me giggle when i saw it.
This commit is contained in:
zaCade 2017-11-01 00:51:48 +01:00
parent eb76f695c5
commit 1cac46a063

View File

@ -1,10 +1,11 @@
/**
* vim: set ts=4 :
* =============================================================================
* SourceMod Rock The Vote Plugin
* Rock The Vote Extended
* Creates a map vote when the required number of players have requested one.
*
* SourceMod (C)2004-2008 AlliedModders LLC. All rights reserved.
* Rock The Vote Extended (C)2012-2013 Powerlord (Ross Bemrose)
* SourceMod (C)2004-2007 AlliedModders LLC. All rights reserved.
* =============================================================================
*
* This program is free software; you can redistribute it and/or modify it under
@ -57,8 +58,8 @@ ConVar g_Cvar_Interval;
ConVar g_Cvar_ChangeTime;
ConVar g_Cvar_RTVPostVoteAction;
bool g_CanRTV = false; // True if RTV loaded maps and is active.
bool g_RTVAllowed = false; // True if RTV is available to players. Used to delay rtv votes.
bool g_CanRTV = false; // True if RTV loaded maps and is active.
bool g_RTVAllowed = false; // True if RTV is available to players. Used to delay rtv votes.
int g_Voters = 0; // Total voters connected. Doesn't include fake clients.
int g_Votes = 0; // Total number of "say rtv" votes
int g_VotesNeeded = 0; // Necessary votes before map vote begins. (voters * percent_needed)
@ -80,6 +81,7 @@ public void OnPluginStart()
g_Cvar_RTVPostVoteAction = CreateConVar("sm_rtv_postvoteaction", "0", "What to do with RTV's after a mapvote has completed. 0 - Allow, success = instant change, 1 - Deny", _, true, 0.0, true, 1.0);
RegConsoleCmd("sm_rtv", Command_RTV);
RegAdminCmd("sm_forcertv", Command_ForceRTV, ADMFLAG_CHANGEMAP, "Force an RTV vote");
RegAdminCmd("sm_disablertv", Command_DisableRTV, ADMFLAG_CHANGEMAP, "Disable the RTV command");
RegAdminCmd("sm_enablertv", Command_EnableRTV, ADMFLAG_CHANGEMAP, "Enable the RTV command");
@ -121,29 +123,29 @@ public void OnConfigsExecuted()
public void OnClientConnected(int client)
{
if(IsFakeClient(client))
return;
g_Voted[client] = false;
g_Voters = GetTeamClientCount(2) + GetTeamClientCount(3);
g_VotesNeeded = RoundToFloor(float(g_Voters) * g_Cvar_Needed.FloatValue);
return;
UpdateRTV();
}
public void OnClientDisconnect(int client)
{
if(IsFakeClient(client))
return;
if(g_Voted[client])
if (g_Voted[client])
{
g_Voted[client] = false;
g_Votes--;
}
UpdateRTV();
}
public void OnPlayerChangedTeam(Handle event, const char[] name, bool dontBroadcast)
{
UpdateRTV();
}
void UpdateRTV()
{
g_Voters = GetTeamClientCount(2) + GetTeamClientCount(3);
g_VotesNeeded = RoundToFloor(float(g_Voters) * g_Cvar_Needed.FloatValue);
g_VotesNeeded = RoundToFloor(float(g_Voters) * GetConVarFloat(g_Cvar_Needed));
if (!g_CanRTV)
{
@ -164,30 +166,6 @@ public void OnClientDisconnect(int client)
}
}
public void OnPlayerChangedTeam(Handle event, const char[] name, bool dontBroadcast)
{
int client = GetClientOfUserId(GetEventInt(event, "userid"));
if(client == 0 || !IsClientConnected(client) || !IsClientInGame(client) || IsFakeClient(client) ||
GetClientTeam(client) == 0 || GetClientTeam(client) == 1)
return;
g_Voters = GetTeamClientCount(2) + GetTeamClientCount(3);
g_VotesNeeded = RoundToFloor(float(g_Voters) * GetConVarFloat(g_Cvar_Needed));
if (g_Votes &&
g_Voters &&
g_Votes >= g_VotesNeeded &&
g_RTVAllowed )
{
if (g_Cvar_RTVPostVoteAction.IntValue == 1 && HasEndOfMapVoteFinished())
{
return;
}
StartRTV();
}
}
public void OnClientSayCommand_Post(int client, const char[] command, const char[] sArgs)
{
if (!g_CanRTV || !client)