ThySpektre
TH.net Regular
- Reaction score
- 10
I am trying to make an ability fire off when an item is dropped. I want it to target the nearest enemy unit. Any ideas how to find the nearest enemy unit?
ThySpektre
ThySpektre
Set Closest = No unit
Set Dist1 = 800.00
Set Point1 = (Position of (Triggering unit))
Custom script: set bj_wantDestroyGroup = true
Unit Group - Pick every unit in (Units within Dist1 of Point1 matching ((((Matching unit) belongs to an enemy of (Owner of (Triggering unit))) Equal to True) and (((Matching unit) is alive) Equal to True))) and do (Actions)
Loop - Actions
Set Point2 = (Position of (Picked unit))
Set Dist2 = (Distance between Point1 and Point2)
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
Dist1 Greater than Dist2
Then - Actions
Set Dist1 = Dist2
Set Closest = (Picked unit)
Else - Actions
Custom script: call RemoveLocation(udg_Point2)
Custom script: call RemoveLocation(udg_Point1)
Set Point1 = (Position of (Triggering unit))
Set Range1 = 999999.00
Set Closest = No unit
Set Interval = 50.00
For each (Integer A) from 1 to 1000, do (Actions)
Loop - Actions
Set Current = (Units within (Interval x (Real((Integer A)))) of Point1 matching ((((Matching unit) belongs to an enemy of (Owner of (Triggering unit))) Equal to True) and (((Matching unit) is alive) Equal to True)))
Unit Group - Remove all units of Done from Current
Unit Group - Pick every unit in Current and do (Actions)
Loop - Actions
Set Point2 = (Position of (Picked unit))
Set Range2 = (Distance between Point1 and Point2)
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
Range1 Greater than Range2
Then - Actions
Set Range1 = Range2
Set Closest = (Picked unit)
Else - Actions
Custom script: call RemoveLocation(udg_Point2)
Custom script: call DestroyGroup(udg_Current)
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
Closest Not equal to No unit
Then - Actions
Custom script: exitwhen true
Else - Actions
Unit Group - Add all units of Current to Done
Custom script: call RemoveLocation(udg_Point1)
Unit Group - Remove all units from Done
Set Interval = 50
For Integer A = 1 to 1000
Set unitGroup = (Units Within (Interval x Integer A) Matching (Matching Unit is an enemy of (Triggering Unit))
If - Conditions:
Number of Units in unitGroup > 0
Then - Actions:
Pick Every Unit in unitGroup and Do:
<Cycle Units to Find Closest Unit>
Else - Actions:
Do Nothing
And "number of units in unit group" actually uses a "pick every" action along with a global variable to count units anyway.pladams9 said:Your right. If there aren't any units in the unit group it won't run anyway.