rockthevote_extended: Add UnRTV

This commit is contained in:
xen 2023-02-15 14:31:06 +02:00
parent ec961cfa58
commit 5fd70ab580
2 changed files with 58 additions and 0 deletions

View File

@ -62,6 +62,7 @@ ConVar g_Cvar_ChangeTime;
ConVar g_Cvar_RTVPostVoteAction; ConVar g_Cvar_RTVPostVoteAction;
ConVar g_Cvar_RTVAutoDisable; ConVar g_Cvar_RTVAutoDisable;
ConVar g_Cvar_AFKTime; ConVar g_Cvar_AFKTime;
ConVar g_Cvar_RTVRevoteDelay;
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.
@ -69,6 +70,7 @@ int g_Voters = 0; // Total voters connected. Doesn't include fake clients.
int g_Votes = 0; // Total number of "say rtv" votes int g_Votes = 0; // Total number of "say rtv" votes
int g_VotesNeeded = 0; // Necessary votes before map vote begins. (voters * percent_needed) int g_VotesNeeded = 0; // Necessary votes before map vote begins. (voters * percent_needed)
bool g_Voted[MAXPLAYERS+1] = {false, ...}; bool g_Voted[MAXPLAYERS+1] = {false, ...};
int g_iTimeTillRTV[MAXPLAYERS+1] = {0, ...};
bool g_InChange = false; bool g_InChange = false;
@ -87,8 +89,10 @@ 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); 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);
g_Cvar_RTVAutoDisable = CreateConVar("sm_rtv_autodisable", "0", "Automatically disable RTV when map time is over.", _, true, 0.0, true, 1.0); g_Cvar_RTVAutoDisable = CreateConVar("sm_rtv_autodisable", "0", "Automatically disable RTV when map time is over.", _, true, 0.0, true, 1.0);
g_Cvar_AFKTime = CreateConVar("sm_rtv_afk_time", "180", "AFK Time in seconds after which a player is not counted in the rtv ratio"); g_Cvar_AFKTime = CreateConVar("sm_rtv_afk_time", "180", "AFK Time in seconds after which a player is not counted in the rtv ratio");
g_Cvar_RTVRevoteDelay = CreateConVar("sm_rtv_revote_delay", "5", "Delay in seconds before a player can vote for RTV after undoing");
RegConsoleCmd("sm_rtv", Command_RTV); RegConsoleCmd("sm_rtv", Command_RTV);
RegConsoleCmd("sm_unrtv", Command_UnRTV);
RegAdminCmd("sm_forcertv", Command_ForceRTV, ADMFLAG_CHANGEMAP, "Force an RTV vote"); RegAdminCmd("sm_forcertv", Command_ForceRTV, ADMFLAG_CHANGEMAP, "Force an RTV vote");
RegAdminCmd("sm_disablertv", Command_DisableRTV, ADMFLAG_CHANGEMAP, "Disable the RTV command"); RegAdminCmd("sm_disablertv", Command_DisableRTV, ADMFLAG_CHANGEMAP, "Disable the RTV command");
@ -132,6 +136,7 @@ public void OnConfigsExecuted()
public void OnClientPutInServer(int client) public void OnClientPutInServer(int client)
{ {
g_iTimeTillRTV[client] = 0;
UpdateRTV(); UpdateRTV();
} }
@ -140,6 +145,7 @@ public void OnClientDisconnect(int client)
if (g_Voted[client]) if (g_Voted[client])
{ {
g_Voted[client] = false; g_Voted[client] = false;
g_iTimeTillRTV[client] = 0;
g_Votes--; g_Votes--;
} }
@ -246,6 +252,12 @@ void AttemptRTV(int client)
return; return;
} }
if (GetTime() < g_iTimeTillRTV[client])
{
ReplyToCommand(client, "[RTVE] %t", "Wait Before Revoting", g_iTimeTillRTV[client] - GetTime());
return;
}
if (g_Voted[client]) if (g_Voted[client])
{ {
ReplyToCommand(client, "[RTVE] %t", "Already Voted", g_Votes, g_VotesNeeded); ReplyToCommand(client, "[RTVE] %t", "Already Voted", g_Votes, g_VotesNeeded);
@ -266,6 +278,36 @@ void AttemptRTV(int client)
} }
} }
public Action Command_UnRTV(int client, int args)
{
if (!g_CanRTV || !client)
{
return Plugin_Handled;
}
AttemptUnRTV(client);
return Plugin_Handled;
}
void AttemptUnRTV(int client)
{
if (!g_Voted[client])
{
ReplyToCommand(client, "[RTVE] %t", "Didn't RTV Yet");
return;
}
char name[MAX_NAME_LENGTH];
GetClientName(client, name, sizeof(name));
g_Votes--;
g_Voted[client] = false;
g_iTimeTillRTV[client] = GetTime() + g_Cvar_RTVRevoteDelay.IntValue;
ReplyToCommand(client, "[RTVE] %t", "RTV Undone");
}
public Action Timer_DelayRTV(Handle timer) public Action Timer_DelayRTV(Handle timer)
{ {
g_RTVAllowed = true; g_RTVAllowed = true;

View File

@ -25,6 +25,17 @@
"#format" "{1:d},{2:d}" "#format" "{1:d},{2:d}"
"en" "You have already voted to Rock the Vote. ({1} votes, {2} required)" "en" "You have already voted to Rock the Vote. ({1} votes, {2} required)"
} }
"Wait Before Revoting"
{
"#format" "{1:d}"
"en" "Please wait {1} seconds before you can vote to Rock the Vote again."
}
"Didn't RTV Yet"
{
"en" "You have not voted to Rock the Vote yet."
}
"Minimal Players Not Met" "Minimal Players Not Met"
{ {
@ -36,6 +47,11 @@
"#format" "{1:s},{2:d},{3:d}" "#format" "{1:s},{2:d},{3:d}"
"en" "{1} wants to rock the vote. ({2} votes, {3} required)" "en" "{1} wants to rock the vote. ({2} votes, {3} required)"
} }
"RTV Undone"
{
"en" "You have undone your vote to Rock the Vote."
}
"RTV Vote Ready" "RTV Vote Ready"
{ {