Jump to content
Sign in to follow this  
bus

nearestObjects not detecting units inside vehicles

Recommended Posts

I'm using nearestObjects with the class filters "soldiereb" and "soldierwb" so that I can count how many units of each side are nearby. When a soldier is on foot, they're being returned in the array. When a soldier is mounted in a vehicle, they are not.

Here's the code:

_units_east = nearestObjects[(getmarkerpos _marker), ["soldiereb"], (_markersize select 0)];

The idea is that if the unit is within the marker, they're going to get a point for their team. Knowing that, please comment on how I can get around this limitation or if there's a better way to count units in an area, mounted or not.

Thanks,

Bus

Share this post


Link to post
Share on other sites

350 meters. Is there a limitation?

Well, I got around this by running this code as well:

_units_veh = nearestObjects[(getmarkerpos _marker), ["landvehicle"], (_markersize select 0)];

for [{ _loop = 0 },{ _loop < count _units_veh },{ _loop = _loop + 1 }] do

{

_units_veh_mounted = crew (_units_veh select _loop);

for [{ _unitloop = 0 },{ _unitloop < count _units_veh_mounted },{ _unitloop = _unitloop + 1 }] do

{

if(side (_units_veh_mounted select _unitloop) == West) then

{

_units_west_count = _units_west_count + 1;

}

else

{

_units_east_count = _units_east_count + 1;

};

};

};

And that in addition to just checking for infantry ("soldiereb", "soldierwb"), gives me the right total so I'm happy.

Thanks,

Bus

Share this post


Link to post
Share on other sites

It's not that there's a limitation, but you might find it easier to use the following code:

_eastCount = {side _x == east && _x distance (getMarkerPos _marker) <= 175} count allUnits;
_westCount = {side _x == west && _x distance (getMarkerPos _marker) <= 175} count allUnits;

I'm assuming that the marker is a circle and that 350 meters is the diameter, but you could of course change the number if that's not the case.

Share this post


Link to post
Share on other sites

Range/Diameter...it's all the same :-)

Thanks for the code, I'll give it a try!

-Bus

---------- Post added at 03:28 PM ---------- Previous post was at 03:21 PM ----------

Didn't know you could put conditions on count...nice to know.

Works perfectly. I knew there had to be an easier way. Thanks!

-Bus

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  

×