Skip to content

Commit 6865e0a

Browse files
committed
core: new native mapm_load_maplist_to_array
1 parent 87673c8 commit 6865e0a

File tree

4 files changed

+51
-20
lines changed

4 files changed

+51
-20
lines changed

addons/amxmodx/scripting/include/map_manager.inc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,17 @@
2626
*/
2727
native mapm_load_maplist(filename[], clearlist = true);
2828

29+
/**
30+
* Load maps from file.
31+
* File loads from configs dir.
32+
*
33+
* @param array Array with item size MapStruct.
34+
* @param filename File name
35+
*
36+
* @noreturn
37+
*/
38+
native mapm_load_maplist_to_array(Array:array, filename[]);
39+
2940
/**
3041
* Get map index in mapslist array.
3142
*

addons/amxmodx/scripting/include/map_manager_blocklist.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@
1717
*
1818
* @param map Map name
1919
*
20-
* @return Blocked count
20+
* @return Blocked count
2121
*/
2222
native mapm_get_blocked_count(map[]);

addons/amxmodx/scripting/map_manager_core.sma

Lines changed: 39 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ public plugin_natives()
119119
register_library("map_manager_core");
120120

121121
register_native("mapm_load_maplist", "native_load_maplist");
122+
register_native("mapm_load_maplist_to_array", "native_load_maplist_to_array");
122123
register_native("mapm_get_map_index", "native_get_map_index");
123124
register_native("mapm_get_prefix", "native_get_prefix");
124125
register_native("mapm_set_vote_finished", "native_set_vote_finished");
@@ -145,13 +146,25 @@ public native_load_maplist(plugin, params)
145146

146147
new filename[256];
147148
get_string(arg_filename, filename, charsmax(filename));
148-
load_maplist(filename);
149+
load_maplist(g_aMapsList, filename);
150+
}
151+
public native_load_maplist_to_array(plugin, params)
152+
{
153+
enum {
154+
arg_array = 1,
155+
arg_filename
156+
};
157+
158+
new filename[256];
159+
get_string(arg_filename, filename, charsmax(filename));
160+
161+
load_maplist(Array:get_param(arg_array), filename, false);
149162
}
150163
public native_get_map_index(plugin, params)
151164
{
152165
enum { arg_map = 1 };
153166
new map[MAPNAME_LENGTH]; get_string(arg_map, map, charsmax(map));
154-
return get_map_index(map);
167+
return get_map_index(g_aMapsList, map);
155168
}
156169
public native_get_prefix(plugin, params)
157170
{
@@ -208,7 +221,7 @@ public native_push_map_to_votelist(plugin, params)
208221
return PUSH_BLOCKED;
209222
}
210223

211-
if(!(ignore_checks & CHECK_IGNORE_MAP_ALLOWED) && !is_map_allowed(map, get_param(arg_type), get_map_index(map))) {
224+
if(!(ignore_checks & CHECK_IGNORE_MAP_ALLOWED) && !is_map_allowed(map, get_param(arg_type), get_map_index(g_aMapsList, map))) {
212225
return PUSH_BLOCKED;
213226
}
214227

@@ -263,21 +276,28 @@ public plugin_cfg()
263276
replace_color_tag(g_sPrefix, charsmax(g_sPrefix));
264277

265278
// add forward for change file?
266-
load_maplist(FILE_MAPS);
279+
load_maplist(g_aMapsList, FILE_MAPS);
267280
}
268-
load_maplist(const file[])
281+
load_maplist(Array:array, const file[], bool:silent = false)
269282
{
270283
new file_path[256]; get_localinfo("amxx_configsdir", file_path, charsmax(file_path));
271284
format(file_path, charsmax(file_path), "%s/%s", file_path, file);
272285

273286
if(!file_exists(file_path)) {
274-
set_fail_state("Maps file doesn't exist.");
287+
if(!silent) {
288+
new error[192]; formatex(error, charsmax(error), "File doesn't exist ^"%s^".", file_path);
289+
set_fail_state(error);
290+
}
291+
return;
275292
}
276293

277294
new f = fopen(file_path, "rt");
278295

279296
if(!f) {
280-
set_fail_state("Can't read maps file.");
297+
if(!silent) {
298+
set_fail_state("Can't read maps file.");
299+
}
300+
return;
281301
}
282302

283303
new map_info[MapStruct], text[48], map[MAPNAME_LENGTH], first_map[MAPNAME_LENGTH], min[3], max[3], bool:nextmap, bool:found_nextmap;
@@ -286,7 +306,7 @@ load_maplist(const file[])
286306
fgets(f, text, charsmax(text));
287307
parse(text, map, charsmax(map), min, charsmax(min), max, charsmax(max));
288308

289-
if(!map[0] || map[0] == ';' || !valid_map(map) || get_map_index(map) != INVALID_MAP_INDEX) continue;
309+
if(!map[0] || map[0] == ';' || !valid_map(map) || get_map_index(array, map) != INVALID_MAP_INDEX) continue;
290310

291311
if(!first_map[0]) {
292312
copy(first_map, charsmax(first_map), map);
@@ -305,22 +325,23 @@ load_maplist(const file[])
305325
map_info[MinPlayers] = str_to_num(min);
306326
map_info[MaxPlayers] = str_to_num(max) == 0 ? 32 : str_to_num(max);
307327

308-
ArrayPushArray(g_aMapsList, map_info);
328+
ArrayPushArray(array, map_info);
309329
min = ""; max = "";
310330
}
311331
fclose(f);
312332

313-
if(!ArraySize(g_aMapsList)) {
333+
if(!ArraySize(array) && !silent) {
314334
new error[192]; formatex(error, charsmax(error), "Nothing loaded from ^"%s^".", file_path);
315335
set_fail_state(error);
316336
}
317337

318-
if(!found_nextmap) {
319-
set_cvar_string("amx_nextmap", first_map);
338+
if(!silent) {
339+
if(!found_nextmap) {
340+
set_cvar_string("amx_nextmap", first_map);
341+
}
342+
new ret;
343+
ExecuteForward(g_hForwards[MAPLIST_LOADED], ret, array);
320344
}
321-
322-
new ret;
323-
ExecuteForward(g_hForwards[MAPLIST_LOADED], ret, g_aMapsList);
324345
}
325346
//-----------------------------------------------------//
326347
// Vote stuff
@@ -594,10 +615,10 @@ stop_vote()
594615
//-----------------------------------------------------//
595616
// Usefull func
596617
//-----------------------------------------------------//
597-
get_map_index(map[])
618+
get_map_index(Array:array, map[])
598619
{
599-
for(new i = 0, map_info[MapStruct], size = ArraySize(g_aMapsList); i < size; i++) {
600-
ArrayGetArray(g_aMapsList, i, map_info);
620+
for(new i = 0, map_info[MapStruct], size = ArraySize(array); i < size; i++) {
621+
ArrayGetArray(array, i, map_info);
601622
if(equali(map, map_info[MapName])) return i;
602623
}
603624
return INVALID_MAP_INDEX;

addons/amxmodx/scripting/map_manager_rtv.sma

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ public plugin_init()
4747
g_pCvars[PERCENT] = register_cvar("mapm_rtv_percent", "60");
4848
g_pCvars[PLAYERS] = register_cvar("mapm_rtv_players", "5");
4949
g_pCvars[DELAY] = register_cvar("mapm_rtv_delay", "0"); // minutes
50-
// g_pCvars[CHANGE_TYPE] = register_cvar("mapm_rtv_change_type", "1"); // 0 - after vote, 1 - in round end
5150
g_pCvars[ALLOW_EXTEND] = register_cvar("mapm_rtv_allow_extend", "0"); // 0 - disable, 1 - enable
5251

5352
register_clcmd("say rtv", "clcmd_rtv");

0 commit comments

Comments
 (0)