Jump to content
Tory Xiao

Get an array of positions from objects in editor

Recommended Posts

Im trying 

{
    if (!isPlayer _x) then
    {
        _npcPos = getPosATL _x;

    };
} forEach entities "car";

copyToClipboard _npcPos;

 

But it returns nothing

Share this post


Link to post
Share on other sites

No need for a player check if you are already sorting entities for "CAR." Also, copyToClipboard takes a string.

_posArray = [];

{
    _pos = getPosATL _x;
	_posArray pushBack _pos;
} forEach entities "car";

copyToClipboard str _posArray;

I dropped five Hunters randomly on the map. The above code returns:

[[820.988,701.823,-0.00175762],[624.936,1078,-0.00216675],[1195.94,692.019,-0.00145912],[1372.38,1086.57,-0.000517845],[1013.36,1405.16,-0.00107384]]

 

  • Like 1

Share this post


Link to post
Share on other sites
1 hour ago, Harzach said:

No need for a player check if you are already sorting entities for "CAR." Also, copyToClipboard takes a string.


_posArray = [];

{
    _pos = getPosATL _x;
	_posArray pushBack _pos;
} forEach entities "car";

copyToClipboard str _posArray;

I dropped five Hunters randomly on the map. The above code returns:


[[820.988,701.823,-0.00175762],[624.936,1078,-0.00216675],[1195.94,692.019,-0.00145912],[1372.38,1086.57,-0.000517845],[1013.36,1405.16,-0.00107384]]

 

Thanks! Another question, how do I get the position in 2D [x,y] format? getPos, getPosASL, getPosATL... all return 3D coordinates 

Share this post


Link to post
Share on other sites
_posArray = [];

{
    _pos = getPosATL _x;
    _pos deleteAt (count _pos -1);
    _posArray pushBack _pos;
} forEach entities "car";

copyToClipboard str _posArray;

Untested, but should work. I use "(count _pos -1)" instead of just "2" as the latter is apparently very performance heavy RE: the Biki. See the last comment here: https://community.bistudio.com/wiki/deleteAt

 

*edit* - tested OK

  • Like 2

Share this post


Link to post
Share on other sites

Convert just about anything into a position array,

you_convertToPos={    private _pos= objNull;
    if (typeName _this== "ARRAY") exitWith {_this};
    if (typeName _this== "LOCATION") exitWith {_pos = locationPosition _this; _pos};
    if !(typeName _this== "STRING") then {_pos = (_this ModelToWorld [0,0,0])} else {_pos = (getMarkerPos [_this, true])}    
    _pos
};

Example:
_arr =[(nearestLocation [getPos player, "nameCity"]), (player modelToWorld [0,3,0]), trigger_0, "marker_0"] apply {systemChat str (_x call you_convertToPos)};

Have fun!

  • Like 2

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

×