Jump to content
Sign in to follow this  
snkman

Select all units of a group?

Recommended Posts

Hey guy's,

I'm trying to get a distance between two groups but not only the leaders of the group should be used to check the distance i like to have every soldier from group A checks the distance to every Soldier of group B

EXAMPLE Leader:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">if ((count (units _nh) > 1) && (leader _nh) distance (leader _tg) < 100) then {hint "Good"}

So this checks only the distance between the leaders of the groups.

If leader _nh distance < 100 to leader _tg then "Good"

Okay now i like to have that the distance between all Soldiers in thouse two groups is calculated.

So if any Soldier of group _nh is < 100 to any Soldier of group _tg then "Good"

I tryed with select:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

_i = count units _nh

if ((count (units _nh) > 1) && (units _nh select random _i) distance (leader _tg) < 100) then {hint "Good"}

Okay this works but even not for all Soldiers with random there is always one Soldier of group _nh randomly picked to check the distance

So how can i get this to work, that every soldier from group _nh checks the distance with every soldier of group _tg

Share this post


Link to post
Share on other sites

M8 this is untested and in sqf format but you could try something like this

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_c = 0;

_no_nh = count units _nh;

if (_no_nh >= 1 && _c <= _no_nh) then

{

_unit_nh = _nh select _c;

{if (_unit_nh distance _x) < 100) then {hint "Good"}} forEach _tg;

_c = _c + 1;

}

Essentially it cycles through each member of the group _nh one at a time and for each it checks to see if the distance is less than 100 metres for all the members of group _tg using the forEach command.

Share this post


Link to post
Share on other sites

Thanks for the help guy's smile_o.gif

Well i can't use .sqf becouse i don't understand it and all my stuff is coded in .sqs

@Op4 BuhBye

Could you plz give me an example what exactly do you mean with "foreach LeaderName" or could you show me how the line should look like?

This would be very helpful.

Share this post


Link to post
Share on other sites

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_a = 0

#SeverlyLimitedAndPerformanceKillingBecauseIWontLearnSQFLoop

_unit = GroupA select _a

?({(_x distance _unit)<100} count units GroupB > 0):goto "FoundOne"

_a = _a + 1

?(_a < count units GroupA):goto "SeverlyLimitedAndPerformanceKillingBecauseIWontLearnSQFLoop"

;Didn't find any

exit

#FoundOne

;Do Something

exit

biggrin_o.gif

Share this post


Link to post
Share on other sites

biggrin_o.gif yes i know.

But bevore i start to learn .sqf i need to learn all the basics.

Thank you very much for the nice example CrashDome smile_o.gif

Share this post


Link to post
Share on other sites

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">{Y = _X;{_X distance Y < 100} count (units GroupB) > 0} count (units GroupA) > 0

Untested, but I think it'd work.

Share this post


Link to post
Share on other sites

crazy_o.gif You are really confusing me Kyle biggrin_o.gif

And where do i put this now? then {hint "Good"}

Share this post


Link to post
Share on other sites

I think what kyle really meant to put was:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">{_Y = _X;{_X distance _Y < 100} count (units GroupB) > 0} count (units GroupA) > 0

which was similar to the snippet I wrote and then scratched out because mine was wrong.

You would use this line as your condition in an if statement or trigger etc.:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">if ({_Y = _X;{_X distance _Y < 100} count (units GroupB) > 0} count (units GroupA) > 0) then {hint "We are screwed!"};

Share this post


Link to post
Share on other sites

Cool it works. smile_o.gif Many thanks

Share this post


Link to post
Share on other sites
I think what kyle really meant to put was:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">{_Y = _X;{_X distance _Y < 100} count (units GroupB) > 0} count (units GroupA) > 0

which was similar to the snippet I wrote and then scratched out  because mine was wrong.

You would use this line as your condition in an if statement or trigger etc.:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">if ({_Y = _X;{_X distance _Y < 100} count (units GroupB) > 0} count (units GroupA) > 0) then {hint "We are screwed!"};

How long have we been able to use _Y? huh.gifcrazy_o.gif

Where was that documented? How deep can we go? _Z?

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  

×