From f7214dc00f03ae8dcd7be5a86102319f8f9ce2cc Mon Sep 17 00:00:00 2001 From: dogan Date: Thu, 28 May 2020 16:09:58 +0200 Subject: [PATCH] rtv: split calculation between steam and no-steam players --- .../scripting/rockthevote_extended.sp | 64 +++++++++++++++++-- 1 file changed, 57 insertions(+), 7 deletions(-) diff --git a/mapchooser_extended/scripting/rockthevote_extended.sp b/mapchooser_extended/scripting/rockthevote_extended.sp index b938a9c6..c385533f 100644 --- a/mapchooser_extended/scripting/rockthevote_extended.sp +++ b/mapchooser_extended/scripting/rockthevote_extended.sp @@ -40,6 +40,7 @@ #include #include #include +#include #define MCE_VERSION "1.3.0" @@ -52,7 +53,8 @@ public Plugin myinfo = url = "https://forums.alliedmods.net/showthread.php?t=156974" }; -ConVar g_Cvar_Needed; +ConVar g_Cvar_Steam_Needed; +ConVar g_Cvar_NoSteam_Needed; ConVar g_Cvar_MinPlayers; ConVar g_Cvar_InitialDelay; ConVar g_Cvar_Interval; @@ -76,7 +78,8 @@ public void OnPluginStart() LoadTranslations("rockthevote.phrases"); LoadTranslations("basevotes.phrases"); - g_Cvar_Needed = CreateConVar("sm_rtv_needed", "0.60", "Percentage of players needed to rockthevote (Def 60%)", 0, true, 0.05, true, 1.0); + g_Cvar_Steam_Needed = CreateConVar("sm_rtv_steam_needed", "0.65", "Percentage of Steam players needed to rockthevote (Def 65%)", 0, true, 0.05, true, 1.0); + g_Cvar_NoSteam_Needed = CreateConVar("sm_rtv_nosteam_needed", "0.45", "Percentage of No-Steam players needed to rockthevote (Def 45%)", 0, true, 0.05, true, 1.0); g_Cvar_MinPlayers = CreateConVar("sm_rtv_minplayers", "0", "Number of players required before RTV will be enabled.", 0, true, 0.0, true, float(MAXPLAYERS)); g_Cvar_InitialDelay = CreateConVar("sm_rtv_initialdelay", "30.0", "Time (in seconds) before first RTV can be held", 0, true, 0.00); g_Cvar_Interval = CreateConVar("sm_rtv_interval", "240.0", "Time (in seconds) after a failed RTV before another can be held", 0, true, 0.00); @@ -90,6 +93,7 @@ public void OnPluginStart() 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"); + RegAdminCmd("sm_debugrtv", Command_DebugRTV, ADMFLAG_CHANGEMAP, "Check the current RTV calculation"); HookEvent("player_team", OnPlayerChangedTeam, EventHookMode_PostNoCopy); @@ -150,20 +154,29 @@ public void OnPlayerChangedTeam(Handle event, const char[] name, bool dontBroadc void UpdateRTV() { g_Voters = 0; + int iVotersSteam; + int iVotersNoSteam; for (int i=1; i<=MaxClients; i++) { if (IsClientInGame(i) && !IsFakeClient(i)) { - if (GetClientIdleTime(i) <= g_Cvar_AFKTime.IntValue) - { - g_Voters++; - } + if (GetClientIdleTime(i) >= g_Cvar_AFKTime.IntValue) + continue; + + if (PM_IsPlayerSteam(i)) + iVotersSteam++; + else + iVotersNoSteam++; } } // g_Voters = GetTeamClientCount(2) + GetTeamClientCount(3); - g_VotesNeeded = RoundToFloor(float(g_Voters) * GetConVarFloat(g_Cvar_Needed)); + g_Voters = iVotersSteam + iVotersNoSteam; + int iVotesNeededSteam = RoundToFloor(float(iVotersSteam) * GetConVarFloat(g_Cvar_Steam_Needed)); + int iVotesNeededNoSteam = RoundToFloor(float(iVotersNoSteam) * GetConVarFloat(g_Cvar_NoSteam_Needed)); + + g_VotesNeeded = iVotesNeededSteam + iVotesNeededNoSteam; if (!g_CanRTV) { @@ -357,6 +370,43 @@ public Action Command_EnableRTV(int client, int args) return Plugin_Handled; } +public Action Command_DebugRTV(int client, int args) +{ + if(!g_RTVAllowed) + { + ReplyToCommand(client, "[RTVE] RockTheVote is currently disabled."); + return Plugin_Handled; + } + + int iVotersSteam = 0; + int iVotersNoSteam = 0; + + for (int i=1; i<=MaxClients; i++) + { + if (IsClientInGame(i) && !IsFakeClient(i)) + { + if (GetClientIdleTime(i) >= g_Cvar_AFKTime.IntValue) + continue; + + if (PM_IsPlayerSteam(i)) + iVotersSteam++; + else + iVotersNoSteam++; + } + } + + int iVotesNeededSteam = RoundToFloor(float(iVotersSteam) * GetConVarFloat(g_Cvar_Steam_Needed)); + int iVotesNeededNoSteam = RoundToFloor(float(iVotersNoSteam) * GetConVarFloat(g_Cvar_NoSteam_Needed)); + + int iVotesNeededTotal = iVotesNeededSteam + iVotesNeededNoSteam; + + ReplyToCommand(client, "[RTVE] Currently %d Players needed to start a RTV vote.", iVotesNeededTotal); + ReplyToCommand(client, "[RTVE] Caculated on %d Active Steam Players * %f Ratio = %d", iVotersSteam, GetConVarFloat(g_Cvar_Steam_Needed), iVotesNeededSteam); + ReplyToCommand(client, "[RTVE] + on %d Active No Steam Players * %f Ratio = %d.", iVotersNoSteam, GetConVarFloat(g_Cvar_NoSteam_Needed), iVotesNeededNoSteam); + + return Plugin_Handled; +} + bool RTVAllowed() { if(!g_RTVAllowed)