d3nn16 3 Posted July 17, 2011 Hi What are the possibilities in an SQF script to retrieve the list of markers placed in a map in the editor. My CTF mission is a template and users that don't know much about scripting will mostly place markers in the editor (along with units and buildings). In my scripts I need to retrieve these markers. For now I thought of 2 solutions : #solution 1 - having standard named markers (game_area_1, game_area_2, etc) and a script that tests the existence of each marker in sequence (game_area_1, game_area_2, etc) - the problem is that if there are many markers to place on the map and if a user forgets to place the game_area_2 marker then all the following markers are skipped (game_area_3, game_area_4, etc) #solution 2 - also with standard named markers but with variable part after "game_area" keyword (game_areabla, game_area_bla1, etc) - to get the list of markers I thought of reading the mission.sqm file (loadFIle) then transform the string to an array (toArray) and then loop through all characters and match the "name=game_area" sequence and grab the variable part Is there a more convenient way of doing this ? I searched in the forum and in the wiki, apparently there isn't any other way. I tested some of the configFile entries but couldn't find any that held the list of markers placed through the editor in the mission.sqm file. Thanks Share this post Link to post Share on other sites
sbsmac 0 Posted July 17, 2011 (edited) - having standard named markers (game_area_1, game_area_2, etc) and a script that tests the existence of each marker in sequence (game_area_1, game_area_2, etc)- the problem is that if there are many markers to place on the map and if a user forgets to place the game_area_2 marker then all the following markers are skipped (game_area_3, game_area_4, etc) The way I worked around this in pvpscriptpack (and the following ) was just to search the namespace from marker_0 up to marker_99to get the list of markers I thought of reading the mission.sqm file It's possible but pretty tedious. In the end I decided it wasn't really worth the hassle. Is there a more convenient way of doing this ? VBS has a 'markers' command which gives a list of all marker names. You can vote for it to be ported over to ArmA here but don't get too excited - the request has been open for over two years :( Edited July 17, 2011 by sbsmac Share this post Link to post Share on other sites
d3nn16 3 Posted July 17, 2011 Here is a function that returns markers which names start with BASE_WEST, BASE_EAST and GAME_AREA using the loadFile command. I need to test if there is a limit on the file size for loadFile. f_get_markers = { // the mission.sqm file transformed into an array of numbers _mission_sqm = toArray loadFile "mission.sqm"; _mission_sqm_last_idx = count _mission_sqm - 1; // corresponding number arrays for: name="BASE_WEST, name="BASE_EAST and name="GAME_AREA strings _base_west_str = [110,97,109,101,61,34,66,65,83,69,95,87,69,83,84]; _base_east_str = [110,97,109,101,61,34,66,65,83,69,95,69,65,83,84]; _game_area_str = [110,97,109,101,61,34,71,65,77,69,95,65,82,69,65]; _lookup_str_last_idx = count _base_west_str - 1; _found_base_west_mrk = []; _found_base_east_mrk = []; _found_game_area_mrk = []; // looping through all the mission.sqm characters in numeric format for "_i" from 0 to _mission_sqm_last_idx do { // the current character position must be at N characters from the end of the mission_sqm array // where N is the number of characters of the strings we are looking for if (_i + _lookup_str_last_idx <= _mission_sqm_last_idx) then { // cur_word contains the string starting from _i position to _i + N - 1 position // where N is the size of the strings we are looking for _cur_word = []; for "_j" from _i to _i + _lookup_str_last_idx do { _cur_word set [count _cur_word, _mission_sqm select _j]; }; // compare the current looked up string with the strings we are looking for _base_west_match = true; _base_east_match = true; _game_area_match = true; for "_k" from 0 to count _cur_word - 1 do { if (_cur_word select _k != _base_west_str select _k) then {_base_west_match = false}; if (_cur_word select _k != _base_east_str select _k) then {_base_east_match = false}; if (_cur_word select _k != _game_area_str select _k) then {_game_area_match = false}; if (! _base_west_match && ! _base_east_match && ! _game_area_match) then {break}; }; // grab the variable part _var_part = []; if (_base_west_match || _base_east_match || _game_area_match) then { _m = 1; // insert all following characters until a double quote is found _next = _i + _lookup_str_last_idx + _m; // "34" is the double quote character while {_next <= _mission_sqm_last_idx && _mission_sqm select _next != 34} do { _var_part set [count _var_part, _mission_sqm select _next]; _m = _m + 1; _next = _i + _lookup_str_last_idx + _m; }; }; if (_base_west_match) then { _marker = "BASE_WEST" + toString _var_part; // avoid duplicates - if another type of object has the same name as a marker // avoid objects that are not markers if (! (_marker in _found_base_west_mrk && markerType _marker != '')) then { _found_base_west_mrk set [count _found_base_west_mrk, _marker]; }; }; if (_base_east_match) then { _marker = "BASE_EAST" + toString _var_part; // avoid duplicates - if another type of object has the same name as a marker // avoid objects that are not markers if (! (_marker in _found_base_east_mrk && markerType _marker != '')) then { _found_base_east_mrk set [count _found_base_east_mrk, _marker]; }; }; if (_game_area_match) then { _marker = "GAME_AREA" + toString _var_part; // avoid duplicates - if another type of object has the same name as a marker // avoid objects that are not markers if (! (_marker in _found_game_area_mrk && markerType _marker != '')) then { _found_game_area_mrk set [count _found_game_area_mrk, _marker]; }; }; } else { break; }; }; [_found_base_west_mrk, _found_base_east_mrk, _found_game_area_mrk] }; Share this post Link to post Share on other sites