snkman 351 Posted June 8, 2007 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
norrin 9 Posted June 8, 2007 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
Op4 BuhBye 0 Posted June 8, 2007 Or use the "foreach LeaderName" in sqs. Share this post Link to post Share on other sites
snkman 351 Posted June 8, 2007 Thanks for the help guy's 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
crashdome 3 Posted June 8, 2007 <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 Share this post Link to post Share on other sites
snkman 351 Posted June 8, 2007 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 Share this post Link to post Share on other sites
mr.peanut 1 Posted June 8, 2007 code snippet deleted due to error Share this post Link to post Share on other sites
Big Dawg KS 6 Posted June 8, 2007 <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
snkman 351 Posted June 8, 2007 You are really confusing me Kyle And where do i put this now? then {hint "Good"} Share this post Link to post Share on other sites
mr.peanut 1 Posted June 9, 2007 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
snkman 351 Posted June 9, 2007 Cool it works. Many thanks Share this post Link to post Share on other sites
crashdome 3 Posted June 9, 2007 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? Where was that documented? How deep can we go? _Z? Share this post Link to post Share on other sites