now re-evaluting each rtv when a person disconnects or connects
This commit is contained in:
parent
50058d15f1
commit
59eb86fa23
@ -68,7 +68,6 @@ ConVar g_Cvar_RTVRevoteDelay;
|
|||||||
bool is_bot_player[MAXPLAYERS + 1];
|
bool is_bot_player[MAXPLAYERS + 1];
|
||||||
bool g_CanRTV = false; // True if RTV loaded maps and is active.
|
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_RTVAllowed = false; // True if RTV is available to players. Used to delay rtv votes.
|
||||||
int g_Votes = 0; // 2023: accumulated rtv average hours from typing "rtv". minimum each valid client is equal to GetAveragePlayerTimeOnServerRTV, but can be more
|
|
||||||
int g_VotesNeeded = 0; // Necessary votes before map vote begins. (2023: voters average hour count * percent_needed)
|
int g_VotesNeeded = 0; // Necessary votes before map vote begins. (2023: voters average hour count * percent_needed)
|
||||||
bool g_Voted[MAXPLAYERS+1] = {false, ...};
|
bool g_Voted[MAXPLAYERS+1] = {false, ...};
|
||||||
int g_iTimeTillRTV[MAXPLAYERS+1] = {0, ...};
|
int g_iTimeTillRTV[MAXPLAYERS+1] = {0, ...};
|
||||||
@ -106,7 +105,6 @@ public void OnPluginStart()
|
|||||||
|
|
||||||
public void OnMapStart()
|
public void OnMapStart()
|
||||||
{
|
{
|
||||||
g_Votes = 0;
|
|
||||||
g_VotesNeeded = 0;
|
g_VotesNeeded = 0;
|
||||||
g_InChange = false;
|
g_InChange = false;
|
||||||
|
|
||||||
@ -146,7 +144,6 @@ public void OnClientDisconnect(int client)
|
|||||||
{
|
{
|
||||||
g_Voted[client] = false;
|
g_Voted[client] = false;
|
||||||
g_iTimeTillRTV[client] = 0;
|
g_iTimeTillRTV[client] = 0;
|
||||||
g_Votes -= GetPlayerWorthRTV_(client);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
UpdateRTV();
|
UpdateRTV();
|
||||||
@ -204,9 +201,10 @@ void UpdateRTV()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (g_Votes &&
|
int Votes = get_voted_rtv();
|
||||||
|
if (Votes &&
|
||||||
iVotersSteam &&
|
iVotersSteam &&
|
||||||
g_Votes >= g_VotesNeeded &&
|
Votes >= g_VotesNeeded &&
|
||||||
RTVAllowed())
|
RTVAllowed())
|
||||||
{
|
{
|
||||||
if (g_Cvar_RTVPostVoteAction.IntValue == 1 && HasEndOfMapVoteFinished())
|
if (g_Cvar_RTVPostVoteAction.IntValue == 1 && HasEndOfMapVoteFinished())
|
||||||
@ -218,6 +216,19 @@ void UpdateRTV()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int get_voted_rtv()
|
||||||
|
{
|
||||||
|
int Votes = 0;
|
||||||
|
for (int i = 0; i < MaxClients; i++)
|
||||||
|
{
|
||||||
|
if (IsValidClient(i) && g_Voted[i])
|
||||||
|
{
|
||||||
|
Votes += GetPlayerWorthRTV_(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return Votes;
|
||||||
|
}
|
||||||
|
|
||||||
public void OnClientSayCommand_Post(int client, const char[] command, const char[] sArgs)
|
public void OnClientSayCommand_Post(int client, const char[] command, const char[] sArgs)
|
||||||
{
|
{
|
||||||
if (!g_CanRTV || !client)
|
if (!g_CanRTV || !client)
|
||||||
@ -276,11 +287,16 @@ void AttemptRTV(int client)
|
|||||||
if (g_Voted[client])
|
if (g_Voted[client])
|
||||||
{
|
{
|
||||||
float rtv_worth = GetPlayerWorthRTV_boost_(client);
|
float rtv_worth = GetPlayerWorthRTV_boost_(client);
|
||||||
|
int Votes = get_voted_rtv();
|
||||||
if (g_VotesNeeded == 0)
|
if (g_VotesNeeded == 0)
|
||||||
{
|
{
|
||||||
g_VotesNeeded = g_Votes;
|
g_VotesNeeded = Votes;
|
||||||
|
}
|
||||||
|
int rtv_percentage_reached = RoundToFloor((float(Votes) / float(g_VotesNeeded)) * 100);
|
||||||
|
if (rtv_percentage_reached > 100)
|
||||||
|
{
|
||||||
|
rtv_percentage_reached = 100;
|
||||||
}
|
}
|
||||||
int rtv_percentage_reached = RoundToFloor((float(g_Votes) / float(g_VotesNeeded)) * 100);
|
|
||||||
ReplyToCommand(client, "[RTVE] %t", "Already Voted", rtv_percentage_reached, "%", rtv_worth);
|
ReplyToCommand(client, "[RTVE] %t", "Already Voted", rtv_percentage_reached, "%", rtv_worth);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -294,18 +310,22 @@ void AttemptRTV(int client)
|
|||||||
char name[MAX_NAME_LENGTH];
|
char name[MAX_NAME_LENGTH];
|
||||||
GetClientName(client, name, sizeof(name));
|
GetClientName(client, name, sizeof(name));
|
||||||
|
|
||||||
g_Votes += GetPlayerWorthRTV_(client);
|
|
||||||
g_Voted[client] = true;
|
g_Voted[client] = true;
|
||||||
|
|
||||||
|
int Votes = get_voted_rtv();
|
||||||
float rtv_worth = GetPlayerWorthRTV_boost_(client);
|
float rtv_worth = GetPlayerWorthRTV_boost_(client);
|
||||||
if (g_VotesNeeded == 0)
|
if (g_VotesNeeded == 0)
|
||||||
{
|
{
|
||||||
g_VotesNeeded = g_Votes;
|
g_VotesNeeded = Votes;
|
||||||
|
}
|
||||||
|
int rtv_percentage_reached = RoundToFloor((float(Votes) / float(g_VotesNeeded)) * 100);
|
||||||
|
if (rtv_percentage_reached > 100)
|
||||||
|
{
|
||||||
|
rtv_percentage_reached = 100;
|
||||||
}
|
}
|
||||||
int rtv_percentage_reached = RoundToFloor((float(g_Votes) / float(g_VotesNeeded)) * 100);
|
|
||||||
PrintToChatAll("[RTVE] %t", "RTV Requested", name, rtv_percentage_reached, "%", rtv_worth);
|
PrintToChatAll("[RTVE] %t", "RTV Requested", name, rtv_percentage_reached, "%", rtv_worth);
|
||||||
|
|
||||||
if (g_Votes >= g_VotesNeeded)
|
if (Votes >= g_VotesNeeded)
|
||||||
{
|
{
|
||||||
StartRTV();
|
StartRTV();
|
||||||
}
|
}
|
||||||
@ -334,7 +354,6 @@ void AttemptUnRTV(int client)
|
|||||||
char name[MAX_NAME_LENGTH];
|
char name[MAX_NAME_LENGTH];
|
||||||
GetClientName(client, name, sizeof(name));
|
GetClientName(client, name, sizeof(name));
|
||||||
|
|
||||||
g_Votes -= GetPlayerWorthRTV_(client);
|
|
||||||
g_Voted[client] = false;
|
g_Voted[client] = false;
|
||||||
g_iTimeTillRTV[client] = GetTime() + g_Cvar_RTVRevoteDelay.IntValue;
|
g_iTimeTillRTV[client] = GetTime() + g_Cvar_RTVRevoteDelay.IntValue;
|
||||||
|
|
||||||
@ -388,8 +407,6 @@ void StartRTV()
|
|||||||
|
|
||||||
void ResetRTV()
|
void ResetRTV()
|
||||||
{
|
{
|
||||||
g_Votes = 0;
|
|
||||||
|
|
||||||
for (int i=1; i<=MAXPLAYERS; i++)
|
for (int i=1; i<=MAXPLAYERS; i++)
|
||||||
{
|
{
|
||||||
g_Voted[i] = false;
|
g_Voted[i] = false;
|
||||||
@ -486,3 +503,10 @@ bool RTVAllowed()
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
stock bool IsValidClient(int client)
|
||||||
|
{
|
||||||
|
if (client > 0 && client <= MaxClients && IsClientConnected(client) && IsClientInGame(client))
|
||||||
|
return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user