Jump to content
Sign in to follow this  
joikd

nearestObjects--filter results by distance?

Recommended Posts

nearestObjects [player, ["Car","Tank"], 1000]

Is there a way to run the above just once, but filter out objects based on distance rather than running it again? For example, could I get the objects from 200 to 1000, the objects from 200 to 800, and so on from the above? I don't want to run it multiple times for different ranges--it's just too demanding for higher ranges with many objects.

Share this post


Link to post
Share on other sites

that command returns an array of objects, so you can iterate through it, checking for it's distance from the player.

<tankycode>
_myobjects = nearestobjects [player, ["car", tank"], 1000];
{
_mydistance = player distance _x;
if ((_mydistance > 200) and (_mydistance < 1000)) then {_mynewarray set _x};
}foreach _myobjects;

Above code guaranteed not to work as is, but you get the idea. _mynewarray will contain only the car and tank objects from _myobjects that are between 200 and 1000 meters from the player.

---------- Post added at 21:00 ---------- Previous post was at 20:54 ----------

Oh and while I remember... if you don't need your _myobjects array to be sorted by distance, and from what I can see, you don't, you'd use nearobjects, but that command only allows you to specify one unit type to find, whereas you are using two. Swings/Roundabouts.

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  

×