diff --git a/mapchooser_extended/scripting/mapchooser_extended_avg.sp b/mapchooser_extended/scripting/mapchooser_extended_avg.sp index 7feb5819..3acfafe9 100755 --- a/mapchooser_extended/scripting/mapchooser_extended_avg.sp +++ b/mapchooser_extended/scripting/mapchooser_extended_avg.sp @@ -282,7 +282,7 @@ public void OnPluginStart() 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", "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_IncludeMaps = CreateConVar("mce_include", "5", "Specifies how many maps to include in the vote.", _, true, 2.0, true, 9.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); g_Cvar_Extend = CreateConVar("mce_extend", "0", "Number of extensions allowed each map.", _, true, 0.0); @@ -1055,13 +1055,12 @@ public Action Command_Mapvote(int client, int args) public Handle get_most_nominated_maps() { - int voteSize = GetVoteSize(2); int arraySize = ByteCountToCells(PLATFORM_MAX_PATH); Handle most_nominated_maps = CreateArray(arraySize); StringMap sm = new StringMap(); //november 2023 edit: now the leader can nominate one map per map played that can skip requirements: Expectation is the leader will want to lead the map. - //if leaders abuse the feature they should simply be removed from the feature. + //if leaders abuse the feature they should simply be removed from the leader list file. char MapleaderNominatedMap[PLATFORM_MAX_PATH]; GetMapleaderNominatedMap(MapleaderNominatedMap); @@ -1075,8 +1074,12 @@ public Handle get_most_nominated_maps() sm.GetValue(map_iteration, nominate_count_for_particular_map); //if i is 0 its admin nominated map that must come into the vote. - //if strequal the map was nominated by a leader and most be forced on the vote. - if(!i || StrEqual(map_iteration, MapleaderNominatedMap, false)) + //if strequal the map was nominated by a leader and must be forced on the vote. + if (!i) + { + nominate_count_for_particular_map = 1999; + } + else if(StrEqual(map_iteration, MapleaderNominatedMap, false)) { nominate_count_for_particular_map = 999; } @@ -1100,37 +1103,21 @@ public Handle get_most_nominated_maps() } static char map_[PLATFORM_MAX_PATH]; - for (int i = 0; i < voteSize; i++) + StringMapSnapshot sm_snapshot = sm.Snapshot(); + ArrayList SortedList = CreateArray(arraySize); + + for(int i = 0; i < sm_snapshot.Length; i++) { - int max_count = 0; - char picked_map[PLATFORM_MAX_PATH]; - StringMapSnapshot keys = sm.Snapshot(); - for (int j = 0; j < keys.Length; j++) - { - int size = keys.KeyBufferSize(j); - char[] buffer = new char[size]; - keys.GetKey(j, buffer, size); - if (StrEqual(buffer, "nominated_maps")) - { - continue; - } - int value = 0; - sm.GetValue(buffer, value); + sm_snapshot.GetKey(i, map_, sizeof(map_)); + SortedList.PushString(map_); + } - //first selection has most nominates, second selection second most etc etc - if (value >= max_count) - { - max_count = value; - strcopy(picked_map, sizeof(picked_map), buffer); - } - } + SortedList.SortCustom(NominateListSortCmp, sm); - delete keys; - if (strlen(picked_map) == 0) - { - continue; - } - sm.Remove(picked_map); + for(int i = 0; i < GetArraySize(SortedList); i++) + { + char picked_map[MAX_NAME_LENGTH]; + GetArrayString(SortedList, i, picked_map, sizeof(picked_map)); //2023 edit: respecting that only right amount of maps per group is allowed in vote int groups_[32]; @@ -1175,6 +1162,26 @@ public Handle get_most_nominated_maps() return most_nominated_maps; } +int NominateListSortCmp(int index1, int index2, Handle array, Handle hndl) +{ + char map1[PLATFORM_MAX_PATH]; + char map2[PLATFORM_MAX_PATH]; + GetArrayString(array, index1, map1, sizeof(map1)); + GetArrayString(array, index2, map2, sizeof(map2)); + + int count1, count2; + + StringMap sm = view_as(hndl); + + sm.GetValue(map1, count1); + sm.GetValue(map2, count2); + + if (count1 == count2) + return 0; + + return count1 > count2 ? -1 : 1; +} + /** * Starts a new map vote * @@ -1279,7 +1286,7 @@ void InitiateVote(MapChange when, Handle inputlist=INVALID_HANDLE) //2023 edit to allow multiple nominations per player Handle most_nominated_maps = get_most_nominated_maps(); - int voteSize = GetVoteSize(2); //voteSize wrong size probably for my for loop + int voteSize = GetVoteSize(0); //voteSize wrong size probably for my for loop if(GetConVarBool(g_Cvar_RandomizeNominations)) randomizeList = CloneArray(most_nominated_maps); @@ -1410,7 +1417,7 @@ void InitiateVote(MapChange when, Handle inputlist=INVALID_HANDLE) //SetMenuExitButton(g_VoteMenu, false); - if(GetVoteSize(2) <= GetMaxPageItems(GetMenuStyle(g_VoteMenu))) + if(GetVoteSize(0) <= GetMaxPageItems(GetMenuStyle(g_VoteMenu))) { //This is necessary to get items 9 and 0 as usable voting items SetMenuPagination(g_VoteMenu, MENU_NO_PAGINATION); @@ -1972,7 +1979,7 @@ void CreateNextVote() delete TimeMapListSnapshot; } - int voteSize = GetVoteSize(2); + int voteSize = GetVoteSize(0); int limit = (voteSize < GetArraySize(tempMaps) ? voteSize : GetArraySize(tempMaps)); // group -> number of maps nominated from group @@ -2125,12 +2132,12 @@ NominateResult InternalNominateMap(char[] map, int owner) PushArrayString(g_NominateList[owner], map); PushArrayCell(g_NominateOwners, owner); //maybe i only want to do this for the first nomination of each client - if(owner == 0 && g_NominateReservedCount < GetVoteSize(1)) + if(owner == 0 && g_NominateReservedCount < GetVoteSize(0)) g_NominateReservedCount++; else g_NominateCount++; - while(GetArraySize(g_NominateList[owner]) > GetVoteSize(2)) + while(GetArraySize(g_NominateList[owner]) > GetVoteSize(0)) { char oldmap[PLATFORM_MAX_PATH]; GetArrayString(g_NominateList[owner], 0, oldmap, PLATFORM_MAX_PATH); diff --git a/mapchooser_extended/scripting/nominations_extended_avg.sp b/mapchooser_extended/scripting/nominations_extended_avg.sp index 4c7ddc8c..a4ffa638 100755 --- a/mapchooser_extended/scripting/nominations_extended_avg.sp +++ b/mapchooser_extended/scripting/nominations_extended_avg.sp @@ -982,7 +982,11 @@ bool PopulateNominateListMenu(Menu menu, int client, const char[] filter = "") int nominate_count_for_particular_map = 0; sm.GetValue(map, nominate_count_for_particular_map); //if its console its admin nomination. if its g_iMapleaderWhoNominatedMap it was map nominated by leader, also has to be correct map out of 3. - if(!owner || (owner == g_iMapleaderWhoNominatedMap && StrEqual(map, g_cMapLeaderNominatedMap))) + if (!owner) + { + nominate_count_for_particular_map = 1999; + } + else if(owner == g_iMapleaderWhoNominatedMap && StrEqual(map, g_cMapLeaderNominatedMap)) { nominate_count_for_particular_map = 999; } @@ -1213,7 +1217,7 @@ public int Handler_MapSelectMenu(Menu menu, MenuAction action, int param1, int p //2023 November edit: one map nominated by mapleader will automatically go to the vote. if (param1 == mapLeader && StrEqual(g_cMapLeaderNominatedMap, "")) { - CPrintToChatAll("{darkorange}[UNLOZE Nominations] {white}The map leader {lightgreen}%N {white}has nominated the map {red}%s{white}. The map will be in the next mapvote.", param1, map); + CPrintToChatAll("{darkorange}[UNLOZE Nominations] {white}The map leader {lightgreen}%N {white}has nominated the map {red}%s{white}. The map will be in the mapvote.", param1, map); CPrintToChatAll("{lightblue}If the map is nextmap and the leader wont play it he will be removed from leader access."); Format(g_cMapLeaderNominatedMap, sizeof(g_cMapLeaderNominatedMap), map); g_iMapleaderWhoNominatedMap = param1;