From 3c19b91972bc09d0e4564eced82743c3f07c7b44 Mon Sep 17 00:00:00 2001 From: neon <> Date: Thu, 20 Sep 2018 11:32:50 +0200 Subject: [PATCH] nominations_extended: added time based restrictions for non-VIPs --- .../scripting/nominations_extended.sp | 57 ++++++++++++++++++- 1 file changed, 56 insertions(+), 1 deletion(-) diff --git a/mapchooser_extended/scripting/nominations_extended.sp b/mapchooser_extended/scripting/nominations_extended.sp index 7d09db00..c22c6840 100644 --- a/mapchooser_extended/scripting/nominations_extended.sp +++ b/mapchooser_extended/scripting/nominations_extended.sp @@ -75,6 +75,11 @@ Handle g_Cvar_MarkCustomMaps = INVALID_HANDLE; Handle g_Cvar_NominateDelay = INVALID_HANDLE; Handle g_Cvar_InitialDelay = INVALID_HANDLE; +// VIP Nomination Convars +Handle g_Cvar_VIPTimeframe = INVALID_HANDLE; +Handle g_Cvar_VIPTimeframeMinTime = INVALID_HANDLE; +Handle g_Cvar_VIPTimeframeMaxTime = INVALID_HANDLE; + int g_Player_NominationDelay[MAXPLAYERS+1]; int g_NominationDelay; @@ -94,6 +99,10 @@ public void OnPluginStart() g_Cvar_InitialDelay = CreateConVar("sm_nominate_initialdelay", "60.0", "Time in seconds before first Nomination can be made", 0, true, 0.00); g_Cvar_NominateDelay = CreateConVar("sm_nominate_delay", "3.0", "Delay between nominations", 0, true, 0.00, true, 60.00); + g_Cvar_VIPTimeframe = CreateConVar("sm_nominate_vip_timeframe", "1", "Specifies if the should be a timeframe where only VIPs can nominate maps", 0, true, 0.00, true, 1.0); + g_Cvar_VIPTimeframeMinTime = CreateConVar("sm_nominate_vip_timeframe_mintime", "1800", "Start of the timeframe where only VIPs can nominate maps (Format: HHMM)", 0, true, 0000.00, true, 2359.0); + g_Cvar_VIPTimeframeMaxTime = CreateConVar("sm_nominate_vip_timeframe_maxtime", "2200", "End of the timeframe where only VIPs can nominate maps (Format: HHMM)", 0, true, 0000.00, true, 2359.0); + RegConsoleCmd("say", Command_Say); RegConsoleCmd("say_team", Command_Say); @@ -863,8 +872,21 @@ public int Handler_MapSelectMenu(Menu menu, MenuAction action, int param1, int p stock bool IsNominateAllowed(int client) { - if(BaseComm_IsClientGagged(client)) + if (BaseComm_IsClientGagged(client)) + { + CReplyToCommand(client, "[NE] You are not allowed to nominate maps while you are gagged."); return false; + } + + if (!CheckCommandAccess(client, "sm_tag", ADMFLAG_CUSTOM1)) + { + int VIPTimeRestriction = GetVIPTimeRestriction(); + if(VIPTimeRestriction) + { + 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; + } + } CanNominateResult result = CanNominate(); @@ -1104,3 +1126,36 @@ public int Native_RemoveMapsFromNominationPool(Handle plugin, int numArgs) return 0; } + +stock int GetVIPTimeRestriction() +{ + if (!GetConVarBool(g_Cvar_VIPTimeframe)) + return 0; + + char sTime[8]; + FormatTime(sTime, sizeof(sTime), "%H%M"); + + int CurTime = StringToInt(sTime); + int MinTime = GetConVarInt(g_Cvar_VIPTimeframeMinTime); + int MaxTime = GetConVarInt(g_Cvar_VIPTimeframeMaxTime); + + //Wrap around. + CurTime = (CurTime <= MinTime) ? CurTime + 2400 : CurTime; + MaxTime = (MaxTime <= MinTime) ? MaxTime + 2400 : MaxTime; + + if ((MinTime <= CurTime <= MaxTime)) + { + //Wrap around. + MinTime = (MinTime <= CurTime) ? MinTime + 2400 : MinTime; + MinTime = (MinTime <= MaxTime) ? MinTime + 2400 : MinTime; + + // Convert our 'time' to minutes. + CurTime = (RoundToFloor(float(CurTime / 100)) * 60) + (CurTime % 100); + MinTime = (RoundToFloor(float(MinTime / 100)) * 60) + (MinTime % 100); + MaxTime = (RoundToFloor(float(MaxTime / 100)) * 60) + (MaxTime % 100); + + return MaxTime - CurTime; + } + + return 0; +}