• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

Check closest unit

Status
Not open for further replies.

Uncle

Warcraft Moderator
Level 73
Joined
Aug 10, 2018
Messages
7,869
There's plenty of threads on this already, but here's the idea:
  • Actions
    • Set Variable Position1 = (Position of (Triggering unit))
    • Set Variable ClosestUnit = No unit
    • Set Variable ClosestDistance = 99999.00
    • Set Variable ClosestGroup = (Units that are allied with Owner of (Triggering unit) excluding (Triggering unit), Dead units, etc)
    • Unit Group - Pick every unit in ClosestGroup and do Actions
      • Loop - Actions
        • Set Variabe Position2 = (Position of (Picked unit))
        • Set Variable CurrentDistance = (Distance between Position 1 and Position2)
        • If all conditions are true then do (Actions)
          • If - Conditions
            • CurrentDistance Less than ClosestDistance
          • Then - Actions
            • Set Variable ClosestUnit = (Picked unit)
            • Set Variable ClosestDistance = CurrentDistance
          • Else - Actions
    • Unit - Kill ClosestUnit <-- just an example
After the Loop is completely finished you will have your ClosestUnit. Don't forget to clean up the memory leaks.
 
Last edited:
Status
Not open for further replies.
Top