- Joined
- Jul 15, 2012
- Messages
- 89
how can i order a unit to attack nearest enemy unit?
This was posted by Maker in some other thread
point1 and point2 are point variables, real1 and real2 real variables and unit1 is unit variable.
- Closest Unit
- Events
- Your event
- Conditions
- Your conditions
- Actions
- Set point1 = (Position of (Triggering unit))
- Set real1 = 10000.00
- Custom script: set bj_wantDestroyGroup = true
- Unit Group - Pick every unit in (Units within 1500.00 of point1) and do (Actions)
- Loop - Actions
- Set point2 = (Position of (Picked unit))
- Set real2 = (Distance between point1 and point2)
- If (All Conditions are True) then do (Then Actions) else do (Else Actions)
- If - Conditions
- real2 Less than real1
- Then - Actions
- -------- We have found our closest unit --------
- Set Unit1 = (Picked unit)
- Set real1 = real2
- Else - Actions
- Custom script: call RemoveLocation(udg_point2)
- Custom script: call RemoveLocation(udg_point1)
- -------- Closest unit to point1 is Unit1 --------
You can tweak it a bit by adding conditions for unit group and increasing/decreasing the range.