Jump to content
Sign in to follow this  
Koni

Distance to Faction side or group member

Recommended Posts

How do you use a trigger to measure the distance from a unit to a faction side or any group member?

I know about

unit distance unit <= 10

to measure distance between one unit and another or object but how do you use a faction side and a group member ?

Like, distance from unitname to any unit of Blufor faction, or unitname distance to any member of a certain group.

Thanks

Share this post


Link to post
Share on other sites

Try this:

{if ((side _x == east) && (_x distance unit <= 10)) then {hint "east unit is near !";}} foreach allunits;

Share this post


Link to post
Share on other sites

Don't know if this might help you...but it is a function I just put together that will return UNITS of a specified SIDE within a specified RADIUS.

You can then measure the distance to each unit or whatever. From testing... the first object in the returned list is always the closest object. Works with all things of type "LAND".... so will return units and land vehicles of the specified side.

I haven't thought about making it work with a trigger... but will post this anyway and have a further tinkle to see what I come up with.

fn_getNearUnits.sqf :-

/*

Put in init.sqf:-
getNearUnits = compile preprocessfile "fn_getNearUnits.sqf";

Call like this:-
_nearunits =  [object,radius,side_to_check_for] call getNearUnits;

Where object is an object, a marker or a position. 

returns number of units of side_to_check_for within the specified
radius of the object

*/

private ["_inp","_rad","_sid","_pos","_list","_i","_dude","_units"];

_inp = _this select 0;
_rad = _this select 1;
_sid = _this select 2;

switch (typename _inp) do {
case "OBJECT": {_pos = getpos _inp};
case "STRING": {_pos = getmarkerpos _inp};
case "ARRAY": {_pos = _inp};
};

_units = [];

_list = nearestObjects [_pos,["Land"],_rad];

for "_i" from 0 to ((count _list) - 1) do {
_dude = _list select _i;
if (_sid == side _dude) then {
	if (not(_dude in _units)) then {_units set [(count _units),_dude]};
};
};

_units

EDIT: Forgot to add that the thing you are scanning from can be an object, a marker or a position.

Edited by twirly
Clarity

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  

×