@@ -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}
150163public 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}
156169public 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;
0 commit comments