From bf8bd72176ad091fcf2925f29d0983a1e11a6621 Mon Sep 17 00:00:00 2001 From: BotoX Date: Wed, 18 Sep 2019 09:22:41 +0200 Subject: [PATCH 1/4] Revert "MCE: replace map-based CD system with time-based one" This reverts commit 217f1680e0d4db796b8f1ad524845c204de6da21. --- .../scripting/mapchooser_extended.sp | 27 ++++++---------- .../scripting/nominations_extended.sp | 31 +++---------------- .../mapchooser_extended.phrases.txt | 14 +-------- 3 files changed, 16 insertions(+), 56 deletions(-) diff --git a/mapchooser_extended/scripting/mapchooser_extended.sp b/mapchooser_extended/scripting/mapchooser_extended.sp index 4e57c0f0..26577c96 100644 --- a/mapchooser_extended/scripting/mapchooser_extended.sp +++ b/mapchooser_extended/scripting/mapchooser_extended.sp @@ -237,7 +237,7 @@ public void OnPluginStart() g_Cvar_ExtendTimeStep = CreateConVar("mce_extend_timestep", "15", "Specifies how much many more minutes each extension makes", _, true, 5.0); g_Cvar_ExtendRoundStep = CreateConVar("mce_extend_roundstep", "5", "Specifies how many more rounds each extension makes", _, true, 1.0); g_Cvar_ExtendFragStep = CreateConVar("mce_extend_fragstep", "10", "Specifies how many more frags are allowed when map is extended.", _, true, 5.0); - g_Cvar_ExcludeMaps = CreateConVar("mce_exclude", "5", "Specifies for how many hours past maps should be excluded from the vote.", _, true, 0.0); + g_Cvar_ExcludeMaps = CreateConVar("mce_exclude", "5", "Specifies how many past maps to exclude from the vote.", _, true, 0.0); g_Cvar_IncludeMaps = CreateConVar("mce_include", "5", "Specifies how many maps to include in the vote.", _, true, 2.0, true, 7.0); g_Cvar_IncludeMapsReserved = CreateConVar("mce_include_reserved", "2", "Specifies how many private/random maps to include in the vote.", _, true, 0.0, true, 5.0); g_Cvar_NoVoteMode = CreateConVar("mce_novote", "1", "Specifies whether or not MapChooser should pick a map if no votes are received.", _, true, 0.0, true, 1.0); @@ -378,8 +378,6 @@ public void OnPluginStart() g_MapVoteRunoffStartForward = CreateGlobalForward("OnMapVoteRunnoffWarningStart", ET_Ignore); InternalRestoreMapCooldowns(); - - CreateTimer(60.0, UpdateCooldowns, INVALID_HANDLE, TIMER_REPEAT); } public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max) @@ -528,28 +526,23 @@ public void OnMapEnd() g_WarningTimer = INVALID_HANDLE; g_RunoffCount = 0; - if(g_SaveCDOnMapEnd) - { - static char map[PLATFORM_MAX_PATH]; - GetCurrentMap(map, PLATFORM_MAX_PATH); - int Cooldown = InternalGetMapCooldown(map); - g_OldMapList.SetValue(map, Cooldown, true); - InternalStoreMapCooldowns(); - } -} - -public Action UpdateCooldowns(Handle timer) -{ static char map[PLATFORM_MAX_PATH]; int Cooldown; + if(g_SaveCDOnMapEnd) + { + 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++) { OldMapListSnapshot.GetKey(i, map, sizeof(map)); g_OldMapList.GetValue(map, Cooldown); - Cooldown --; + Cooldown--; if(Cooldown > 0) g_OldMapList.SetValue(map, Cooldown, true); else @@ -2308,7 +2301,7 @@ stock int InternalGetMapCooldown(const char[] map) g_Config.Rewind(); } - return RoundToNearest(Cooldown * 60.0); + return Cooldown; } void CheckMapRestrictions(bool time = false, bool players = false) diff --git a/mapchooser_extended/scripting/nominations_extended.sp b/mapchooser_extended/scripting/nominations_extended.sp index 933d9874..b6d039a5 100644 --- a/mapchooser_extended/scripting/nominations_extended.sp +++ b/mapchooser_extended/scripting/nominations_extended.sp @@ -118,8 +118,6 @@ public void OnPluginStart() CreateConVar("ne_version", MCE_VERSION, "Nominations Extended Version", FCVAR_SPONLY|FCVAR_NOTIFY|FCVAR_DONTRECORD); g_mapTrie = CreateTrie(); - - CreateTimer(60.0, ForceUpdate, INVALID_HANDLE, TIMER_REPEAT); } public APLRes AskPluginLoad2(Handle hThis, bool bLate, char[] err, int iErrLen) @@ -241,11 +239,6 @@ void UpdateMapTrie() delete excludeMaps; } -public Action ForceUpdate(Handle timer) -{ - UpdateMapTrie(); -} - public void OnNominationRemoved(const char[] map, int owner) { int status; @@ -298,9 +291,7 @@ public Action Command_Addmap(int client, int args) if((status & MAPSTATUS_EXCLUDE_PREVIOUS) == MAPSTATUS_EXCLUDE_PREVIOUS) { int Cooldown = GetMapCooldown(mapname); - int ConvertedCooldown[2]; - ConvertCooldown(Cooldown, ConvertedCooldown); - CPrintToChat(client, "[NE] %T", "Map Nominate Cooldown Error", client, ConvertedCooldown[0], ConvertedCooldown[1]); + CPrintToChat(client, "[NE] %t (%d)", "Map in Exclude List", Cooldown); } if((status & MAPSTATUS_EXCLUDE_NOMINATED) == MAPSTATUS_EXCLUDE_NOMINATED) @@ -394,7 +385,7 @@ public Action Command_AddExclude(int client, int args) { if(args < 1) { - CReplyToCommand(client, "[NE] Usage: sm_nominate_exclude [cooldown (minutes)] [mode]"); + CReplyToCommand(client, "[NE] Usage: sm_nominate_exclude "); return Plugin_Handled; } @@ -510,9 +501,7 @@ public Action Command_Nominate(int client, int args) if(((status & MAPSTATUS_EXCLUDE_PREVIOUS) == MAPSTATUS_EXCLUDE_PREVIOUS) && AreRestrictionsActive()) { int Cooldown = GetMapCooldown(mapname); - int ConvertedCooldown[2]; - ConvertCooldown(Cooldown, ConvertedCooldown); - CPrintToChat(client, "[NE] %T", "Map Nominate Cooldown Error", client, ConvertedCooldown[0], ConvertedCooldown[1]); + CPrintToChat(client, "[NE] %t (%d)", "Map in Exclude List", Cooldown); } if((status & MAPSTATUS_EXCLUDE_NOMINATED) == MAPSTATUS_EXCLUDE_NOMINATED) @@ -885,9 +874,7 @@ public int Handler_MapSelectMenu(Menu menu, MenuAction action, int param1, int p if(((status & MAPSTATUS_EXCLUDE_PREVIOUS) == MAPSTATUS_EXCLUDE_PREVIOUS) && AreRestrictionsActive()) { int Cooldown = GetMapCooldown(map); - int ConvertedCooldown[2]; - ConvertCooldown(Cooldown, ConvertedCooldown); - Format(display, sizeof(display), "%s (%T)", buffer, "Map Cooldown", param1, ConvertedCooldown[0], ConvertedCooldown[1]); + Format(display, sizeof(display), "%s (%T %d)", buffer, "Recently Played", param1, Cooldown); return RedrawMenuItem(display); } @@ -1063,9 +1050,7 @@ public int Handler_AdminMapSelectMenu(Menu menu, MenuAction action, int param1, if((status & MAPSTATUS_EXCLUDE_PREVIOUS) == MAPSTATUS_EXCLUDE_PREVIOUS) { int Cooldown = GetMapCooldown(map); - int ConvertedCooldown[2]; - ConvertCooldown(Cooldown, ConvertedCooldown); - Format(display, sizeof(display), "%s (%T)", buffer, "Map Cooldown", param1, ConvertedCooldown[0], ConvertedCooldown[1]); + Format(display, sizeof(display), "%s (%T %d)", buffer, "Recently Played", param1, Cooldown); return RedrawMenuItem(display); } @@ -1229,9 +1214,3 @@ stock int GetVIPTimeRestriction() return 0; } - -stock void ConvertCooldown(int Cooldown, int Time[2]) -{ - Time[0] = Cooldown / 60; - Time[1] = Cooldown - (Time[0] * 60); -} diff --git a/mapchooser_extended/translations/mapchooser_extended.phrases.txt b/mapchooser_extended/translations/mapchooser_extended.phrases.txt index e252fd61..07ad85a4 100644 --- a/mapchooser_extended/translations/mapchooser_extended.phrases.txt +++ b/mapchooser_extended/translations/mapchooser_extended.phrases.txt @@ -111,15 +111,9 @@ "en" "VIP Nomination" } - "Map Nominate Cooldown Error" - { - "#format" "{1:d},{2:d}" - "en" "You need to wait {1} hours and {2} minutes for the map to come off cooldown." - } - "Map Nominate VIP Error" { - "en" "You need to be VIP to nominate this map." + "en" "Only VIPs can nominate this map." } "Map Nominate Time Error" @@ -146,12 +140,6 @@ "en" "The maximum amount ({1}) of maps from this group has already been nominated." } - "Map Cooldown" - { - "#format" "{1:d},{2:d}" - "en" "Cooldown: {1}H{2}M" - } - "Map Time Restriction" { "#format" "{1:s},{2:d},{3:d}" From 04660fde951365a88f64f5f7f1d0fa65a494d7bc Mon Sep 17 00:00:00 2001 From: BotoX Date: Wed, 18 Sep 2019 12:36:08 +0200 Subject: [PATCH 2/4] WIP --- .../scripting/include/mapchooser_extended.inc | 5 +- .../scripting/mapchooser_extended.sp | 152 +++++++++++++++++- .../scripting/nominations_extended.sp | 77 ++++++--- .../mapchooser_extended.phrases.txt | 70 ++++---- 4 files changed, 238 insertions(+), 66 deletions(-) diff --git a/mapchooser_extended/scripting/include/mapchooser_extended.inc b/mapchooser_extended/scripting/include/mapchooser_extended.inc index ceb9fdff..9ca9c730 100644 --- a/mapchooser_extended/scripting/include/mapchooser_extended.inc +++ b/mapchooser_extended/scripting/include/mapchooser_extended.inc @@ -106,8 +106,11 @@ native CanNominateResult CanNominate(); * @return true on success */ native bool ExcludeMap(const char[] map, int cooldown = 0, int mode = 0); +// Cooldown in minutes +native bool ExcludeMapTime(const char[] map, int cooldown = 0, int mode = 0); native int GetMapCooldown(const char[] map); +native int GetMapCooldownTime(const char[] map); // in unix time native int GetMapMinTime(const char[] map); native int GetMapMaxTime(const char[] map); native int GetMapMinPlayers(const char[] map); @@ -141,7 +144,7 @@ native bool GetMapVIPRestriction(const char[] map, int client = 0); */ native int GetExtendsLeft(); -native int AreRestrictionsActive(); +native bool AreRestrictionsActive(); public SharedPlugin __pl_mapchooser_extended = { diff --git a/mapchooser_extended/scripting/mapchooser_extended.sp b/mapchooser_extended/scripting/mapchooser_extended.sp index 26577c96..fedeae1a 100644 --- a/mapchooser_extended/scripting/mapchooser_extended.sp +++ b/mapchooser_extended/scripting/mapchooser_extended.sp @@ -105,6 +105,7 @@ ConVar g_Cvar_ExtendTimeStep; ConVar g_Cvar_ExtendRoundStep; ConVar g_Cvar_ExtendFragStep; ConVar g_Cvar_ExcludeMaps; +ConVar g_Cvar_ExcludeMapsTime; ConVar g_Cvar_IncludeMaps; ConVar g_Cvar_IncludeMapsReserved; ConVar g_Cvar_NoVoteMode; @@ -122,6 +123,7 @@ Handle g_MapList = INVALID_HANDLE; Handle g_NominateList = INVALID_HANDLE; Handle g_NominateOwners = INVALID_HANDLE; StringMap g_OldMapList; +StringMap g_TimeMapList; Handle g_NextMapList = INVALID_HANDLE; Handle g_VoteMenu = INVALID_HANDLE; KeyValues g_Config; @@ -224,6 +226,7 @@ public void OnPluginStart() g_NominateList = CreateArray(arraySize); g_NominateOwners = CreateArray(1); g_OldMapList = new StringMap(); + g_TimeMapList = new StringMap(); g_NextMapList = CreateArray(arraySize); g_OfficialList = CreateArray(arraySize); @@ -238,6 +241,7 @@ public void OnPluginStart() g_Cvar_ExtendRoundStep = CreateConVar("mce_extend_roundstep", "5", "Specifies how many more rounds each extension makes", _, true, 1.0); g_Cvar_ExtendFragStep = CreateConVar("mce_extend_fragstep", "10", "Specifies how many more frags are allowed when map is extended.", _, true, 5.0); g_Cvar_ExcludeMaps = CreateConVar("mce_exclude", "5", "Specifies how many past maps to exclude from the vote.", _, true, 0.0); + g_Cvar_ExcludeMapsTime = CreateConVar("mce_exclude_time", "5", "Specifies how long in minutes an old map is excluded from the vote.", _, true, 0.0); g_Cvar_IncludeMaps = CreateConVar("mce_include", "5", "Specifies how many maps to include in the vote.", _, true, 2.0, true, 7.0); g_Cvar_IncludeMapsReserved = CreateConVar("mce_include_reserved", "2", "Specifies how many private/random maps to include in the vote.", _, true, 0.0, true, 5.0); g_Cvar_NoVoteMode = CreateConVar("mce_novote", "1", "Specifies whether or not MapChooser should pick a map if no votes are received.", _, true, 0.0, true, 1.0); @@ -406,7 +410,9 @@ public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max CreateNative("IsMapOfficial", Native_IsMapOfficial); CreateNative("CanNominate", Native_CanNominate); CreateNative("ExcludeMap", Native_ExcludeMap); + CreateNative("ExcludeMapTime", Native_ExcludeMapTime); CreateNative("GetMapCooldown", Native_GetMapCooldown); + CreateNative("GetMapCooldownTime", Native_GetMapCooldownTime); CreateNative("GetMapMinTime", Native_GetMapMinTime); CreateNative("GetMapMaxTime", Native_GetMapMaxTime); CreateNative("GetMapMinPlayers", Native_GetMapMinPlayers); @@ -534,6 +540,9 @@ public void OnMapEnd() GetCurrentMap(map, PLATFORM_MAX_PATH); Cooldown = InternalGetMapCooldown(map); g_OldMapList.SetValue(map, Cooldown, true); + + Cooldown = InternalGetMapCooldownTime(map); + g_TimeMapList.SetValue(map, Cooldown, true); } StringMapSnapshot OldMapListSnapshot = g_OldMapList.Snapshot(); @@ -548,8 +557,20 @@ public void OnMapEnd() else g_OldMapList.Remove(map); } - InternalStoreMapCooldowns(); delete OldMapListSnapshot; + + StringMapSnapshot TimeMapListSnapshot = g_TimeMapList.Snapshot(); + for(int i = 0; i < TimeMapListSnapshot.Length; i++) + { + TimeMapListSnapshot.GetKey(i, map, sizeof(map)); + g_TimeMapList.GetValue(map, Cooldown); + + if(Cooldown < GetTime()) + g_TimeMapList.Remove(map); + } + delete OldMapListSnapshot; + + InternalStoreMapCooldowns(); } public void OnClientPutInServer(int client) @@ -1552,7 +1573,7 @@ void CreateNextVote() GetCurrentMap(map, PLATFORM_MAX_PATH); RemoveStringFromArray(tempMaps, map); - if((GetConVarInt(g_Cvar_ExcludeMaps) && GetArraySize(tempMaps) > GetConVarInt(g_Cvar_ExcludeMaps)) && (InternalAreRestrictionsActive())) + 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++) @@ -1563,6 +1584,21 @@ void CreateNextVote() delete OldMapListSnapshot; } + if(GetConVarInt(g_Cvar_ExcludeMapsTime) && InternalAreRestrictionsActive()) + { + StringMapSnapshot TimeMapListSnapshot = g_TimeMapList.Snapshot(); + for(int i = 0; i < TimeMapListSnapshot.Length; i++) + { + TimeMapListSnapshot.GetKey(i, map, sizeof(map)); + int Cooldown; + g_TimeMapList.GetValue(map, Cooldown); + + if(Cooldown > GetTime()) + RemoveStringFromArray(tempMaps, map); + } + delete TimeMapListSnapshot; + } + int voteSize = GetVoteSize(2); int limit = (voteSize < GetArraySize(tempMaps) ? voteSize : GetArraySize(tempMaps)); @@ -2031,8 +2067,51 @@ public int Native_ExcludeMap(Handle plugin, int numParams) return true; } +public int Native_ExcludeMapTime(Handle plugin, int numParams) +{ + if(!InternalAreRestrictionsActive()) + return true; + + int len; + GetNativeStringLength(1, len); + + if(len <= 0) + return false; + + char[] map = new char[len+1]; + GetNativeString(1, map, len+1); + + int Cooldown; + int Mode = GetNativeCell(3); + + if(Mode == 0) + { + Cooldown = InternalGetMapCooldownTime(map); + } + else if(Mode == 1) + { + Cooldown = GetNativeCell(2) * 60; + } + else if(Mode == 2) + { + g_TimeMapList.GetValue(map, Cooldown); + int NewCooldown = GetTime() + GetNativeCell(2) * 60; + if(NewCooldown > Cooldown) + Cooldown = GetNativeCell(2) * 60; + } + + Cooldown += GetTime(); + g_TimeMapList.SetValue(map, Cooldown, true); + InternalStoreMapCooldowns(); + + return true; +} + public int Native_GetMapCooldown(Handle plugin, int numParams) { + if(!InternalAreRestrictionsActive()) + return 0; + int len; GetNativeStringLength(1, len); @@ -2048,6 +2127,26 @@ public int Native_GetMapCooldown(Handle plugin, int numParams) return Cooldown; } +public int Native_GetMapCooldownTime(Handle plugin, int numParams) +{ + if(!InternalAreRestrictionsActive()) + return 0; + + int len; + GetNativeStringLength(1, len); + + if(len <= 0) + return false; + + char[] map = new char[len+1]; + GetNativeString(1, map, len+1); + + int Cooldown = 0; + g_TimeMapList.GetValue(map, Cooldown); + + return Cooldown; +} + public int Native_GetMapMinTime(Handle plugin, int numParams) { int len; @@ -2304,6 +2403,19 @@ stock int InternalGetMapCooldown(const char[] map) return Cooldown; } +stock int InternalGetMapCooldownTime(const char[] map) +{ + int Cooldown = g_Cvar_ExcludeMapsTime.IntValue; + + if(g_Config && g_Config.JumpToKey(map)) + { + Cooldown = g_Config.GetNum("CooldownTime", Cooldown); + g_Config.Rewind(); + } + + return Cooldown; +} + void CheckMapRestrictions(bool time = false, bool players = false) { if(!InternalAreRestrictionsActive()) @@ -2513,10 +2625,10 @@ stock int InternalGetMapPlayerRestriction(const char[] map) return 0; } -stock int InternalAreRestrictionsActive() +stock bool InternalAreRestrictionsActive() { if (!GetConVarBool(g_Cvar_NoRestrictionTimeframeEnable)) - return 1; + return true; char sTime[8]; FormatTime(sTime, sizeof(sTime), "%H%M"); @@ -2531,10 +2643,10 @@ stock int InternalAreRestrictionsActive() if ((MinTime <= CurTime <= MaxTime)) { - return 0; + return false; } - return 1; + return true; } stock int FindIntInArray(int[] array, int size, int value) @@ -2605,6 +2717,12 @@ stock void InternalRestoreMapCooldowns() LogMessage("Restored cooldown: %s -> %d", map, Cooldown); g_OldMapList.SetValue(map, Cooldown, true); } + + if((Cooldown = Cooldowns.GetNum("CooldownTime", -1)) > 0) + { + LogMessage("Restored time cooldown: %s -> %d", map, Cooldown); + g_TimeMapList.SetValue(map, Cooldown, true); + } } while(Cooldowns.GotoNextKey(true)); delete Cooldowns; @@ -2643,15 +2761,33 @@ stock void InternalStoreMapCooldowns() Cooldowns.SetNum("Cooldown", Cooldown); Cooldowns.Rewind(); } + delete OldMapListSnapshot; + + StringMapSnapshot TimeMapListSnapshot = g_TimeMapList.Snapshot(); + for(int i = 0; i < TimeMapListSnapshot.Length; i++) + { + TimeMapListSnapshot.GetKey(i, map, sizeof(map)); + g_TimeMapList.GetValue(map, Cooldown); + + if (!Cooldowns.JumpToKey(map, true)) + { + LogMessage("Unable to create/find key: %s", map); + delete TimeMapListSnapshot; + delete Cooldowns; + return; + } + + Cooldowns.SetNum("CooldownTime", Cooldown); + Cooldowns.Rewind(); + } + delete TimeMapListSnapshot; if(!Cooldowns.ExportToFile(sCooldownFile)) { LogMessage("Unable to export cooldown file: \"%s\"", sCooldownFile); - delete OldMapListSnapshot; delete Cooldowns; return; } - delete OldMapListSnapshot; delete Cooldowns; } \ No newline at end of file diff --git a/mapchooser_extended/scripting/nominations_extended.sp b/mapchooser_extended/scripting/nominations_extended.sp index b6d039a5..2f8c5df7 100644 --- a/mapchooser_extended/scripting/nominations_extended.sp +++ b/mapchooser_extended/scripting/nominations_extended.sp @@ -280,6 +280,8 @@ public Action Command_Addmap(int client, int args) if(!CheckCommandAccess(client, "sm_nominate_ignore", ADMFLAG_CHEATS, true)) { + bool RestrictionsActive = AreRestrictionsActive(); + int status; if(GetTrieValue(g_mapTrie, mapname, status)) { @@ -288,7 +290,7 @@ public Action Command_Addmap(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(RestrictionsActive && (status & MAPSTATUS_EXCLUDE_PREVIOUS) == MAPSTATUS_EXCLUDE_PREVIOUS) { int Cooldown = GetMapCooldown(mapname); CPrintToChat(client, "[NE] %t (%d)", "Map in Exclude List", Cooldown); @@ -302,7 +304,7 @@ public Action Command_Addmap(int client, int args) } int TimeRestriction = GetMapTimeRestriction(mapname); - if(TimeRestriction) + if(RestrictionsActive && TimeRestriction) { CPrintToChat(client, "[NE] %t", "Map Nominate Time Error", RoundToFloor(float(TimeRestriction / 60)), TimeRestriction % 60); @@ -310,7 +312,7 @@ public Action Command_Addmap(int client, int args) } int PlayerRestriction = GetMapPlayerRestriction(mapname); - if(PlayerRestriction) + if(RestrictionsActive && PlayerRestriction) { if(PlayerRestriction < 0) CPrintToChat(client, "[NE] %t", "Map Nominate MinPlayers Error", PlayerRestriction * -1); @@ -321,7 +323,7 @@ public Action Command_Addmap(int client, int args) } int GroupRestriction = GetMapGroupRestriction(mapname); - if(GroupRestriction >= 0) + if(RestrictionsActive && GroupRestriction >= 0) { CPrintToChat(client, "[NE] %t", "Map Nominate Group Error", GroupRestriction); return Plugin_Handled; @@ -485,6 +487,7 @@ public Action Command_Nominate(int client, int args) static char mapname[PLATFORM_MAX_PATH]; GetCmdArg(1, mapname, sizeof(mapname)); + int status; if(!GetTrieValue(g_mapTrie, mapname, status)) { @@ -493,12 +496,14 @@ public Action Command_Nominate(int client, int args) return Plugin_Handled; } + bool RestrictionsActive = AreRestrictionsActive(); + if((status & MAPSTATUS_DISABLED) == MAPSTATUS_DISABLED) { 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) && AreRestrictionsActive()) + if(RestrictionsActive && (status & MAPSTATUS_EXCLUDE_PREVIOUS) == MAPSTATUS_EXCLUDE_PREVIOUS) { int Cooldown = GetMapCooldown(mapname); CPrintToChat(client, "[NE] %t (%d)", "Map in Exclude List", Cooldown); @@ -511,7 +516,7 @@ public Action Command_Nominate(int client, int args) } bool VIPRestriction = GetMapVIPRestriction(mapname, client); - if((VIPRestriction) && AreRestrictionsActive()) + if(RestrictionsActive && VIPRestriction) { CPrintToChat(client, "[NE] %t", "Map Nominate VIP Error"); @@ -519,7 +524,7 @@ public Action Command_Nominate(int client, int args) } int TimeRestriction = GetMapTimeRestriction(mapname); - if((TimeRestriction) && AreRestrictionsActive()) + if(RestrictionsActive && TimeRestriction) { CPrintToChat(client, "[NE] %t", "Map Nominate Time Error", RoundToFloor(float(TimeRestriction / 60)), TimeRestriction % 60); @@ -527,7 +532,7 @@ public Action Command_Nominate(int client, int args) } int PlayerRestriction = GetMapPlayerRestriction(mapname); - if((PlayerRestriction) && AreRestrictionsActive()) + if(RestrictionsActive && PlayerRestriction) { if(PlayerRestriction < 0) CPrintToChat(client, "[NE] %t", "Map Nominate MinPlayers Error", PlayerRestriction * -1); @@ -538,7 +543,7 @@ public Action Command_Nominate(int client, int args) } int GroupRestriction = GetMapGroupRestriction(mapname, client); - if((GroupRestriction >= 0) && AreRestrictionsActive()) + if(RestrictionsActive && GroupRestriction >= 0) { CPrintToChat(client, "[NE] %t", "Map Nominate Group Error", GroupRestriction); return Plugin_Handled; @@ -749,7 +754,12 @@ 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)) && AreRestrictionsActive()) + if(AreRestrictionsActive() && ( + GetMapCooldownTime(map) > GetTime() || + GetMapTimeRestriction(map) || + GetMapPlayerRestriction(map) || + GetMapGroupRestriction(map, param1) >= 0 || + GetMapVIPRestriction(map, param1))) { PrintToChat(param1, "[NE] You can't nominate this map right now."); return 0; @@ -800,7 +810,7 @@ public int Handler_MapSelectMenu(Menu menu, MenuAction action, int param1, int p return ITEMDRAW_DISABLED; } - if(((status & MAPSTATUS_EXCLUDE_PREVIOUS) == MAPSTATUS_EXCLUDE_PREVIOUS) && AreRestrictionsActive()) + if(AreRestrictionsActive() && (status & MAPSTATUS_EXCLUDE_PREVIOUS) == MAPSTATUS_EXCLUDE_PREVIOUS) { return ITEMDRAW_DISABLED; } @@ -811,8 +821,15 @@ public int Handler_MapSelectMenu(Menu menu, MenuAction action, int param1, int p } } - if((GetMapTimeRestriction(map) || GetMapPlayerRestriction(map) || GetMapGroupRestriction(map, param1) >= 0 || GetMapVIPRestriction(map, param1)) && AreRestrictionsActive()) + if(AreRestrictionsActive() && ( + GetMapCooldownTime(map) > GetTime() || + GetMapTimeRestriction(map) || + GetMapPlayerRestriction(map) || + GetMapGroupRestriction(map, param1) >= 0 || + GetMapVIPRestriction(map, param1))) + { return ITEMDRAW_DISABLED; + } return ITEMDRAW_DEFAULT; } @@ -857,8 +874,10 @@ public int Handler_MapSelectMenu(Menu menu, MenuAction action, int param1, int p else strcopy(buffer, sizeof(buffer), map); + bool RestrictionsActive = AreRestrictionsActive(); + bool VIPRestriction = GetMapVIPRestriction(map); - if((VIPRestriction) && AreRestrictionsActive()) + if(RestrictionsActive && VIPRestriction) { Format(buffer, sizeof(buffer), "%s (%T)", buffer, "VIP Restriction", param1); } @@ -871,7 +890,7 @@ public int Handler_MapSelectMenu(Menu menu, MenuAction action, int param1, int p return RedrawMenuItem(display); } - if(((status & MAPSTATUS_EXCLUDE_PREVIOUS) == MAPSTATUS_EXCLUDE_PREVIOUS) && AreRestrictionsActive()) + if(RestrictionsActive && (status & MAPSTATUS_EXCLUDE_PREVIOUS) == MAPSTATUS_EXCLUDE_PREVIOUS) { int Cooldown = GetMapCooldown(map); Format(display, sizeof(display), "%s (%T %d)", buffer, "Recently Played", param1, Cooldown); @@ -886,14 +905,14 @@ public int Handler_MapSelectMenu(Menu menu, MenuAction action, int param1, int p } int TimeRestriction = GetMapTimeRestriction(map); - if((TimeRestriction) && AreRestrictionsActive()) + if(RestrictionsActive && TimeRestriction) { 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) && AreRestrictionsActive()) + if(RestrictionsActive && PlayerRestriction) { if(PlayerRestriction < 0) Format(display, sizeof(display), "%s (%T)", buffer, "Map Player Restriction", param1, "+", PlayerRestriction * -1); @@ -904,13 +923,13 @@ public int Handler_MapSelectMenu(Menu menu, MenuAction action, int param1, int p } int GroupRestriction = GetMapGroupRestriction(map, param1); - if((GroupRestriction >= 0) && AreRestrictionsActive()) + if(RestrictionsActive && GroupRestriction >= 0) { Format(display, sizeof(display), "%s (%T)", buffer, "Map Group Restriction", param1, GroupRestriction); return RedrawMenuItem(display); } - if((VIPRestriction) && AreRestrictionsActive()) + if(RestrictionsActive && VIPRestriction) { return RedrawMenuItem(buffer); } @@ -1036,6 +1055,8 @@ public int Handler_AdminMapSelectMenu(Menu menu, MenuAction action, int param1, strcopy(buffer, sizeof(buffer), map); + bool RestrictionsActive = AreRestrictionsActive(); + int status; if(GetTrieValue(g_mapTrie, map, status)) { @@ -1047,7 +1068,7 @@ public int Handler_AdminMapSelectMenu(Menu menu, MenuAction action, int param1, return RedrawMenuItem(display); } - if((status & MAPSTATUS_EXCLUDE_PREVIOUS) == MAPSTATUS_EXCLUDE_PREVIOUS) + if(RestrictionsActive && (status & MAPSTATUS_EXCLUDE_PREVIOUS) == MAPSTATUS_EXCLUDE_PREVIOUS) { int Cooldown = GetMapCooldown(map); Format(display, sizeof(display), "%s (%T %d)", buffer, "Recently Played", param1, Cooldown); @@ -1063,7 +1084,7 @@ public int Handler_AdminMapSelectMenu(Menu menu, MenuAction action, int param1, } int TimeRestriction = GetMapTimeRestriction(map); - if(TimeRestriction) + if(RestrictionsActive && TimeRestriction) { Format(display, sizeof(display), "%s (%T)", buffer, "Map Time Restriction", param1, "+", RoundToFloor(float(TimeRestriction / 60)), TimeRestriction % 60); @@ -1071,7 +1092,7 @@ public int Handler_AdminMapSelectMenu(Menu menu, MenuAction action, int param1, } int PlayerRestriction = GetMapPlayerRestriction(map); - if(PlayerRestriction) + if(RestrictionsActive && PlayerRestriction) { if(PlayerRestriction < 0) Format(display, sizeof(display), "%s (%T)", buffer, "Map Player Restriction", param1, "+", PlayerRestriction * -1); @@ -1082,7 +1103,7 @@ public int Handler_AdminMapSelectMenu(Menu menu, MenuAction action, int param1, } int GroupRestriction = GetMapGroupRestriction(map); - if(GroupRestriction >= 0) + if(RestrictionsActive && GroupRestriction >= 0) { Format(display, sizeof(display), "%s (%T)", buffer, "Map Group Restriction", param1, GroupRestriction); return RedrawMenuItem(display); @@ -1214,3 +1235,15 @@ stock int GetVIPTimeRestriction() return 0; } + +stock void CustomFormatTime(int seconds, char[] buffer, int maxlen) +{ + if(seconds <= 60) + Format(buffer, maxlen, "%ds", seconds); + else if(seconds <= 3600) + Format(buffer, maxlen, "%dm", RoundToNearest(seconds / 60)); + else if(seconds <= 10*3600) + Format(buffer, maxlen, "%dh%dm", RoundToFloor(seconds / 3600), RoundToNearest((seconds % 3600) / 60)); + else + Format(buffer, maxlen, "%dh", RoundToNearest(seconds / 3600)); +} diff --git a/mapchooser_extended/translations/mapchooser_extended.phrases.txt b/mapchooser_extended/translations/mapchooser_extended.phrases.txt index 07ad85a4..ad1ca47a 100644 --- a/mapchooser_extended/translations/mapchooser_extended.phrases.txt +++ b/mapchooser_extended/translations/mapchooser_extended.phrases.txt @@ -2,45 +2,45 @@ { "Vote Nextmap" { - "en" "Vote for the next map!" + "en" "Vote for the next map!" } "Nextmap Voting Started" { - "en" "Voting for next map has started." + "en" "Voting for next map has started." } "Nextmap Voting Finished" { - "#format" "{1:s},{2:i},{3:i}" - "en" "Map voting has finished. The next map will be {1}. (Received {2}%% of {3} votes)" + "#format" "{1:s},{2:i},{3:i}" + "en" "Map voting has finished. The next map will be {1}. (Received {2}%% of {3} votes)" } "Current Map Extended" { - "#format" "{1:i},{2:i}" - "en" "The current map has been extended. (Received {1}%% of {2} votes)" + "#format" "{1:i},{2:i}" + "en" "The current map has been extended. (Received {1}%% of {2} votes)" } "Extend Map" { - "en" "Extend Current Map" + "en" "Extend Current Map" } "Dont Change" { - "en" "Don't Change" + "en" "Don't Change" } "Current Map Stays" { - "#format" "{1:i},{2:i}" - "en" "Current map continues! The Vote has spoken! (Received {1}%% of {2} votes)" + "#format" "{1:i},{2:i}" + "en" "Current map continues! The Vote has spoken! (Received {1}%% of {2} votes)" } "Changed Next Map" { - "#format" "{1:s}" + "#format" "{1:s}" "en" "Changed nextmap to \"{1}\"." } @@ -108,76 +108,76 @@ "VIP Nomination" { - "en" "VIP Nomination" + "en" "VIP" } "Map Nominate VIP Error" { - "en" "Only VIPs can nominate this map." + "en" "Only VIPs can nominate this map." } "Map Nominate Time Error" { - "#format" "{1:d},{2:d}" - "en" "You can only nominate this map in {1} hours and {2} minutes." + "#format" "{1:d},{2:d}" + "en" "You can nominate this map in {1} hours and {2} minutes." } "Map Nominate MinPlayers Error" { - "#format" "{1:d}" - "en" "Map requires {1} more players." + "#format" "{1:d}" + "en" "Map requires {1} more players." } "Map Nominate MaxPlayers Error" { - "#format" "{1:d}" - "en" "Map requires {1} less players." + "#format" "{1:d}" + "en" "Map requires {1} less players." } "Map Nominate Group Error" { - "#format" "{1:d}" - "en" "The maximum amount ({1}) of maps from this group has already been nominated." + "#format" "{1:d}" + "en" "The maximum amount ({1}) of maps from this group has already been nominated." } "Map Time Restriction" { - "#format" "{1:s},{2:d},{3:d}" - "en" "Time{1}{2}H{3}M" + "#format" "{1:s},{2:d},{3:d}" + "en" "Time{1}{2}H{3}M" } "Map Player Restriction" { - "#format" "{1:s},{2:d}" - "en" "Players{1}{2}" + "#format" "{1:s},{2:d}" + "en" "Players{1}{2}" } "Map Group Restriction" { - "#format" "{1:d}" - "en" "Group max: {1}" + "#format" "{1:d}" + "en" "Group max: {1}" } "VIP Restriction" { - "en" "VIP only" + "en" "VIP only" } "Nomination Removed Time Error" { - "#format" "{1:s}" - "en" "Your nomination {1} has been removed because it doesn't meet the time requirements." + "#format" "{1:s}" + "en" "Your nomination {1} has been removed because it doesn't meet the time requirements." } "Nomination Removed MinPlayers Error" { - "#format" "{1:s}" - "en" "Your nomination {1} has been removed because it doesn't meet the minimum player requirements." + "#format" "{1:s}" + "en" "Your nomination {1} has been removed because it doesn't meet the minimum player requirements." } "Nomination Removed MaxPlayers Error" { - "#format" "{1:s}" - "en" "Your nomination {1} has been removed because it exceeds the maximum player restriction." + "#format" "{1:s}" + "en" "Your nomination {1} has been removed because it exceeds the maximum player restriction." } -} \ No newline at end of file +} From e4e19587bbcab6561b628f47e9524784db7dcf51 Mon Sep 17 00:00:00 2001 From: BotoX Date: Wed, 18 Sep 2019 16:58:30 +0200 Subject: [PATCH 3/4] Looks good. --- .../configs/mapchooser_extended/sounds/tf.cfg | 77 ----------- .../scripting/include/mapchooser_extended.inc | 2 +- .../scripting/mapchooser_extended.sp | 44 ++++-- .../scripting/nominations_extended.sp | 130 ++++++++++++++++-- .../scripting/rockthevote_extended.sp | 2 +- .../mapchooser_extended.phrases.txt | 6 + 6 files changed, 156 insertions(+), 105 deletions(-) delete mode 100644 mapchooser_extended/configs/mapchooser_extended/sounds/tf.cfg diff --git a/mapchooser_extended/configs/mapchooser_extended/sounds/tf.cfg b/mapchooser_extended/configs/mapchooser_extended/sounds/tf.cfg deleted file mode 100644 index 92bdbb52..00000000 --- a/mapchooser_extended/configs/mapchooser_extended/sounds/tf.cfg +++ /dev/null @@ -1,77 +0,0 @@ -"MapchooserSoundsList" -{ - "tf" - { - "counter" - { - "1" - { - "sound" "sourcemod/mapchooser/tf2/announcer_begins_1sec.mp3" - "builtin" "vo/announcer_begins_1sec.wav" - "event" "Announcer.RoundBegins1Seconds" - } - "2" - { - "sound" "sourcemod/mapchooser/tf2/announcer_begins_2sec.mp3" - "builtin" "vo/announcer_begins_2sec.wav" - "event" "Announcer.RoundBegins2Seconds" - } - "3" - { - "sound" "sourcemod/mapchooser/tf2/announcer_begins_3sec.mp3" - "builtin" "vo/announcer_begins_3sec.wav" - "event" "Announcer.RoundBegins3Seconds" - } - "4" - { - "sound" "sourcemod/mapchooser/tf2/announcer_begins_4sec.mp3" - "builtin" "vo/announcer_begins_4sec.wav" - "event" "Announcer.RoundBegins4Seconds" - } - "5" - { - "sound" "sourcemod/mapchooser/tf2/announcer_begins_5sec.mp3" - "builtin" "vo/announcer_begins_5sec.wav" - "event" "Announcer.RoundBegins5Seconds" - } - "10" - { - "sound" "sourcemod/mapchooser/tf2/announcer_dec_missionbegins10s01.mp3" - "builtin" "vo/announcer_dec_missionbegins10s01.wav" - } - "30" - { - "sound" "sourcemod/mapchooser/tf2/announcer_dec_missionbegins30s01.mp3" - "builtin" "vo/announcer_dec_missionbegins30s01.wav" - } - "60" - { - "sound" "sourcemod/mapchooser/tf2/announcer_dec_missionbegins60s06.mp3" - "builtin" "vo/announcer_dec_missionbegins60s06.wav" - } - } - "vote start" - { - "sound" "sourcemod/mapchooser/tf2/vote_started.mp3" - "event" "Vote.Created" - "builtin" "ui/vote_started.wav" - } - "vote end" - { - "sound" "sourcemod/mapchooser/tf2/vote_success.mp3" - "event" "Vote.Passed" - "builtin" "ui/vote_success.wav" - } - "vote warning" - { - "sound" "sourcemod/mapchooser/tf2/announcer_dec_missionbegins60s03.mp3" - "builtin" "vo/announcer_dec_missionbegins60s03.wav" - } - "runoff warning" - { - "sound" "sourcemod/mapchooser/tf2/vote_failure.mp3" - "event" "Vote.Failed" - "builtin" "ui/vote_failure.wav" - } - } -} \ No newline at end of file diff --git a/mapchooser_extended/scripting/include/mapchooser_extended.inc b/mapchooser_extended/scripting/include/mapchooser_extended.inc index 9ca9c730..4f7a45b4 100644 --- a/mapchooser_extended/scripting/include/mapchooser_extended.inc +++ b/mapchooser_extended/scripting/include/mapchooser_extended.inc @@ -106,7 +106,7 @@ native CanNominateResult CanNominate(); * @return true on success */ native bool ExcludeMap(const char[] map, int cooldown = 0, int mode = 0); -// Cooldown in minutes +// Cooldown in seconds native bool ExcludeMapTime(const char[] map, int cooldown = 0, int mode = 0); native int GetMapCooldown(const char[] map); diff --git a/mapchooser_extended/scripting/mapchooser_extended.sp b/mapchooser_extended/scripting/mapchooser_extended.sp index fedeae1a..0f12983c 100644 --- a/mapchooser_extended/scripting/mapchooser_extended.sp +++ b/mapchooser_extended/scripting/mapchooser_extended.sp @@ -53,7 +53,7 @@ #pragma semicolon 1 #pragma newdecls required -#define MCE_VERSION "1.2.0" +#define MCE_VERSION "1.3.0" enum RoundCounting { @@ -241,7 +241,7 @@ public void OnPluginStart() g_Cvar_ExtendRoundStep = CreateConVar("mce_extend_roundstep", "5", "Specifies how many more rounds each extension makes", _, true, 1.0); g_Cvar_ExtendFragStep = CreateConVar("mce_extend_fragstep", "10", "Specifies how many more frags are allowed when map is extended.", _, true, 5.0); g_Cvar_ExcludeMaps = CreateConVar("mce_exclude", "5", "Specifies how many past maps to exclude from the vote.", _, true, 0.0); - g_Cvar_ExcludeMapsTime = CreateConVar("mce_exclude_time", "5", "Specifies how long in minutes an old map is excluded from the vote.", _, true, 0.0); + g_Cvar_ExcludeMapsTime = CreateConVar("mce_exclude_time", "5h", "Specifies how long in minutes an old map is excluded from the vote."); g_Cvar_IncludeMaps = CreateConVar("mce_include", "5", "Specifies how many maps to include in the vote.", _, true, 2.0, true, 7.0); g_Cvar_IncludeMapsReserved = CreateConVar("mce_include_reserved", "2", "Specifies how many private/random maps to include in the vote.", _, true, 0.0, true, 5.0); g_Cvar_NoVoteMode = CreateConVar("mce_novote", "1", "Specifies whether or not MapChooser should pick a map if no votes are received.", _, true, 0.0, true, 1.0); @@ -541,7 +541,7 @@ public void OnMapEnd() Cooldown = InternalGetMapCooldown(map); g_OldMapList.SetValue(map, Cooldown, true); - Cooldown = InternalGetMapCooldownTime(map); + Cooldown = GetTime() + InternalGetMapCooldownTime(map); g_TimeMapList.SetValue(map, Cooldown, true); } @@ -1573,7 +1573,7 @@ void CreateNextVote() GetCurrentMap(map, PLATFORM_MAX_PATH); RemoveStringFromArray(tempMaps, map); - if(GetConVarInt(g_Cvar_ExcludeMaps) && GetArraySize(tempMaps) > GetConVarInt(g_Cvar_ExcludeMaps) && InternalAreRestrictionsActive()) + if(GetArraySize(tempMaps) > GetConVarInt(g_Cvar_ExcludeMaps) && InternalAreRestrictionsActive()) { StringMapSnapshot OldMapListSnapshot = g_OldMapList.Snapshot(); for(int i = 0; i < OldMapListSnapshot.Length; i++) @@ -1584,7 +1584,7 @@ void CreateNextVote() delete OldMapListSnapshot; } - if(GetConVarInt(g_Cvar_ExcludeMapsTime) && InternalAreRestrictionsActive()) + if(InternalAreRestrictionsActive()) { StringMapSnapshot TimeMapListSnapshot = g_TimeMapList.Snapshot(); for(int i = 0; i < TimeMapListSnapshot.Length; i++) @@ -2090,14 +2090,14 @@ public int Native_ExcludeMapTime(Handle plugin, int numParams) } else if(Mode == 1) { - Cooldown = GetNativeCell(2) * 60; + Cooldown = GetNativeCell(2); } else if(Mode == 2) { g_TimeMapList.GetValue(map, Cooldown); - int NewCooldown = GetTime() + GetNativeCell(2) * 60; + int NewCooldown = GetTime() + GetNativeCell(2); if(NewCooldown > Cooldown) - Cooldown = GetNativeCell(2) * 60; + Cooldown = GetNativeCell(2); } Cooldown += GetTime(); @@ -2405,11 +2405,15 @@ stock int InternalGetMapCooldown(const char[] map) stock int InternalGetMapCooldownTime(const char[] map) { - int Cooldown = g_Cvar_ExcludeMapsTime.IntValue; + char time[16]; + g_Cvar_ExcludeMapsTime.GetString(time, sizeof(time)); + int Cooldown = TimeStrToSeconds(time); if(g_Config && g_Config.JumpToKey(map)) { - Cooldown = g_Config.GetNum("CooldownTime", Cooldown); + g_Config.GetString("CooldownTime", time, sizeof(time), ""); + Cooldown = TimeStrToSeconds(time); + g_Config.Rewind(); } @@ -2790,4 +2794,22 @@ stock void InternalStoreMapCooldowns() } delete Cooldowns; -} \ No newline at end of file +} + +stock int TimeStrToSeconds(const char[] str) +{ + int seconds = 0; + int maxlen = strlen(str); + for(int i = 0; i < maxlen; i++) + { + int val = 0; + i += StringToIntEx(str[i], val); + if(str[i] == 'h') + { + val *= 60; + i++; + } + seconds += val * 60; + } + return seconds; +} diff --git a/mapchooser_extended/scripting/nominations_extended.sp b/mapchooser_extended/scripting/nominations_extended.sp index 2f8c5df7..d0f398ca 100644 --- a/mapchooser_extended/scripting/nominations_extended.sp +++ b/mapchooser_extended/scripting/nominations_extended.sp @@ -41,7 +41,7 @@ #include #include -#define MCE_VERSION "1.13.0" +#define MCE_VERSION "1.3.0" public Plugin myinfo = { @@ -112,7 +112,8 @@ public void OnPluginStart() RegAdminCmd("sm_nominate_addmap", Command_Addmap, ADMFLAG_CHANGEMAP, "sm_nominate_addmap - Forces a map to be on the next mapvote."); RegAdminCmd("sm_nominate_removemap", Command_Removemap, ADMFLAG_CHANGEMAP, "sm_nominate_removemap - Removes a map from Nominations."); - RegAdminCmd("sm_nominate_exclude", Command_AddExclude, ADMFLAG_CHANGEMAP, "sm_nominate_exclude [cooldown] - Forces a map to be inserted into the recently played maps. Effectively blocking the map from being nominated."); + RegAdminCmd("sm_nominate_exclude", Command_AddExclude, ADMFLAG_CHANGEMAP, "sm_nominate_exclude [cooldown] [mode]- Forces a map to be inserted into the recently played maps. Effectively blocking the map from being nominated."); + RegAdminCmd("sm_nominate_exclude_time", Command_AddExcludeTime, ADMFLAG_CHANGEMAP, "sm_nominate_exclude_time [cooldown] [mode] - Forces a map to be inserted into the recently played maps. Effectively blocking the map from being nominated."); // Nominations Extended cvars CreateConVar("ne_version", MCE_VERSION, "Nominations Extended Version", FCVAR_SPONLY|FCVAR_NOTIFY|FCVAR_DONTRECORD); @@ -303,10 +304,19 @@ public Action Command_Addmap(int client, int args) } } + int Cooldown = GetMapCooldownTime(mapname); + if(RestrictionsActive && Cooldown > GetTime()) + { + int Seconds = Cooldown - GetTime(); + CPrintToChat(client, "[NE] %t", "Map Cooldown Time Error", Seconds / 3600, (Seconds % 3600) / 60); + + return Plugin_Handled; + } + int TimeRestriction = GetMapTimeRestriction(mapname); if(RestrictionsActive && TimeRestriction) { - CPrintToChat(client, "[NE] %t", "Map Nominate Time Error", RoundToFloor(float(TimeRestriction / 60)), TimeRestriction % 60); + CPrintToChat(client, "[NE] %t", "Map Nominate Time Error", TimeRestriction / 60, TimeRestriction % 60); return Plugin_Handled; } @@ -387,7 +397,7 @@ public Action Command_AddExclude(int client, int args) { if(args < 1) { - CReplyToCommand(client, "[NE] Usage: sm_nominate_exclude "); + CReplyToCommand(client, "[NE] Usage: sm_nominate_exclude [cooldown] [mode]"); return Plugin_Handled; } @@ -427,6 +437,49 @@ public Action Command_AddExclude(int client, int args) return Plugin_Handled; } +public Action Command_AddExcludeTime(int client, int args) +{ + if(args < 1) + { + CReplyToCommand(client, "[NE] Usage: sm_nominate_exclude_time [cooldown] [mode]"); + return Plugin_Handled; + } + + static char mapname[PLATFORM_MAX_PATH]; + GetCmdArg(1, mapname, sizeof(mapname)); + + int cooldown = 0; + int mode = 0; + if(args >= 2) + { + static char buffer[16]; + GetCmdArg(2, buffer, sizeof(buffer)); + cooldown = TimeStrToSeconds(buffer); + PrintToChatAll("%s -> %d", buffer, cooldown); + } + if(args >= 3) + { + static char buffer[8]; + GetCmdArg(3, buffer, sizeof(buffer)); + mode = StringToInt(buffer); + } + + int status; + if(!GetTrieValue(g_mapTrie, mapname, status)) + { + ReplyToCommand(client, "[NE] %t", "Map was not found", mapname); + return Plugin_Handled; + } + + ShowActivity(client, "ExcludedTime map \"%s\" from nomination", mapname); + LogAction(client, -1, "\"%L\" excludedTime map \"%s\" from nomination", client, mapname); + + // native call to mapchooser_extended + ExcludeMapTime(mapname, cooldown, mode); + + return Plugin_Handled; +} + public Action Command_Say(int client, int args) { if(!client) @@ -515,6 +568,15 @@ public Action Command_Nominate(int client, int args) return Plugin_Handled; } + int Cooldown = GetMapCooldownTime(mapname); + if(RestrictionsActive && Cooldown > GetTime()) + { + int Seconds = Cooldown - GetTime(); + CPrintToChat(client, "[NE] %t", "Map Cooldown Time Error", Seconds / 3600, (Seconds % 3600) / 60); + + return Plugin_Handled; + } + bool VIPRestriction = GetMapVIPRestriction(mapname, client); if(RestrictionsActive && VIPRestriction) { @@ -526,7 +588,7 @@ public Action Command_Nominate(int client, int args) int TimeRestriction = GetMapTimeRestriction(mapname); if(RestrictionsActive && TimeRestriction) { - CPrintToChat(client, "[NE] %t", "Map Nominate Time Error", RoundToFloor(float(TimeRestriction / 60)), TimeRestriction % 60); + CPrintToChat(client, "[NE] %t", "Map Nominate Time Error", TimeRestriction / 60, TimeRestriction % 60); return Plugin_Handled; } @@ -904,10 +966,20 @@ public int Handler_MapSelectMenu(Menu menu, MenuAction action, int param1, int p } } + int Cooldown = GetMapCooldownTime(map); + if(RestrictionsActive && Cooldown > GetTime()) + { + int Seconds = Cooldown - GetTime(); + char time[16]; + CustomFormatTime(Seconds, time, sizeof(time)); + Format(display, sizeof(display), "%s (%T %s)", buffer, "Recently Played", param1, time); + return RedrawMenuItem(display); + } + int TimeRestriction = GetMapTimeRestriction(map); if(RestrictionsActive && TimeRestriction) { - Format(display, sizeof(display), "%s (%T)", buffer, "Map Time Restriction", param1, "+", RoundToFloor(float(TimeRestriction / 60)), TimeRestriction % 60); + Format(display, sizeof(display), "%s (%T)", buffer, "Map Time Restriction", param1, "+", TimeRestriction / 60, TimeRestriction % 60); return RedrawMenuItem(display); } @@ -957,7 +1029,7 @@ stock bool IsNominateAllowed(int client) int VIPTimeRestriction = GetVIPTimeRestriction(); 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); + 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.", VIPTimeRestriction / 60, VIPTimeRestriction % 60); return false; } } @@ -1083,10 +1155,20 @@ public int Handler_AdminMapSelectMenu(Menu menu, MenuAction action, int param1, } } + int Cooldown = GetMapCooldownTime(map); + if(RestrictionsActive && Cooldown > GetTime()) + { + int Seconds = Cooldown - GetTime(); + char time[16]; + CustomFormatTime(Seconds, time, sizeof(time)); + Format(display, sizeof(display), "%s (%T %s)", buffer, "Recently Played", param1, time); + return RedrawMenuItem(display); + } + int TimeRestriction = GetMapTimeRestriction(map); if(RestrictionsActive && TimeRestriction) { - Format(display, sizeof(display), "%s (%T)", buffer, "Map Time Restriction", param1, "+", RoundToFloor(float(TimeRestriction / 60)), TimeRestriction % 60); + Format(display, sizeof(display), "%s (%T)", buffer, "Map Time Restriction", param1, "+", TimeRestriction / 60, TimeRestriction % 60); return RedrawMenuItem(display); } @@ -1226,9 +1308,9 @@ stock int GetVIPTimeRestriction() 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); + CurTime = ((CurTime / 100) * 60) + (CurTime % 100); + MinTime = ((MinTime / 100) * 60) + (MinTime % 100); + MaxTime = ((MaxTime / 100) * 60) + (MaxTime % 100); return MaxTime - CurTime; } @@ -1241,9 +1323,27 @@ stock void CustomFormatTime(int seconds, char[] buffer, int maxlen) if(seconds <= 60) Format(buffer, maxlen, "%ds", seconds); else if(seconds <= 3600) - Format(buffer, maxlen, "%dm", RoundToNearest(seconds / 60)); - else if(seconds <= 10*3600) - Format(buffer, maxlen, "%dh%dm", RoundToFloor(seconds / 3600), RoundToNearest((seconds % 3600) / 60)); + Format(buffer, maxlen, "%dm", seconds / 60); + else if(seconds < 10*3600) + Format(buffer, maxlen, "%dh%dm", seconds / 3600, (seconds % 3600) / 60); else - Format(buffer, maxlen, "%dh", RoundToNearest(seconds / 3600)); + Format(buffer, maxlen, "%dh", seconds / 3600); +} + +stock int TimeStrToSeconds(const char[] str) +{ + int seconds = 0; + int maxlen = strlen(str); + for(int i = 0; i < maxlen; i++) + { + int val = 0; + i += StringToIntEx(str[i], val); + if(str[i] == 'h') + { + val *= 60; + i++; + } + seconds += val * 60; + } + return seconds; } diff --git a/mapchooser_extended/scripting/rockthevote_extended.sp b/mapchooser_extended/scripting/rockthevote_extended.sp index a9a7d42c..bc580021 100644 --- a/mapchooser_extended/scripting/rockthevote_extended.sp +++ b/mapchooser_extended/scripting/rockthevote_extended.sp @@ -40,7 +40,7 @@ #include #include -#define MCE_VERSION "1.13.0" +#define MCE_VERSION "1.3.0" public Plugin myinfo = { diff --git a/mapchooser_extended/translations/mapchooser_extended.phrases.txt b/mapchooser_extended/translations/mapchooser_extended.phrases.txt index ad1ca47a..7941f6ca 100644 --- a/mapchooser_extended/translations/mapchooser_extended.phrases.txt +++ b/mapchooser_extended/translations/mapchooser_extended.phrases.txt @@ -106,6 +106,12 @@ "en" "*{1}" } + "Map Cooldown Time Error" + { + "#format" "{1:d},{2:d}" + "en" "This map is on cooldown for the next {1} hours and {2} minutes." + } + "VIP Nomination" { "en" "VIP" From 4f43ff3bf305d2640c2b72a5424f48eeab342fe2 Mon Sep 17 00:00:00 2001 From: BotoX Date: Wed, 18 Sep 2019 17:11:29 +0200 Subject: [PATCH 4/4] fix issues --- mapchooser_extended/scripting/mapchooser_extended.sp | 2 +- mapchooser_extended/scripting/nominations_extended.sp | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/mapchooser_extended/scripting/mapchooser_extended.sp b/mapchooser_extended/scripting/mapchooser_extended.sp index 0f12983c..9f5cd109 100644 --- a/mapchooser_extended/scripting/mapchooser_extended.sp +++ b/mapchooser_extended/scripting/mapchooser_extended.sp @@ -2800,7 +2800,7 @@ stock int TimeStrToSeconds(const char[] str) { int seconds = 0; int maxlen = strlen(str); - for(int i = 0; i < maxlen; i++) + for(int i = 0; i < maxlen;) { int val = 0; i += StringToIntEx(str[i], val); diff --git a/mapchooser_extended/scripting/nominations_extended.sp b/mapchooser_extended/scripting/nominations_extended.sp index d0f398ca..15e24178 100644 --- a/mapchooser_extended/scripting/nominations_extended.sp +++ b/mapchooser_extended/scripting/nominations_extended.sp @@ -455,7 +455,6 @@ public Action Command_AddExcludeTime(int client, int args) static char buffer[16]; GetCmdArg(2, buffer, sizeof(buffer)); cooldown = TimeStrToSeconds(buffer); - PrintToChatAll("%s -> %d", buffer, cooldown); } if(args >= 3) { @@ -1334,7 +1333,7 @@ stock int TimeStrToSeconds(const char[] str) { int seconds = 0; int maxlen = strlen(str); - for(int i = 0; i < maxlen; i++) + for(int i = 0; i < maxlen;) { int val = 0; i += StringToIntEx(str[i], val);