MCE: Adding a timeframe where all map restrictions and CDs are disabled

This commit is contained in:
neon 2019-08-17 14:31:28 +02:00
parent fe1ed7973e
commit 00c37c4db8
3 changed files with 93 additions and 21 deletions

View File

@ -132,6 +132,8 @@ native int GetMapGroupRestriction(const char[] map, int client = 0);
native bool GetMapVIPRestriction(const char[] map, int client = 0);
/**
* Amount of Extends left on the current map
*
@ -139,6 +141,8 @@ native bool GetMapVIPRestriction(const char[] map, int client = 0);
*/
native int GetExtendsLeft();
native int AreRestrictionsActive();
public SharedPlugin __pl_mapchooser_extended =
{
name = "mapchooser",

View File

@ -160,6 +160,9 @@ ConVar g_Cvar_RandomizeNominations;
ConVar g_Cvar_HideTimer;
ConVar g_Cvar_NoVoteOption;
ConVar g_Cvar_ShufflePerClient;
ConVar g_Cvar_NoRestrictionTimeframeEnable;
ConVar g_Cvar_NoRestrictionTimeframeMinTime;
ConVar g_Cvar_NoRestrictionTimeframeMaxTime;
/* Mapchooser Extended Data Handles */
Handle g_OfficialList = INVALID_HANDLE;
@ -260,6 +263,9 @@ public void OnPluginStart()
g_Cvar_HideTimer = CreateConVar("mce_hidetimer", "0", "Hide the MapChooser Extended warning timer", _, true, 0.0, true, 1.0);
g_Cvar_NoVoteOption = CreateConVar("mce_addnovote", "1", "Add \"No Vote\" to vote menu?", _, true, 0.0, true, 1.0);
g_Cvar_ShufflePerClient = CreateConVar("mce_shuffle_per_client", "1", "Random shuffle map vote menu per client?", _, true, 0.0, true, 1.0);
g_Cvar_NoRestrictionTimeframeEnable = CreateConVar("mce_no_restriction_timeframe_enable", "1", "Enable timeframe where all nomination restrictions and cooldowns are disabled?", _, true, 0.0, true, 1.0);
g_Cvar_NoRestrictionTimeframeMinTime = CreateConVar("mce_no_restriction_timeframe_mintime", "0100", "Start of the timeframe where all nomination restrictions and cooldowns are disabled (Format: HHMM)", _, true, 0000.0, true, 2359.0);
g_Cvar_NoRestrictionTimeframeMaxTime = CreateConVar("mce_no_restriction_timeframe_maxtime", "0700", "End of the timeframe where all nomination restrictions and cooldowns are disabled (Format: HHMM)", _, true, 0000.0, true, 2359.0);
RegAdminCmd("sm_mapvote", Command_Mapvote, ADMFLAG_CHANGEMAP, "sm_mapvote - Forces MapChooser to attempt to run a map vote now.");
RegAdminCmd("sm_setnextmap", Command_SetNextmap, ADMFLAG_CHANGEMAP, "sm_setnextmap <map>");
@ -410,6 +416,7 @@ public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max
CreateNative("GetMapGroupRestriction", Native_GetMapGroupRestriction);
CreateNative("GetMapVIPRestriction", Native_GetMapVIPRestriction);
CreateNative("GetExtendsLeft", Native_GetExtendsLeft);
CreateNative("AreRestrictionsActive", Native_AreRestrictionsActive);
return APLRes_Success;
}
@ -514,10 +521,14 @@ public void OnMapEnd()
g_RunoffCount = 0;
static char map[PLATFORM_MAX_PATH];
GetCurrentMap(map, PLATFORM_MAX_PATH);
int Cooldown;
int Cooldown = InternalGetMapCooldown(map);
if(InternalAreRestrictionsActive())
{
GetCurrentMap(map, PLATFORM_MAX_PATH);
Cooldown = InternalGetMapCooldown(map);
g_OldMapList.SetValue(map, Cooldown, true);
}
StringMapSnapshot OldMapListSnapshot = g_OldMapList.Snapshot();
for(int i = 0; i < OldMapListSnapshot.Length; i++)
@ -1535,7 +1546,7 @@ void CreateNextVote()
GetCurrentMap(map, PLATFORM_MAX_PATH);
RemoveStringFromArray(tempMaps, map);
if(GetConVarInt(g_Cvar_ExcludeMaps) && GetArraySize(tempMaps) > GetConVarInt(g_Cvar_ExcludeMaps))
if((GetConVarInt(g_Cvar_ExcludeMaps) && GetArraySize(tempMaps) > GetConVarInt(g_Cvar_ExcludeMaps)) && (InternalAreRestrictionsActive()))
{
StringMapSnapshot OldMapListSnapshot = g_OldMapList.Snapshot();
for(int i = 0; i < OldMapListSnapshot.Length; i++)
@ -1579,6 +1590,13 @@ void CreateNextVote()
b = GetRandomInt(0, GetArraySize(tempMaps) - 1);
GetArrayString(tempMaps, b, map, PLATFORM_MAX_PATH);
if(!InternalAreRestrictionsActive())
{
PushArrayString(g_NextMapList, map);
RemoveFromArray(tempMaps, b);
break;
}
if(InternalGetMapVIPRestriction(map))
continue;
@ -1974,6 +1992,9 @@ public int Native_CanNominate(Handle plugin, int numParams)
public int Native_ExcludeMap(Handle plugin, int numParams)
{
if(!InternalAreRestrictionsActive())
return true;
int len;
GetNativeStringLength(1, len);
@ -2219,6 +2240,11 @@ public int Native_GetExtendsLeft(Handle plugin, int numParams)
return GetConVarInt(g_Cvar_Extend) - g_Extends;
}
public int Native_AreRestrictionsActive(Handle plugin, int numParams)
{
return InternalAreRestrictionsActive();
}
stock void AddMapItem(const char[] map)
{
AddMenuItem(g_VoteMenu, map, map);
@ -2278,6 +2304,9 @@ stock int InternalGetMapCooldown(const char[] map)
void CheckMapRestrictions(bool time = false, bool players = false)
{
if(!InternalAreRestrictionsActive())
return;
static char map[PLATFORM_MAX_PATH];
for(int i = 0; i < GetArraySize(g_NominateList); i++)
{
@ -2482,6 +2511,30 @@ stock int InternalGetMapPlayerRestriction(const char[] map)
return 0;
}
stock int InternalAreRestrictionsActive()
{
if (!GetConVarBool(g_Cvar_NoRestrictionTimeframeEnable))
return 1;
char sTime[8];
FormatTime(sTime, sizeof(sTime), "%H%M");
int CurTime = StringToInt(sTime);
int MinTime = GetConVarInt(g_Cvar_NoRestrictionTimeframeMinTime);
int MaxTime = GetConVarInt(g_Cvar_NoRestrictionTimeframeMaxTime);
//Wrap around.
CurTime = (CurTime <= MinTime) ? CurTime + 2400 : CurTime;
MaxTime = (MaxTime <= MinTime) ? MaxTime + 2400 : MaxTime;
if ((MinTime <= CurTime <= MaxTime))
{
return 0;
}
return 1;
}
stock int FindIntInArray(int[] array, int size, int value)
{
for(int i = 0; i < size; i++)

View File

@ -498,7 +498,7 @@ public Action Command_Nominate(int client, int args)
if((status & MAPSTATUS_EXCLUDE_CURRENT) == MAPSTATUS_EXCLUDE_CURRENT)
CPrintToChat(client, "[NE] %t", "Can't Nominate Current Map");
if((status & MAPSTATUS_EXCLUDE_PREVIOUS) == MAPSTATUS_EXCLUDE_PREVIOUS)
if(((status & MAPSTATUS_EXCLUDE_PREVIOUS) == MAPSTATUS_EXCLUDE_PREVIOUS) && AreRestrictionsActive())
{
int Cooldown = GetMapCooldown(mapname);
CPrintToChat(client, "[NE] %t (%d)", "Map in Exclude List", Cooldown);
@ -511,7 +511,7 @@ public Action Command_Nominate(int client, int args)
}
bool VIPRestriction = GetMapVIPRestriction(mapname, client);
if(VIPRestriction)
if((VIPRestriction) && AreRestrictionsActive())
{
CPrintToChat(client, "[NE] %t", "Map Nominate VIP Error");
@ -519,7 +519,7 @@ public Action Command_Nominate(int client, int args)
}
int TimeRestriction = GetMapTimeRestriction(mapname);
if(TimeRestriction)
if((TimeRestriction) && AreRestrictionsActive())
{
CPrintToChat(client, "[NE] %t", "Map Nominate Time Error", RoundToFloor(float(TimeRestriction / 60)), TimeRestriction % 60);
@ -527,7 +527,7 @@ public Action Command_Nominate(int client, int args)
}
int PlayerRestriction = GetMapPlayerRestriction(mapname);
if(PlayerRestriction)
if((PlayerRestriction) && AreRestrictionsActive())
{
if(PlayerRestriction < 0)
CPrintToChat(client, "[NE] %t", "Map Nominate MinPlayers Error", PlayerRestriction * -1);
@ -538,7 +538,7 @@ public Action Command_Nominate(int client, int args)
}
int GroupRestriction = GetMapGroupRestriction(mapname, client);
if(GroupRestriction >= 0)
if((GroupRestriction >= 0) && AreRestrictionsActive())
{
CPrintToChat(client, "[NE] %t", "Map Nominate Group Error", GroupRestriction);
return Plugin_Handled;
@ -636,7 +636,7 @@ public int Handler_NominateListMenu(Menu menu, MenuAction action, int param1, in
GetMenuItem(menu, param2, map, sizeof(map));
bool VIPRestriction = GetMapVIPRestriction(map);
if(VIPRestriction)
if((VIPRestriction) && AreRestrictionsActive())
{
Format(display, sizeof(display), "%s (%T)", map, "VIP Nomination", param1);
return RedrawMenuItem(display);
@ -749,7 +749,7 @@ public int Handler_MapSelectMenu(Menu menu, MenuAction action, int param1, int p
GetClientName(param1, name, MAX_NAME_LENGTH);
if(GetMapTimeRestriction(map) || GetMapPlayerRestriction(map) || GetMapGroupRestriction(map, param1) >= 0 || GetMapVIPRestriction(map, param1))
if((GetMapTimeRestriction(map) || GetMapPlayerRestriction(map) || GetMapGroupRestriction(map, param1) >= 0 || GetMapVIPRestriction(map, param1)) && AreRestrictionsActive())
{
PrintToChat(param1, "[NE] You can't nominate this map right now.");
return 0;
@ -794,9 +794,24 @@ public int Handler_MapSelectMenu(Menu menu, MenuAction action, int param1, int p
}
if((status & MAPSTATUS_DISABLED) == MAPSTATUS_DISABLED)
{
if((status & MAPSTATUS_EXCLUDE_CURRENT) == MAPSTATUS_EXCLUDE_CURRENT)
{
return ITEMDRAW_DISABLED;
}
if(GetMapTimeRestriction(map) || GetMapPlayerRestriction(map) || GetMapGroupRestriction(map, param1) >= 0 || GetMapVIPRestriction(map, param1))
if(((status & MAPSTATUS_EXCLUDE_PREVIOUS) == MAPSTATUS_EXCLUDE_PREVIOUS) && AreRestrictionsActive())
{
return ITEMDRAW_DISABLED;
}
if((status & MAPSTATUS_EXCLUDE_NOMINATED) == MAPSTATUS_EXCLUDE_NOMINATED)
{
return ITEMDRAW_DISABLED;
}
}
if((GetMapTimeRestriction(map) || GetMapPlayerRestriction(map) || GetMapGroupRestriction(map, param1) >= 0 || GetMapVIPRestriction(map, param1)) && AreRestrictionsActive())
return ITEMDRAW_DISABLED;
return ITEMDRAW_DEFAULT;
@ -843,7 +858,7 @@ public int Handler_MapSelectMenu(Menu menu, MenuAction action, int param1, int p
strcopy(buffer, sizeof(buffer), map);
bool VIPRestriction = GetMapVIPRestriction(map);
if(VIPRestriction)
if((VIPRestriction) && AreRestrictionsActive())
{
Format(buffer, sizeof(buffer), "%s (%T)", buffer, "VIP Restriction", param1);
}
@ -856,7 +871,7 @@ public int Handler_MapSelectMenu(Menu menu, MenuAction action, int param1, int p
return RedrawMenuItem(display);
}
if((status & MAPSTATUS_EXCLUDE_PREVIOUS) == MAPSTATUS_EXCLUDE_PREVIOUS)
if(((status & MAPSTATUS_EXCLUDE_PREVIOUS) == MAPSTATUS_EXCLUDE_PREVIOUS) && AreRestrictionsActive())
{
int Cooldown = GetMapCooldown(map);
Format(display, sizeof(display), "%s (%T %d)", buffer, "Recently Played", param1, Cooldown);
@ -871,14 +886,14 @@ public int Handler_MapSelectMenu(Menu menu, MenuAction action, int param1, int p
}
int TimeRestriction = GetMapTimeRestriction(map);
if(TimeRestriction)
if((TimeRestriction) && AreRestrictionsActive())
{
Format(display, sizeof(display), "%s (%T)", buffer, "Map Time Restriction", param1, "+", RoundToFloor(float(TimeRestriction / 60)), TimeRestriction % 60);
return RedrawMenuItem(display);
}
int PlayerRestriction = GetMapPlayerRestriction(map);
if(PlayerRestriction)
if((PlayerRestriction) && AreRestrictionsActive())
{
if(PlayerRestriction < 0)
Format(display, sizeof(display), "%s (%T)", buffer, "Map Player Restriction", param1, "+", PlayerRestriction * -1);
@ -889,13 +904,13 @@ public int Handler_MapSelectMenu(Menu menu, MenuAction action, int param1, int p
}
int GroupRestriction = GetMapGroupRestriction(map, param1);
if(GroupRestriction >= 0)
if((GroupRestriction >= 0) && AreRestrictionsActive())
{
Format(display, sizeof(display), "%s (%T)", buffer, "Map Group Restriction", param1, GroupRestriction);
return RedrawMenuItem(display);
}
if(VIPRestriction)
if((VIPRestriction) && AreRestrictionsActive())
{
return RedrawMenuItem(buffer);
}
@ -921,7 +936,7 @@ stock bool IsNominateAllowed(int client)
if (!CheckCommandAccess(client, "sm_tag", ADMFLAG_CUSTOM1))
{
int VIPTimeRestriction = GetVIPTimeRestriction();
if(VIPTimeRestriction)
if((VIPTimeRestriction) && AreRestrictionsActive())
{
CReplyToCommand(client, "[NE] During peak hours only VIPs are allowed to nominate maps. Wait for %d hours and %d minutes or buy VIP at Unloze.com to nominate maps again.", RoundToFloor(float(VIPTimeRestriction / 60)), VIPTimeRestriction % 60);
return false;