Jump to content
Sign in to follow this  
CarlGustaffa

How to find nearest unit of a given side...

Recommended Posts

...based on a position?

Having some problems with this one, without it having to go way too complicated.

Enemy AI artillery system have a possible target, but need to find out if they have some of their own units in the area. I've tried findNearestEnemy, based on one of our units, but that requires us to know about the enemy. Not always we do that.

Basically, a function like:

[_position, "east"] call fn_nearestfriendlyunit gives back an object or objNull.

Any suggestions? I don't want to use reveal btw.

Edit: It's important that I don't use the actual target, but a position, since I'm basing the risk on where the target will end up after projectile flight time.

Edited by CarlGustaffa

Share this post


Link to post
Share on other sites

How about nearestObjects?

{side _x == <friendly side>} count nearestObjects [<the position>,["Man","Car","Tank"],<the radius>] > 0

returns true if there are friendly units around, else false.

Share this post


Link to post
Share on other sites

_nearestunits = nearestObjects [<the position>,["Man","Car","Tank"],<the radius>];
_nearestfriendlies = [];

if(<your side> countSide _nearestunits > 0) then{
  {
     _unit = _x;
     if(side _unit == <your side>) then{_nearestfriendlies = _nearestfriendlies + [_unit]};
  } foreach _nearestunits;
};

This will give you the array _nearestfriendlies with all friendly units within the given radius around the given position, sorted by distance (closest unit is first element in array). If there is no friendly unit nearby, the array remains empty.

Maybe not the most elegant way, but it should work.

Share this post


Link to post
Share on other sites

Rgr that, thanks. I will try it out.

Edit: Seems to work pretty good. Thanks.

Edited by CarlGustaffa

Share this post


Link to post
Share on other sites

I'm trying to make my own CTF mode where i want to find the nearest unit within 5 meters of the flag where that unit is _unit. i have been searching around in different forums but cannot find anything that i can use that works. I am quite new to scripting and trying to learn as much as i can.

 

This is what i have so far:

//the init of the flag
[[blueflag,["Pickup","blueflag.sqf"]],"addAction",true] call BIS_fnc_MP;
//blueflag.sqf
_unit playActionNow "MedicOther";
sleep 6;
blueflag attachto [_unit, [0, 0.4, 5] ];
scopeName "loop";
while {alive _unit} do {
if (!alive _unit) then {detach blueflag; blueflag setpos getpos _unit; breakTo "loop2"} else {breakTo "loop"};

scopeName "loop2";
if (!alive _unit) then {[[blueflag,["Pickup","blueflag.sqf"]],"addAction",true] call BIS_fnc_MP; breakTo "loop";} else {breakTo "loop2"};

this code works when i make _unit = player. But if the player dies and someone else picks up the flag i want _unit to change to the unit which picked up the flag.

Share this post


Link to post
Share on other sites

I'm trying to make my own CTF mode where i want to find the nearest unit within 5 meters of the flag where that unit is _unit. i have been searching around in different forums but cannot find anything that i can use that works. I am quite new to scripting and trying to learn as much as i can.

 

This is what i have so far:

//the init of the flag
[[blueflag,["Pickup","blueflag.sqf"]],"addAction",true] call BIS_fnc_MP;

You're confused. This is for Arma 3 not for Arma 2 / OA

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  

×