added feature so that all restrictions are removed if less than a certain amount of clients are considered active

This commit is contained in:
jenz 2023-12-10 15:17:44 +01:00
parent 8c0bfb037b
commit 5ab55caec8

View File

@ -53,6 +53,7 @@
#include <PlayerManager> #include <PlayerManager>
#include <nominations_extended> #include <nominations_extended>
#include <rockthevote_extended> #include <rockthevote_extended>
#include <AFKManager>
#pragma semicolon 1 #pragma semicolon 1
#pragma newdecls required #pragma newdecls required
@ -139,6 +140,8 @@ bool g_ChangeMapAtRoundEnd;
bool g_ChangeMapInProgress; bool g_ChangeMapInProgress;
bool g_HasIntermissionStarted = false; bool g_HasIntermissionStarted = false;
int g_mapFileSerial = -1; int g_mapFileSerial = -1;
int g_iPlayerCount_excludeSpec;
int g_iPlayerAFKTime;
int g_NominateCount = 0; int g_NominateCount = 0;
@ -285,6 +288,17 @@ public void OnPluginStart()
g_Cvar_DontChange = CreateConVar("mce_dontchange", "1", "Specifies if a 'Don't Change option should be added to early votes", _, true, 0.0); g_Cvar_DontChange = CreateConVar("mce_dontchange", "1", "Specifies if a 'Don't Change option should be added to early votes", _, true, 0.0);
g_Cvar_VoteDuration = CreateConVar("mce_voteduration", "20", "Specifies how long the mapvote should be available for.", _, true, 5.0); g_Cvar_VoteDuration = CreateConVar("mce_voteduration", "20", "Specifies how long the mapvote should be available for.", _, true, 5.0);
ConVar cvar1;
HookConVarChange((cvar1 = CreateConVar("sm_active_players_required", "15", "Amount of players required to be considered active before any restrictions are enabled at all.")), Cvar_playerExcludeSpec);
g_iPlayerCount_excludeSpec = cvar1.IntValue;
delete cvar1;
ConVar cvar;
HookConVarChange((cvar = CreateConVar("sm_mapchooser_afk_time", "120", "Time in seconds until a player is considered as AFK and therefore excluded from player average")), Cvar_playerAFKTime);
g_iPlayerAFKTime = cvar.IntValue;
delete cvar;
// MapChooser Extended cvars // MapChooser Extended cvars
CreateConVar("mce_version", MCE_VERSION, "MapChooser Extended Version", FCVAR_SPONLY|FCVAR_NOTIFY|FCVAR_DONTRECORD); CreateConVar("mce_version", MCE_VERSION, "MapChooser Extended Version", FCVAR_SPONLY|FCVAR_NOTIFY|FCVAR_DONTRECORD);
@ -413,6 +427,16 @@ public void OnPluginStart()
InternalRestoreMapCooldowns(); InternalRestoreMapCooldowns();
} }
public void Cvar_playerExcludeSpec(ConVar convar, const char[] oldValue, const char[] newValue)
{
g_iPlayerCount_excludeSpec = convar.IntValue;
}
public void Cvar_playerAFKTime(ConVar convar, const char[] oldValue, const char[] newValue)
{
g_iPlayerAFKTime = convar.IntValue;
}
public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max) public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max)
{ {
if(LibraryExists("mapchooser")) if(LibraryExists("mapchooser"))
@ -2987,26 +3011,40 @@ stock int InternalGetMapPlayerRestriction(const char[] map)
stock bool InternalAreRestrictionsActive() stock bool InternalAreRestrictionsActive()
{ {
if (!GetConVarBool(g_Cvar_NoRestrictionTimeframeEnable)) if (!GetConVarBool(g_Cvar_NoRestrictionTimeframeEnable))
return true; return true;
char sTime[8]; char sTime[8];
FormatTime(sTime, sizeof(sTime), "%H%M"); FormatTime(sTime, sizeof(sTime), "%H%M");
int CurTime = StringToInt(sTime); int CurTime = StringToInt(sTime);
int MinTime = GetConVarInt(g_Cvar_NoRestrictionTimeframeMinTime); int MinTime = GetConVarInt(g_Cvar_NoRestrictionTimeframeMinTime);
int MaxTime = GetConVarInt(g_Cvar_NoRestrictionTimeframeMaxTime); int MaxTime = GetConVarInt(g_Cvar_NoRestrictionTimeframeMaxTime);
//Wrap around. //Wrap around.
CurTime = (CurTime <= MinTime) ? CurTime + 2400 : CurTime; CurTime = (CurTime <= MinTime) ? CurTime + 2400 : CurTime;
MaxTime = (MaxTime <= MinTime) ? MaxTime + 2400 : MaxTime; MaxTime = (MaxTime <= MinTime) ? MaxTime + 2400 : MaxTime;
if ((MinTime <= CurTime <= MaxTime)) if ((MinTime <= CurTime <= MaxTime))
{ {
return false; return false;
} }
return true; int AcitvePlayerCount = 0;
for (int i = 0; i < MaxClients; i++)
{
if (IsValidClient(i) && !IsFakeClient(i) && !IsClientSourceTV(i) && !is_bot_player[i] && GetClientIdleTime(i) < g_iPlayerAFKTime)
{
AcitvePlayerCount++;
}
}
if (AcitvePlayerCount <= g_iPlayerCount_excludeSpec)
{
return false;
}
return true;
} }
stock int FindIntInArray(int[] array, int size, int value) stock int FindIntInArray(int[] array, int size, int value)