From 5fd70ab580dffb7dbd19b0cde9efff3507ae8413 Mon Sep 17 00:00:00 2001 From: xen Date: Wed, 15 Feb 2023 14:31:06 +0200 Subject: [PATCH] rockthevote_extended: Add UnRTV --- .../scripting/rockthevote_extended.sp | 42 +++++++++++++++++++ .../rockthevote_extended.phrases.txt | 16 +++++++ 2 files changed, 58 insertions(+) diff --git a/mapchooser_extended/scripting/rockthevote_extended.sp b/mapchooser_extended/scripting/rockthevote_extended.sp index b9c79b78..d8720d31 100644 --- a/mapchooser_extended/scripting/rockthevote_extended.sp +++ b/mapchooser_extended/scripting/rockthevote_extended.sp @@ -62,6 +62,7 @@ ConVar g_Cvar_ChangeTime; ConVar g_Cvar_RTVPostVoteAction; ConVar g_Cvar_RTVAutoDisable; ConVar g_Cvar_AFKTime; +ConVar g_Cvar_RTVRevoteDelay; 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. @@ -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_VotesNeeded = 0; // Necessary votes before map vote begins. (voters * percent_needed) bool g_Voted[MAXPLAYERS+1] = {false, ...}; +int g_iTimeTillRTV[MAXPLAYERS+1] = {0, ...}; 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_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_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_unrtv", Command_UnRTV); RegAdminCmd("sm_forcertv", Command_ForceRTV, ADMFLAG_CHANGEMAP, "Force an RTV vote"); RegAdminCmd("sm_disablertv", Command_DisableRTV, ADMFLAG_CHANGEMAP, "Disable the RTV command"); @@ -132,6 +136,7 @@ public void OnConfigsExecuted() public void OnClientPutInServer(int client) { + g_iTimeTillRTV[client] = 0; UpdateRTV(); } @@ -140,6 +145,7 @@ public void OnClientDisconnect(int client) if (g_Voted[client]) { g_Voted[client] = false; + g_iTimeTillRTV[client] = 0; g_Votes--; } @@ -246,6 +252,12 @@ void AttemptRTV(int client) return; } + if (GetTime() < g_iTimeTillRTV[client]) + { + ReplyToCommand(client, "[RTVE] %t", "Wait Before Revoting", g_iTimeTillRTV[client] - GetTime()); + return; + } + if (g_Voted[client]) { 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) { g_RTVAllowed = true; diff --git a/mapchooser_extended/translations/rockthevote_extended.phrases.txt b/mapchooser_extended/translations/rockthevote_extended.phrases.txt index 0b9a3d61..51836401 100644 --- a/mapchooser_extended/translations/rockthevote_extended.phrases.txt +++ b/mapchooser_extended/translations/rockthevote_extended.phrases.txt @@ -25,6 +25,17 @@ "#format" "{1:d},{2:d}" "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" { @@ -36,6 +47,11 @@ "#format" "{1:s},{2:d},{3:d}" "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" {