|
| 1 | +#include <amxmodx> |
| 2 | +#include <map_manager> |
| 3 | +#include <map_manager_scheduler> |
| 4 | + |
| 5 | +#define PLUGIN "Map Manager: Online checker" |
| 6 | +#define VERSION "1.0.0" |
| 7 | +#define AUTHOR "Sergey Shorokhov" |
| 8 | + |
| 9 | +#pragma semicolon 1 |
| 10 | + |
| 11 | +#define get_num(%0) get_pcvar_num(g_pCvars[%0]) |
| 12 | +#define get_float(%0) get_pcvar_float(g_pCvars[%0]) |
| 13 | + |
| 14 | +enum (+=100) { |
| 15 | + TASK_CHECK_ONLINE = 100 |
| 16 | +}; |
| 17 | + |
| 18 | +enum Cvars { |
| 19 | + CHECK_INTERVAL, |
| 20 | + CHECKS_COUNT, |
| 21 | + CHECK_TIMEOUT |
| 22 | +}; |
| 23 | + |
| 24 | +new g_sPrefix[48]; |
| 25 | +new g_pCvars[Cvars]; |
| 26 | + |
| 27 | +new g_CurrentMap[MapStruct]; |
| 28 | +new g_Warnings; |
| 29 | + |
| 30 | +public plugin_init() { |
| 31 | + register_plugin(PLUGIN, VERSION + VERSION_HASH, AUTHOR); |
| 32 | + |
| 33 | + g_pCvars[CHECK_INTERVAL] = register_cvar("mapm_online_check_interval", "30"); |
| 34 | + g_pCvars[CHECKS_COUNT] = register_cvar("mapm_online_check_count", "3"); |
| 35 | + g_pCvars[CHECK_TIMEOUT] = register_cvar("mapm_online_check_timeout", "120"); |
| 36 | +} |
| 37 | + |
| 38 | +public plugin_cfg() { |
| 39 | + mapm_get_prefix(g_sPrefix, charsmax(g_sPrefix)); |
| 40 | + get_mapname(g_CurrentMap[Map], charsmax(g_CurrentMap[Map])); |
| 41 | +} |
| 42 | + |
| 43 | +public task_check_online() { |
| 44 | + if(get_num(CHECKS_COUNT) <= 0) { |
| 45 | + return; |
| 46 | + } |
| 47 | + |
| 48 | + new current_online = get_players_num(); |
| 49 | + if(current_online != 0 && get_float(CHECK_TIMEOUT) > get_gametime()) { |
| 50 | + return; |
| 51 | + } |
| 52 | + |
| 53 | + new bool: is_online_incorrect = (current_online < g_CurrentMap[MinPlayers] || current_online > g_CurrentMap[MaxPlayers]); |
| 54 | + |
| 55 | + g_Warnings = clamp(is_online_incorrect ? ++g_Warnings : --g_Warnings, 0, get_num(CHECKS_COUNT)); |
| 56 | + if(g_Warnings != get_num(CHECKS_COUNT)) { |
| 57 | + return; |
| 58 | + } |
| 59 | + |
| 60 | + client_print_color(0, print_team_default, "%s^1 %L", g_sPrefix, LANG_PLAYER, "MAPM_RTV_START_VOTE"); |
| 61 | + |
| 62 | + map_scheduler_start_vote(VOTE_BY_INCORRECT_ONLINE); |
| 63 | +} |
| 64 | + |
| 65 | +public mapm_maplist_loaded(Array: maplist, const nextmap[]) { |
| 66 | + remove_task(TASK_CHECK_ONLINE); |
| 67 | + |
| 68 | + new idx = mapm_get_map_index(g_CurrentMap[Map]); |
| 69 | + if(idx == INVALID_MAP_INDEX) { |
| 70 | + return; |
| 71 | + } |
| 72 | + |
| 73 | + g_Warnings = 0; |
| 74 | + set_task(get_float(CHECK_INTERVAL), "task_check_online", .flags = "b", .id = TASK_CHECK_ONLINE); |
| 75 | + ArrayGetArray(maplist, idx, g_CurrentMap); |
| 76 | +} |
| 77 | + |
| 78 | +public mapm_can_be_extended(type) { |
| 79 | + if(type != VOTE_BY_INCORRECT_ONLINE) { |
| 80 | + return EXTEND_ALLOWED; |
| 81 | + } |
| 82 | + |
| 83 | + return EXTEND_BLOCKED; |
| 84 | +} |
0 commit comments