Jump to content
Sign in to follow this  
davidoss

fix array

Recommended Posts

Hi. Its me again.

 

I got this code  from somewhere on this forum:

_cities = [];
_locations = configfile >> "CfgWorlds" >> worldName >> "Names";
_cityTypes = ["NameVillage","NameCity","NameCityCapital","NameLocal"];

for "_x" from 0 to (count _locations - 1) do {

private["_cityPos","_cityType"];
_randomLoc = _locations select _x;
_cityPos = getArray(_randomLoc >> "position");
_cityType = getText(_randomLoc >> "type"); 

	if (_cityType in _cityTypes) then {

		_cities pushBack [_cityPos]; 
	};  
};  
_cities;

This is giving me array of positions in format

[[[2915.2,6164.52]],[[2615.44,597.12]],[[2718.53,1712.08]]]

I need

[[2915.2,6164.52],[2615.44,597.12],[2718.53,1712.08]]

How to fix that?

 

Please help.

Share this post


Link to post
Share on other sites

Is there any solution to apply position correction on each array element?

 

I.e

 

from

[[2915.2,6164.52],[2615.44,597.12],[2718.53,1712.08]]

to

[[2950,6150],[2650,550],[2750,1750]]

This is about to get exact some sector center.

Share this post


Link to post
Share on other sites

and since you are using parts of "SL_fnc_urbanAreas" you could add this line so strangely coded positions are fetched, too (e.g. for PR Fata sometimes position like ["3454,24 + 2342,34", "2343.23 + 2324.23"] occure)

 

_cityPos = getArray (_randomLoc >> "position");
if (typeName (_cityPos select 0) == "String") then
{
    _cityPos = [call compile (_cityPos select 0), call compile (_cityPos select 1)];
};

Share this post


Link to post
Share on other sites

Is there any solution to apply position correction on each array element?

 

I.e

 

from

[[2915.2,6164.52],[2615.44,597.12],[2718.53,1712.08]]

to

[[2950,6150],[2650,550],[2750,1750]]

This is about to get exact some sector center.

 this will propably only work if you do it manualy. The center of a city name is defined in the config. But if you see a pettern in the positions you could do this. E.g. the positions are always off a certain vector.

 

 

if you want the positions to be exact in the middle of a square on the map you coud use "modulo". 

 

%

_nbr = floor (_pos select 0); // _pos = [2915.2,6164.52] -> _nbr = 2915
_rest = nbr%50; // _rest =  15  <- look up the right syntax plz
_nbr = (50 - _rest) + nbr; //2950

_nbr ist the first index of your position array _pos

with floor you get an integer number

_rest is the rest that remains when you devide _nbr / 50 .

e.g 55%3 = 1, or 34%2 = 0

now we define the new number _nbr with  (50 - _rest) + the old number _nbr

 

 

now you can do this for the next index of _pos

Share this post


Link to post
Share on other sites

_cities = [];
_locations = configfile >> "CfgWorlds" >> worldName >> "Names";
_cityTypes = ["NameVillage","NameCity","NameCityCapital","NameLocal"];




for "_x" from 0 to (count _locations - 1) do 
{

    private["_cityPos","_cityType"];
    _randomLoc = _locations select _x;
    _cityPos = getArray(_randomLoc >> "position");
    _cityType = getText(_randomLoc >> "type"); 




    if(typeName(_cityPos select 0) == "String") then
    {
        _cityPos = [call compile (_cityPos select 0),call compile (_cityPos select 1)];
    };
    _posX = floor (_cityPos select 0);
    _posY = floor (_cityPos select 1);
    _rstX = _posX%50;
    _rsty = _posY%50;
    _posX = (50 - _rstX) + _posX;
    if (_posX%100 == 0) then {_posX = _posX + 50};
    _posY = (50 - _rstY) + _posY;
    if (_posY%100 != 0) then {_posY = _posY - 50};
    _cityPos set [0, _posX];
    _cityPos set [1, _posY];
    if (_cityType in _cityTypes) then 
    {
        _cities pushBack _cityPos; 
    };  
};  
_cities
/*
{
    _mrk = createMarker [format ["%1",str _x] , _x];
    _mrk setMarkerShape "ICON";
    _mrk setMarkerType "mil_dot";
}foreach _cities;
*/

sorry now they are dead center (at least on chernarus)

  • Like 1

Share this post


Link to post
Share on other sites

and consider putting the position correction into  "if (_cityType in _cityTypes) then { /*position correction*/ _cities pushBack _cityPos}; ". No need to waste CPU usage.

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×