Detect closest unit

Weep

Godspeed to the sound of the pounding
Reaction score
400
You'll need to set a unit group to all units in the maximum range you want, then use a unit variable and real variable to track which unit is closest and the distance to that unit, and replace the value of the unit variable if the distance to the picked unit from the group is less than the previous distance value.

Trigger:
  • Actions
    • Set TempPoint = (Position of Center Unit)
    • Set TempGroup = (Units within 600.00 of TempPoint)
    • Set Distance = 600.00
    • Unit Group - Pick every unit in TempGroup and do (Actions)
      • Loop - Actions
        • Set TempPoint2 = (Position of (Picked unit))
        • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
          • If - Conditions
            • (Distance between TempPoint and TempPoint2) Less than or equal to distance
          • Then - Actions
            • Set TempUnit = (Picked unit)
            • Set Distance = (Distance between TempPoint and TempPoint2)
          • Else - Actions
        • Custom script: call RemoveLocation (udg_TempPoint2)
    • Custom script: call DestroyGroup(udg_TempGroup)


Credit to Flare, whose Chain Lightning spell I referred to: http://www.thehelper.net/forums/showthread.php?t=87066
 

Undead Me

New Member
Reaction score
5
I don't quite understand this and I'm trying to use it in a game. I want a spell to detect which enemy within an 800 radius is closest, then create a dummy unit who uses a spell on that closest unit.
I mimiced the trigger here, but I don't know how to take the information it gives and use it.
 

Slapshot136

Divide et impera
Reaction score
471
I don't quite understand this and I'm trying to use it in a game. I want a spell to detect which enemy within an 800 radius is closest, then create a dummy unit who uses a spell on that closest unit.
I mimiced the trigger here, but I don't know how to take the information it gives and use it.

tempunit is the unit that is closest after that runs, you would need to add an extra condition so that not only is the distance the least, it is also an enemy of whoever, and then after it check that the unit is within 800 range and an enemy again
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top