# [TRIGGER] Unit Group problem

Discussion in 'World Editor Help Zone' started by Dynasti, Aug 11, 2008.

1. ### Dynasti

Joined:
Oct 18, 2007
Messages:
877
Resources:
4
Maps:
2
Spells:
1
Tutorials:
1
Resources:
4
Ok, how do i make a unit group that picks only, lets say the 5 closest targets?

Code (Text):
[COLOR="Orange"]Edit:[/COLOR] [COLOR="Blue"]Fixed the problem, check out the map. [/COLOR]
[url=http://www.hiveworkshop.com/resources_new/spells/1562]Warcraft III Spells - Detect the closest units[/url]

Last edited: Aug 16, 2008
2. ### YoshiRyu

Joined:
Jun 26, 2007
Messages:
686
Resources:
0
Resources:
0
you've got to pick every unit (in limit range?) and to sort them in a other unit group, it will take cpu time :/

3. ### RunBa

Joined:
Jul 22, 2008
Messages:
353
Resources:
0
Resources:
0
Unit Group - Pick every unit in (Units matching (number of units in range of 500 less then or equal to 5)).... i think it can be done. but i'm at office so....

4. ### Squiggy

Joined:
Mar 25, 2008
Messages:
2,627
Resources:
18
Maps:
2
Spells:
15
Tutorials:
1
Resources:
18
eh.. what?
sorry but this fails in my opinion..
YoshiRyu is right i think

5. ### RunBa

Joined:
Jul 22, 2008
Messages:
353
Resources:
0
Resources:
0
I know. he is right. but i thought that give him something else. i said i have no WC3 instaled here so i can't try what I think...

6. ### NeC-ChRiSSi

Joined:
Jun 25, 2008
Messages:
64
Resources:
0
Resources:
0
Maybe like this:
Set X = 0
Pick Every unit in 500 range of XXX
Set X = X + 1
if X <= 5
Add (Picked unit) to YourGroup // Variable of Type: Unit Group

Then you have your 5 units in "YourGroup"
As I think the Command "Pick Every Unit in X range" starts with the closest ones. But im not sure
And im not sure if this will work..^^

7. ### Dynasti

Joined:
Oct 18, 2007
Messages:
877
Resources:
4
Maps:
2
Spells:
1
Tutorials:
1
Resources:
4
K Nec-ChRiSSi, il check it out,
+ rep

Joined:
Mar 25, 2008
Messages:
2,627
Resources:
18
Maps:
2
Spells:
15
Tutorials:
1
Resources:
18
9. ### Dynasti

Joined:
Oct 18, 2007
Messages:
877
Resources:
4
Maps:
2
Spells:
1
Tutorials:
1
Resources:
4
Ok i have tried it out, but it chooses random units...

File size:
25.9 KB
Views:
37

Joined:
Mar 25, 2008
Messages:
2,627
Resources:
18
Maps:
2
Spells:
15
Tutorials:
1
Resources:
18

11. ### YoshiRyu

Joined:
Jun 26, 2007
Messages:
686
Resources:
0
Resources:
0
the trigger probably pick and check the units in their order in the "all-units" array of the game
that was obvious to me that a "pick" feature doesn't sort its elements : why the game would perform a process wich cost cpu time if this process is almost never usefull ?

you've got to sort the group by yourself, that's the only way i think because blizzard hadn't made a "sort units by distance to a point" feature

12. ### Dynasti

Joined:
Oct 18, 2007
Messages:
877
Resources:
4
Maps:
2
Spells:
1
Tutorials:
1
Resources:
4
ok then, how do i do that ???

Joined:
Aug 20, 2007
Messages:
1,048
Resources:
2
Maps:
2
Resources:
2
14. ### YoshiRyu

Joined:
Jun 26, 2007
Messages:
686
Resources:
0
Resources:
0
a trigger wich perform 333 pick-in-range, i'm not sure it will faster than a bubble sort on a unit group
add at least al loop's break when the fifth unit is reached

15. ### Vicboy

Joined:
Aug 20, 2007
Messages:
1,048
Resources:
2
Maps:
2
Resources:
2
It doesn't break the loop... It just does nothing if there are already 5 units in a unit group...

16. ### YoshiRyu

Joined:
Jun 26, 2007
Messages:
686
Resources:
0
Resources:
0
yes, i know, and i say you it should (at least)

17. ### Vicboy

Joined:
Aug 20, 2007
Messages:
1,048
Resources:
2
Maps:
2
Resources:
2
How then do you brake a loop?

18. ### YoshiRyu

Joined:
Jun 26, 2007
Messages:
686
Resources:
0
Resources:
0
you convert it in JASS (or you add a Custom Script action), and you use "exitwhen CountUnitsInGroup(closestunits) >= 5" at the right place

19. ### Eleandor

Joined:
Aug 21, 2005
Messages:
3,681
Resources:
2
Models:
1
Tutorials:
1
Resources:
2
Making loops in GUI:

We'll need: a global integer variable. I'll call it
Integer_C

Making the loop:
• For each Integer_C from 1 to 3 do (multiple actions)
• Loop - actions
• If (all conditions are true) then do (then actions) else do (else actions)
• If - Conditions
• Then - Actions
• Set Integer_C = 4
• Else - Actions
• Set Integer_C = 1

Using this for loop, you create an infinite loop. The loop is only exited when the "If - conditions" are reached. In your example, you do:

• For each Integer_C from 1 to 3 do (multiple actions)
• Loop - actions
• If (all conditions are true) then do (then actions) else do (else actions)
• If - Conditions
• (Number of units in closestunits) Less than (<) 5
• Then - Actions
• Set Integer_C = 4
• Else - Actions
• Find the closest unit and add it to the unit group ClosestUnits
• Set Integer_C = 1
• Unit Group - pick every unit in ClosestUnits and do actions
• Do stuff with the 5 units

20. ### YoshiRyu

Joined:
Jun 26, 2007
Messages:
686
Resources:
0
Resources:
0
but "Find the closest unit and add it to the unit group ClosestUnits" have two problems :
1) it's in fact "Find the closest unit wich is not already in the group"
2) it will require a second loop in the loop :/

in JASS, you can use "exitwhen" as many time as you wish and anywhere in the loop, that's usefull

anyway i'm still thinking that a loop's "pick in range" with an incremental range will take more time than any kind of sort algorythm, even than a simple bubble sort.
"pick in range" is a glutton action, each occurence of it create a new group, check all unit of the game, make two real substractions + two real square + one real addition + one real square root + a real comparison for each unit.