|
| 1 | +#include <amxmodx> |
| 2 | +#include <map_manager> |
| 3 | + |
| 4 | +#define PLUGIN "Map Manager: Online sorter" |
| 5 | +#define VERSION "0.0.1" |
| 6 | +#define AUTHOR "Mistrick" |
| 7 | + |
| 8 | +#pragma semicolon 1 |
| 9 | + |
| 10 | +#define get_num(%0) get_pcvar_num(g_pCvars[%0]) |
| 11 | + |
| 12 | +enum Cvars { |
| 13 | + CHECK_NOMINATED_MAPS |
| 14 | +}; |
| 15 | + |
| 16 | +new g_pCvars[Cvars]; |
| 17 | + |
| 18 | +new Array:g_aMapsList; |
| 19 | + |
| 20 | +public plugin_init() |
| 21 | +{ |
| 22 | + register_plugin(PLUGIN, VERSION, AUTHOR); |
| 23 | + |
| 24 | + g_pCvars[CHECK_NOMINATED_MAPS] = register_cvar("mapm_sort_check_nominated_maps", "0"); // 0 - disable, 1 - enable |
| 25 | +} |
| 26 | +public mapm_maplist_loaded(Array:maplist) |
| 27 | +{ |
| 28 | + g_aMapsList = maplist; |
| 29 | +} |
| 30 | +public mapm_prepare_votelist(type) |
| 31 | +{ |
| 32 | + if(type == VOTE_BY_SCHEDULER_SECOND) { |
| 33 | + return; |
| 34 | + } |
| 35 | + |
| 36 | + new players_num = get_players_num(); |
| 37 | + |
| 38 | + new Array:array = ArrayCreate(MAPNAME_LENGTH, 1); |
| 39 | + new map_info[MapStruct], size = ArraySize(g_aMapsList); |
| 40 | + |
| 41 | + server_print("Found maps for current online:"); |
| 42 | + for(new i; i < size; i++) { |
| 43 | + ArrayGetArray(g_aMapsList, i, map_info); |
| 44 | + if(map_info[MinPlayers] <= players_num <= map_info[MaxPlayers]) { |
| 45 | + ArrayPushString(array, map_info[MapName]); |
| 46 | + server_print("%d - %s", ArraySize(array), map_info[MapName]); |
| 47 | + } |
| 48 | + } |
| 49 | + |
| 50 | + new map[MAPNAME_LENGTH], max_items = mapm_get_votelist_size(); |
| 51 | + for(new i, index; i < max_items && ArraySize(array); i++) { |
| 52 | + index = random(ArraySize(array)); |
| 53 | + ArrayGetString(array, index, map, charsmax(map)); |
| 54 | + ArrayDeleteItem(array, index); |
| 55 | + if(mapm_push_map_to_votelist(map, PUSH_BY_ONLINE_SORTER) == PUSH_BLOCKED) { |
| 56 | + i--; |
| 57 | + } |
| 58 | + } |
| 59 | + |
| 60 | + ArrayDestroy(array); |
| 61 | +} |
| 62 | +public mapm_can_be_in_votelist(map[], type, index) |
| 63 | +{ |
| 64 | + // add online checks for another addons? |
| 65 | + |
| 66 | + if(type == PUSH_BY_NOMINATION && index != INVALID_MAP_INDEX && get_num(CHECK_NOMINATED_MAPS)) { |
| 67 | + new map_info[MapStruct]; ArrayGetArray(g_aMapsList, index, map_info); |
| 68 | + new players_num = get_players_num(); |
| 69 | + if(map_info[MinPlayers] > players_num || map_info[MaxPlayers] < players_num) { |
| 70 | + return MAP_BLOCKED; |
| 71 | + } |
| 72 | + } |
| 73 | + return MAP_ALLOWED; |
| 74 | +} |
0 commit comments