• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

Check closest unit

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,543
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:
Top