From 9532c0893fc21e3cd6ed3b0839babc96e1786a15 Mon Sep 17 00:00:00 2001 From: zaCade Date: Thu, 12 Oct 2017 21:52:19 +0200 Subject: [PATCH] Allow mapchooser to exclude maps based on Daytime. --- .../scripting/include/mapchooser_extended.inc | 3 + .../scripting/mapchooser_extended.sp | 138 ++++++++++++++++-- .../scripting/nominations_extended.sp | 48 +++++- .../mapchooser_extended.phrases.txt | 30 ++++ 4 files changed, 206 insertions(+), 13 deletions(-) diff --git a/mapchooser_extended/scripting/include/mapchooser_extended.inc b/mapchooser_extended/scripting/include/mapchooser_extended.inc index b5bbc414..99b002c1 100644 --- a/mapchooser_extended/scripting/include/mapchooser_extended.inc +++ b/mapchooser_extended/scripting/include/mapchooser_extended.inc @@ -108,8 +108,11 @@ native CanNominateResult CanNominate(); native bool ExcludeMap(const char[] map, int cooldown = 0, int mode = 0); native int GetMapCooldown(const char[] map); +native int GetMapMinTime(const char[] map); +native int GetMapMaxTime(const char[] map); native int GetMapMinPlayers(const char[] map); native int GetMapMaxPlayers(const char[] map); +native int GetMapTimeRestriction(const char[] map); native int GetMapPlayerRestriction(const char[] map); public SharedPlugin __pl_mapchooser_extended = diff --git a/mapchooser_extended/scripting/mapchooser_extended.sp b/mapchooser_extended/scripting/mapchooser_extended.sp index e0ef15a8..9a31f1b9 100644 --- a/mapchooser_extended/scripting/mapchooser_extended.sp +++ b/mapchooser_extended/scripting/mapchooser_extended.sp @@ -399,8 +399,11 @@ public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max CreateNative("CanNominate", Native_CanNominate); CreateNative("ExcludeMap", Native_ExcludeMap); CreateNative("GetMapCooldown", Native_GetMapCooldown); + CreateNative("GetMapMinTime", Native_GetMapMinTime); + CreateNative("GetMapMaxTime", Native_GetMapMaxTime); CreateNative("GetMapMinPlayers", Native_GetMapMinPlayers); CreateNative("GetMapMaxPlayers", Native_GetMapMaxPlayers); + CreateNative("GetMapTimeRestriction", Native_GetMapTimeRestriction); CreateNative("GetMapPlayerRestriction", Native_GetMapPlayerRestriction); return APLRes_Success; @@ -544,12 +547,12 @@ public void OnMapEnd() public void OnClientPutInServer(int client) { - CheckMapPlayerRestriction(); + CheckMapRestrictions(false, true); } public void OnClientDisconnect_Post(int client) { - CheckMapPlayerRestriction(); + CheckMapRestrictions(false, true); } public void OnClientDisconnect(int client) @@ -990,7 +993,7 @@ void InitiateVote(MapChange when, Handle inputlist=INVALID_HANDLE) if(g_MapVoteCompleted && g_ChangeMapInProgress) return; - CheckMapPlayerRestriction(); + CheckMapRestrictions(true, true); CreateNextVote(); g_ChangeTime = when; @@ -2060,6 +2063,34 @@ public int Native_GetMapCooldown(Handle plugin, int numParams) return Cooldown; } +public int Native_GetMapMinTime(Handle plugin, int numParams) +{ + int len; + GetNativeStringLength(1, len); + + if(len <= 0) + return false; + + char[] map = new char[len+1]; + GetNativeString(1, map, len+1); + + return InternalGetMapMinTime(map); +} + +public int Native_GetMapMaxTime(Handle plugin, int numParams) +{ + int len; + GetNativeStringLength(1, len); + + if(len <= 0) + return false; + + char[] map = new char[len+1]; + GetNativeString(1, map, len+1); + + return InternalGetMapMaxTime(map); +} + public int Native_GetMapMinPlayers(Handle plugin, int numParams) { int len; @@ -2088,6 +2119,20 @@ public int Native_GetMapMaxPlayers(Handle plugin, int numParams) return InternalGetMapMaxPlayers(map); } +public int Native_GetMapTimeRestriction(Handle plugin, int numParams) +{ + int len; + GetNativeStringLength(1, len); + + if(len <= 0) + return false; + + char[] map = new char[len+1]; + GetNativeString(1, map, len+1); + + return InternalGetMapTimeRestriction(map); +} + public int Native_GetMapPlayerRestriction(Handle plugin, int numParams) { int len; @@ -2169,7 +2214,7 @@ stock int InternalGetMapCooldown(const char[] map) return Cooldown; } -void CheckMapPlayerRestriction() +void CheckMapRestrictions(bool time = false, bool players = false) { static char map[PLATFORM_MAX_PATH]; for(int i = 0; i < GetArraySize(g_NominateList); i++) @@ -2178,9 +2223,38 @@ void CheckMapPlayerRestriction() if(CheckCommandAccess(client, "sm_nominate_ignore", ADMFLAG_CHEATS, true)) continue; + bool remove; GetArrayString(g_NominateList, i, map, PLATFORM_MAX_PATH); - int Restriction = InternalGetMapPlayerRestriction(map); - if(Restriction) + + if (time) + { + int TimeRestriction = InternalGetMapTimeRestriction(map); + if(TimeRestriction) + { + remove = true; + + if(TimeRestriction < 0) + CPrintToChat(client, "[MCE] %t", "Nomination Removed MinTime Error", map); + else + CPrintToChat(client, "[MCE] %t", "Nomination Removed MaxTime Error", map); + } + } + + if (players) + { + int PlayerRestriction = InternalGetMapPlayerRestriction(map); + if(PlayerRestriction) + { + remove = true; + + if(PlayerRestriction < 0) + CPrintToChat(client, "[MCE] %t", "Nomination Removed MinPlayers Error", map); + else + CPrintToChat(client, "[MCE] %t", "Nomination Removed MaxPlayers Error", map); + } + } + + if (remove) { Call_StartForward(g_NominationsResetForward); Call_PushString(map); @@ -2190,15 +2264,36 @@ void CheckMapPlayerRestriction() RemoveFromArray(g_NominateList, i); RemoveFromArray(g_NominateOwners, i); g_NominateCount--; - - if(Restriction < 0) - CPrintToChat(client, "[MCE] %t", "Nomination Removed MinPlayers Error", map); - else if(Restriction > 0) - CPrintToChat(client, "[MCE] %t", "Nomination Removed MaxPlayers Error", map); } } } +stock int InternalGetMapMinTime(const char[] map) +{ + int MinTime = 0; + + if(g_Config && g_Config.JumpToKey(map)) + { + MinTime = g_Config.GetNum("MinTime", MinTime); + g_Config.Rewind(); + } + + return MinTime; +} + +stock int InternalGetMapMaxTime(const char[] map) +{ + int MaxTime = 0; + + if(g_Config && g_Config.JumpToKey(map)) + { + MaxTime = g_Config.GetNum("MaxTime", MaxTime); + g_Config.Rewind(); + } + + return MaxTime; +} + stock int InternalGetMapMinPlayers(const char[] map) { int MinPlayers = 0; @@ -2225,6 +2320,27 @@ stock int InternalGetMapMaxPlayers(const char[] map) return MaxPlayers; } +// <0 = Less than MinTime +// 0 = Okay +// >0 = More than MaxTime +stock int InternalGetMapTimeRestriction(const char[] map) +{ + char sHour[8]; + FormatTime(sHour, sizeof(sHour), "%H"); + + int CurTime = StringToInt(sHour); + int MinTime = InternalGetMapMinTime(map); + int MaxTime = InternalGetMapMaxTime(map); + + if(MinTime && CurTime < MinTime) + return CurTime - MinTime; + + if(MaxTime && CurTime > MaxTime) + return CurTime - MinTime; + + return 0; +} + // <0 = Less than MinPlayers // 0 = Okay // >0 = More than MaxPlayers diff --git a/mapchooser_extended/scripting/nominations_extended.sp b/mapchooser_extended/scripting/nominations_extended.sp index 29f1a247..9cfd51ae 100644 --- a/mapchooser_extended/scripting/nominations_extended.sp +++ b/mapchooser_extended/scripting/nominations_extended.sp @@ -268,6 +268,17 @@ public Action Command_Addmap(int client, int args) } } + int TimeRestriction = GetMapTimeRestriction(mapname); + if(TimeRestriction) + { + if(TimeRestriction < 0) + CPrintToChat(client, "[NE] %t", "Map Nominate MinTime Error", TimeRestriction * -1); + else + CPrintToChat(client, "[NE] %t", "Map Nominate MaxTime Error", TimeRestriction); + + return Plugin_Handled; + } + int PlayerRestriction = GetMapPlayerRestriction(mapname); if(PlayerRestriction) { @@ -462,6 +473,17 @@ public Action Command_Nominate(int client, int args) return Plugin_Handled; } + int TimeRestriction = GetMapTimeRestriction(mapname); + if(TimeRestriction) + { + if(TimeRestriction < 0) + CPrintToChat(client, "[NE] %t", "Map Nominate MinTime Error", TimeRestriction * -1); + else + CPrintToChat(client, "[NE] %t", "Map Nominate MaxTime Error", TimeRestriction); + + return Plugin_Handled; + } + int PlayerRestriction = GetMapPlayerRestriction(mapname); if(PlayerRestriction) { @@ -685,7 +707,7 @@ public int Handler_MapSelectMenu(Menu menu, MenuAction action, int param1, int p if((status & MAPSTATUS_DISABLED) == MAPSTATUS_DISABLED) return ITEMDRAW_DISABLED; - if(GetMapPlayerRestriction(map)) + if(GetMapTimeRestriction(map) || GetMapPlayerRestriction(map)) return ITEMDRAW_DISABLED; return ITEMDRAW_DEFAULT; @@ -753,6 +775,17 @@ public int Handler_MapSelectMenu(Menu menu, MenuAction action, int param1, int p } } + int TimeRestriction = GetMapTimeRestriction(map); + if(TimeRestriction) + { + if(TimeRestriction < 0) + Format(display, sizeof(display), "%s (%T)", buffer, "Map Time Restriction", param1, "+", TimeRestriction * -1); + else + Format(display, sizeof(display), "%s (%T)", buffer, "Map Time Restriction", param1, "-", TimeRestriction); + + return RedrawMenuItem(display); + } + int PlayerRestriction = GetMapPlayerRestriction(map); if(PlayerRestriction) { @@ -850,7 +883,7 @@ public int Handler_AdminMapSelectMenu(Menu menu, MenuAction action, int param1, return ITEMDRAW_DISABLED; } - if(GetMapPlayerRestriction(map)) + if(GetMapTimeRestriction(map) || GetMapPlayerRestriction(map)) return ITEMDRAW_DISABLED; } @@ -894,6 +927,17 @@ public int Handler_AdminMapSelectMenu(Menu menu, MenuAction action, int param1, } } + int TimeRestriction = GetMapTimeRestriction(map); + if(TimeRestriction) + { + if(TimeRestriction < 0) + Format(display, sizeof(display), "%s (%T)", buffer, "Map Time Restriction", param1, "+", TimeRestriction * -1); + else + Format(display, sizeof(display), "%s (%T)", buffer, "Map Time Restriction", param1, "-", TimeRestriction); + + return RedrawMenuItem(display); + } + int PlayerRestriction = GetMapPlayerRestriction(map); if(PlayerRestriction) { diff --git a/mapchooser_extended/translations/mapchooser_extended.phrases.txt b/mapchooser_extended/translations/mapchooser_extended.phrases.txt index d9156dc0..2811da60 100644 --- a/mapchooser_extended/translations/mapchooser_extended.phrases.txt +++ b/mapchooser_extended/translations/mapchooser_extended.phrases.txt @@ -106,6 +106,18 @@ "en" "*{1}" } + "Map Nominate MinTime Error" + { + "#format" "{1:d}" + "en" "It's to early to nominate {1}." + } + + "Map Nominate MaxTime Error" + { + "#format" "{1:d}" + "en" "It's to late to nominate {1}." + } + "Map Nominate MinPlayers Error" { "#format" "{1:d}" @@ -118,12 +130,30 @@ "en" "Map requires {1} less players." } + "Map Time Restriction" + { + "#format" "{1:s},{2:d}" + "en" "Hours{1}{2}" + } + "Map Player Restriction" { "#format" "{1:s},{2:d}" "en" "Players{1}{2}" } + "Nomination Removed MinTime Error" + { + "#format" "{1:s}" + "en" "Your nomination {1} has been removed because it doesn't meet the minumum time requirements." + } + + "Nomination Removed MaxTime Error" + { + "#format" "{1:s}" + "en" "Your nomination {1} has been removed because it exceeds the maximum time restriction." + } + "Nomination Removed MinPlayers Error" { "#format" "{1:s}"