now re-evaluting each rtv when a person disconnects or connects

This commit is contained in:
jenz 2023-09-17 00:29:00 +02:00
parent 50058d15f1
commit 59eb86fa23

View File

@ -68,7 +68,6 @@ ConVar g_Cvar_RTVRevoteDelay;
bool is_bot_player[MAXPLAYERS + 1];
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_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)
bool g_Voted[MAXPLAYERS+1] = {false, ...};
int g_iTimeTillRTV[MAXPLAYERS+1] = {0, ...};
@ -106,7 +105,6 @@ public void OnPluginStart()
public void OnMapStart()
{
g_Votes = 0;
g_VotesNeeded = 0;
g_InChange = false;
@ -146,7 +144,6 @@ public void OnClientDisconnect(int client)
{
g_Voted[client] = false;
g_iTimeTillRTV[client] = 0;
g_Votes -= GetPlayerWorthRTV_(client);
}
UpdateRTV();
@ -204,9 +201,10 @@ void UpdateRTV()
return;
}
if (g_Votes &&
int Votes = get_voted_rtv();
if (Votes &&
iVotersSteam &&
g_Votes >= g_VotesNeeded &&
Votes >= g_VotesNeeded &&
RTVAllowed())
{
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)
{
if (!g_CanRTV || !client)
@ -276,11 +287,16 @@ void AttemptRTV(int client)
if (g_Voted[client])
{
float rtv_worth = GetPlayerWorthRTV_boost_(client);
int Votes = get_voted_rtv();
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);
return;
}
@ -294,18 +310,22 @@ void AttemptRTV(int client)
char name[MAX_NAME_LENGTH];
GetClientName(client, name, sizeof(name));
g_Votes += GetPlayerWorthRTV_(client);
g_Voted[client] = true;
int Votes = get_voted_rtv();
float rtv_worth = GetPlayerWorthRTV_boost_(client);
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);
if (g_Votes >= g_VotesNeeded)
if (Votes >= g_VotesNeeded)
{
StartRTV();
}
@ -334,7 +354,6 @@ void AttemptUnRTV(int client)
char name[MAX_NAME_LENGTH];
GetClientName(client, name, sizeof(name));
g_Votes -= GetPlayerWorthRTV_(client);
g_Voted[client] = false;
g_iTimeTillRTV[client] = GetTime() + g_Cvar_RTVRevoteDelay.IntValue;
@ -388,8 +407,6 @@ void StartRTV()
void ResetRTV()
{
g_Votes = 0;
for (int i=1; i<=MAXPLAYERS; i++)
{
g_Voted[i] = false;
@ -486,3 +503,10 @@ bool RTVAllowed()
return true;
}
stock bool IsValidClient(int client)
{
if (client > 0 && client <= MaxClients && IsClientConnected(client) && IsClientInGame(client))
return true;
return false;
}