diff --git a/mapchooser_extended/configs/mapchooser_extended.cfg b/mapchooser_extended/configs/mapchooser_extended.cfg index 895840fc..f783cfaf 100644 --- a/mapchooser_extended/configs/mapchooser_extended.cfg +++ b/mapchooser_extended/configs/mapchooser_extended.cfg @@ -9,4 +9,14 @@ "MaxPlayers" "50" "Cooldown" "20" } + + "_groups" + { + "example_group" + { + "_max" "1" + "example_map1" {} + "example_map2" {} + } + } } \ 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 99b002c1..551d3e57 100644 --- a/mapchooser_extended/scripting/include/mapchooser_extended.inc +++ b/mapchooser_extended/scripting/include/mapchooser_extended.inc @@ -112,9 +112,24 @@ native int GetMapMinTime(const char[] map); native int GetMapMaxTime(const char[] map); native int GetMapMinPlayers(const char[] map); native int GetMapMaxPlayers(const char[] map); + +// 0 = Okay +// >0 = Minutes till Okay native int GetMapTimeRestriction(const char[] map); + +// <0 = Less than MinPlayers +// 0 = Okay +// >0 = More than MaxPlayers native int GetMapPlayerRestriction(const char[] map); +// <0 = No group +// >=0 = Group _max +native int GetMapGroup(const char[] map, char[] group, int size); + +// <0 = No restriction +// >=0 = Group _max -> Group full +native int GetMapGroupRestriction(const char[] map, int client = 0); + public SharedPlugin __pl_mapchooser_extended = { name = "mapchooser", diff --git a/mapchooser_extended/scripting/mapchooser_extended.sp b/mapchooser_extended/scripting/mapchooser_extended.sp index a9e27a45..0232f79f 100644 --- a/mapchooser_extended/scripting/mapchooser_extended.sp +++ b/mapchooser_extended/scripting/mapchooser_extended.sp @@ -405,6 +405,8 @@ public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max CreateNative("GetMapMaxPlayers", Native_GetMapMaxPlayers); CreateNative("GetMapTimeRestriction", Native_GetMapTimeRestriction); CreateNative("GetMapPlayerRestriction", Native_GetMapPlayerRestriction); + CreateNative("GetMapGroup", Native_GetMapGroup); + CreateNative("GetMapGroupRestriction", Native_GetMapGroupRestriction); return APLRes_Success; } @@ -1144,17 +1146,14 @@ void InitiateVote(MapChange when, Handle inputlist=INVALID_HANDLE) GetArrayString(g_NextMapList, count, map, PLATFORM_MAX_PATH); count++; - if(InternalGetMapPlayerRestriction(map) == 0) + if(randomizeList == INVALID_HANDLE) { - if(randomizeList == INVALID_HANDLE) - { - /* Insert the map and increment our count */ - AddMapItem(map); - } - else - PushArrayString(randomizeList, map); - i++; + /* Insert the map and increment our count */ + AddMapItem(map); } + else + PushArrayString(randomizeList, map); + i++; //Run out of maps, this will have to do. if(count >= availableMaps) @@ -1655,6 +1654,9 @@ void CreateNextVote() int voteSize = GetVoteSize(); int limit = (voteSize < GetArraySize(tempMaps) ? voteSize : GetArraySize(tempMaps)); + StringMap groups = new StringMap(); + char group[255]; + for(int i = 0; i < limit; i++) { int b; @@ -1662,13 +1664,27 @@ void CreateNextVote() { b = GetRandomInt(0, GetArraySize(tempMaps) - 1); GetArrayString(tempMaps, b, map, PLATFORM_MAX_PATH); + if(InternalGetMapPlayerRestriction(map) == 0) break; + + int groupmax = InternalGetMapGroup(map, group, sizeof(group)); + if(groupmax >= 0) + { + int groupcur = 0; + groups.GetValue(group, groupcur); + + if(groupcur >= groupmax) + break; + groupcur++; + groups.SetValue(group, groupcur, true); + } } PushArrayString(g_NextMapList, map); RemoveFromArray(tempMaps, b); } + delete groups; CloseHandle(tempMaps); } @@ -2149,6 +2165,79 @@ public int Native_GetMapPlayerRestriction(Handle plugin, int numParams) return InternalGetMapPlayerRestriction(map); } +public int Native_GetMapGroup(Handle plugin, int numParams) +{ + int len; + GetNativeStringLength(1, len); + int size = GetNativeCell(3); + + if(len <= 0) + return -999; + + char[] map = new char[len+1]; + GetNativeString(1, map, len+1); + + char[] group = new char[size]; + int groupmax = InternalGetMapGroup(map, group, size); + if(groupmax >= 0) + SetNativeString(2, group, size); + return groupmax; +} + +public int Native_GetMapGroupRestriction(Handle plugin, int numParams) +{ + int client = GetNativeCell(2); + int len; + GetNativeStringLength(1, len); + + if(len <= 0) + return -999; + + char[] map = new char[len+1]; + GetNativeString(1, map, len+1); + + static char group[255]; + int groupmax = InternalGetMapGroup(map, group, sizeof(group)); + int groupcur = 0; + if(groupmax >= 0) + { + static char map_[PLATFORM_MAX_PATH]; + static char group_[255]; + for(int i = 0; i < GetArraySize(g_NominateList); i++) + { + GetArrayString(g_NominateList, i, map_, PLATFORM_MAX_PATH); + int tmp = InternalGetMapGroup(map_, group_, sizeof(group_)); + if(tmp == groupmax && StrEqual(group, group_)) + groupcur++; + } + + if(groupcur >= groupmax) + { + // Check if client has nominated a map in the same group and can change their nomination + if(client > 0 && client < MaxClients) + { + int index = FindValueInArray(g_NominateOwners, client); + if(index != -1) + { + static char oldmap[PLATFORM_MAX_PATH]; + GetArrayString(g_NominateList, index, oldmap, PLATFORM_MAX_PATH); + char oldgroup[255]; + int tmp = InternalGetMapGroup(oldmap, oldgroup, sizeof(oldgroup)); + if(tmp == groupmax && StrEqual(group, group_)) + return -321; + } + } + + return groupmax; + } + + return -123; + } + + return groupmax; +} + + stock void AddMapItem(const char[] map) { if(g_NativeVotes) @@ -2319,6 +2408,33 @@ stock int InternalGetMapMaxPlayers(const char[] map) return MaxPlayers; } +stock int InternalGetMapGroup(const char[] map, char[] group, int size) +{ + if(g_Config && g_Config.JumpToKey("_groups")) + { + if(!g_Config.GotoFirstSubKey(false)) + { + g_Config.Rewind(); + return -999; + } + + do + { + int ret = g_Config.GetNum("_max", 1); + g_Config.GetSectionName(group, size); + if(g_Config.JumpToKey(map, false)) + { + g_Config.Rewind(); + return ret; + } + } while(g_Config.GotoNextKey()); + + g_Config.Rewind(); + } + + return -999; +} + // 0 = Okay // >0 = Minutes till Okay stock int InternalGetMapTimeRestriction(const char[] map) diff --git a/mapchooser_extended/scripting/nominations_extended.sp b/mapchooser_extended/scripting/nominations_extended.sp index 17a63a85..6a9fa348 100644 --- a/mapchooser_extended/scripting/nominations_extended.sp +++ b/mapchooser_extended/scripting/nominations_extended.sp @@ -309,6 +309,13 @@ public Action Command_Addmap(int client, int args) return Plugin_Handled; } + + int GroupRestriction = GetMapGroupRestriction(mapname); + if(GroupRestriction >= 0) + { + CPrintToChat(client, "[NE] %t", "Map Nominate Group Error", GroupRestriction); + return Plugin_Handled; + } } NominateResult result = NominateMap(mapname, true, 0); @@ -512,6 +519,13 @@ public Action Command_Nominate(int client, int args) return Plugin_Handled; } + int GroupRestriction = GetMapGroupRestriction(mapname, client); + if(GroupRestriction >= 0) + { + CPrintToChat(client, "[NE] %t", "Map Nominate Group Error", GroupRestriction); + return Plugin_Handled; + } + NominateResult result = NominateMap(mapname, false, client); if(result > Nominate_Replaced) @@ -726,7 +740,7 @@ public int Handler_MapSelectMenu(Menu menu, MenuAction action, int param1, int p if((status & MAPSTATUS_DISABLED) == MAPSTATUS_DISABLED) return ITEMDRAW_DISABLED; - if(GetMapTimeRestriction(map) || GetMapPlayerRestriction(map)) + if(GetMapTimeRestriction(map) || GetMapPlayerRestriction(map) || GetMapGroupRestriction(map, param1) >= 0) return ITEMDRAW_DISABLED; return ITEMDRAW_DEFAULT; @@ -813,6 +827,13 @@ public int Handler_MapSelectMenu(Menu menu, MenuAction action, int param1, int p return RedrawMenuItem(display); } + int GroupRestriction = GetMapGroupRestriction(map, param1); + if(GroupRestriction >= 0) + { + Format(display, sizeof(display), "%s (%T)", buffer, "Map Group Restriction", param1, GroupRestriction); + return RedrawMenuItem(display); + } + if(mark && !official) return RedrawMenuItem(buffer); @@ -899,7 +920,7 @@ public int Handler_AdminMapSelectMenu(Menu menu, MenuAction action, int param1, return ITEMDRAW_DISABLED; } - if(GetMapTimeRestriction(map) || GetMapPlayerRestriction(map)) + if(GetMapTimeRestriction(map) || GetMapPlayerRestriction(map) || GetMapGroupRestriction(map) >= 0) return ITEMDRAW_DISABLED; } @@ -962,6 +983,13 @@ public int Handler_AdminMapSelectMenu(Menu menu, MenuAction action, int param1, return RedrawMenuItem(display); } + + int GroupRestriction = GetMapGroupRestriction(map); + if(GroupRestriction >= 0) + { + Format(display, sizeof(display), "%s (%T)", buffer, "Map Group Restriction", param1, GroupRestriction); + return RedrawMenuItem(display); + } } return 0; diff --git a/mapchooser_extended/translations/mapchooser_extended.phrases.txt b/mapchooser_extended/translations/mapchooser_extended.phrases.txt index b6b4d72d..9d236787 100644 --- a/mapchooser_extended/translations/mapchooser_extended.phrases.txt +++ b/mapchooser_extended/translations/mapchooser_extended.phrases.txt @@ -124,6 +124,12 @@ "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." + } + "Map Time Restriction" { "#format" "{1:s},{2:d},{3:d}" @@ -136,6 +142,12 @@ "en" "Players{1}{2}" } + "Map Group Restriction" + { + "#format" "{1:d}" + "en" "Group max: {1}" + } + "Nomination Removed Time Error" { "#format" "{1:s}"