Daskunk
SC2 Forum MVP - TheSkunk #386
- Reaction score
- 186
I’m trying to make a unit attack the closest unit to him.
This is my trigger right now:
It isn’t working. It attempts to chase two different units at a time, even though they are different distances apart, and it seems to try and attack the target every time the trigger fires even though I though I attempted to fix that (Target[1] Not equal to Target[2]). Also, After it kills a unit sometimes it just sits there instead of finding another target.
This is my trigger right now:
Code:
Me Chase
Events
Time - Every 0.50 seconds of game time
Conditions
Actions
Set P1 = (Position of Oger 0009 <gen>)
Set Target[2] = Target[1]
Set TargetRange = 10000000
Set G = (Units within 1000000.00 of P1 matching ((((Matching unit) is A structure) Equal to False) and (((Matching unit) is alive) Equal to True)))
Unit Group - Pick every unit in G and do (Actions)
Loop - Actions
Set P2 = (Position of (Picked unit))
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
(Integer((Distance between P1 and P2))) Less than TargetRange
Then - Actions
Set TargetRange = (Integer((Distance between P1 and P2)))
Set Target[1] = (Picked unit)
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
Target[1] Not equal to Target[2]
Then - Actions
Unit - Order Oger 0009 <gen> to Attack Target[1]
Game - Display to (All players) the text: (The oger is chasing + ((Name of (Owner of Target[1])) + !))
Else - Actions
Else - Actions
Custom script: call RemoveLocation (udg_P2)
Custom script: call RemoveLocation (udg_P1)
Custom script: call DestroyGroup (udg_G)