From 0868599cd07578b0fb860c125cb26b29b6050cc9 Mon Sep 17 00:00:00 2001 From: byjumpe Date: Fri, 8 Dec 2023 20:21:45 +0500 Subject: [PATCH] New MapManager (test) --- .../amxmodx/scripting/regg_mapmanager.sma | 76 ++++++++++++++++++- 1 file changed, 74 insertions(+), 2 deletions(-) diff --git a/cstrike/addons/amxmodx/scripting/regg_mapmanager.sma b/cstrike/addons/amxmodx/scripting/regg_mapmanager.sma index 3c33f67..914d355 100644 --- a/cstrike/addons/amxmodx/scripting/regg_mapmanager.sma +++ b/cstrike/addons/amxmodx/scripting/regg_mapmanager.sma @@ -1,7 +1,9 @@ #include +#include #include -new VoteType; +new VoteType, gMapNums; +new Array:gMapName; public plugin_init() { register_plugin("[ReGG] Map Manager", REGG_VERSION_STR, "Jumper & d3m37r4"); @@ -9,8 +11,12 @@ public plugin_init() { bind_pcvar_num(create_cvar( "regg_mapchange_type", "1", .has_min = true, - .min_val = 1.0 + .min_val = 0.0 ), VoteType); + + gMapName = ArrayCreate(MAX_NAME_LENGTH); + + loadMapCfg(); } public ReGG_FinishPost(const killer, const victim) { @@ -19,6 +25,13 @@ public ReGG_FinishPost(const killer, const victim) { public MapChange() { switch(VoteType){ + case 0: { + new mapname[MAX_NAME_LENGTH]; + ArrayGetString(gMapName, random(gMapNums), mapname, charsmax(mapname)); + message_begin(MSG_ALL, SVC_INTERMISSION); + message_end(); + engine_changelevel(mapname); + } case 1: { server_cmd("mapm_start_vote"); } @@ -30,3 +43,62 @@ public MapChange() { } } } + +loadMapCfg() { + new maps_file[PLATFORM_MAX_PATH]; + get_configsdir(maps_file, charsmax(maps_file)); + format(maps_file, charsmax(maps_file), "%s/maps.ini", maps_file); + + if(!file_exists(maps_file)) { + get_cvar_string("mapcyclefile", maps_file, charsmax(maps_file)); + } + + if(!file_exists(maps_file)) { + format(maps_file, charsmax(maps_file), "mapcycle.txt") + } + + loadMapsFile(maps_file); +} + +loadMapsFile(file[]) { + new iFile = fopen(file, "rt"); + if(!iFile) { + set_fail_state("File ^"%s^" is not found", file); + } + + new szBuffer[PLATFORM_MAX_PATH], szMaps[MAX_NAME_LENGTH]; + while(!feof(iFile)) { + fgets(iFile, szBuffer, charsmax(szBuffer)); + parse(szBuffer, szMaps, charsmax(szMaps)); + + if(!szBuffer[0] || szBuffer[0] == ';' || !isValidMap(szMaps)) { + continue; + } + + ArrayPushString(gMapName, szMaps); + gMapNums++; + } + + fclose(iFile); +} + +stock bool:isValidMap(mapname[]) { + if (is_map_valid(mapname)){ + return true; + } + + new len = strlen(mapname) - 4; + if (len < 0) { + return false; + } + + if (equali(mapname[len], ".bsp")){ + mapname[len] = '^0'; + + if (is_map_valid(mapname)) { + return true; + } + } + + return false; +}