Picking Nearest Unit

AceHart

Your Friendly Neighborhood Admin
Reaction score
1,495
Code:
Set Point1 = Position of <some unit>
Set UnitGroup = Units within 500.0 of Point1 matching (((Matching unit) ... whatever you need))
Set Distance = 1000.0 (anything bigger than the range above will do)
Set Unit = No unit
Pick every unit in UnitGroup and do
    Set Point2 = Position of (Picked unit)
    If Distance between Point1 and Point2 less than Distance then
        Set Unit = (Picked unit)
        Set Distance = Distance between Point1 and Point2
    Custom script: call RemoveLocation( udg_Point2 )
Custom script: call RemoveLocation( udg_Point1 )
Custom script: call DestroyGroup( udg_UnitGroup )
... do whatever do "Unit"
 

ccsdude

New Member
Reaction score
2
I think there is no command like that, you need to select units in an 500 area for example and then calculate the distance, then you compare it with the last distance you got and keep the one that is the less.

I would give you the trigger but don't have WE on this computer.

EDIT: ohh, he manage to give im a trigger... :(
 

Tom Jones

N/A
Reaction score
437
Nope, but you can make your own:
Trigger:
  • Test
    • Events
    • Conditions
    • Actions
      • Set Point[1] = *Somewhere*
      • Set Distance[1] = 1000000000.00
      • Custom script: set bj_wantDestroyGroup = true
      • Unit Group - Pick every unit in (Units within 500.00 of Point[1]) and do (Actions)
        • Loop - Actions
          • Set Point[2] = (Position of (Picked unit))
          • Set Distance[2] = (Distance between Point[1] and Point[2])
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Distance[2] Less than Distance[1]
            • Then - Actions
              • Set Distance[1] = Distance[2]
              • Set Nearest_Unit = (Picked unit)
            • Else - Actions
          • Custom script: call RemoveLocation(udg_Point[2])
      • -------- Nearest_Unit is now ready for use. --------
      • Custom script: call RemoveLocation(udg_Point[1])
 

LordSaddler1

New Member
Reaction score
4
ok thanks everybody!


(I would add more rep to you Tom Jones, but you've helped me in my last 4 problems so It's making me spread it around.)
 
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