Tracking - 2 Closes units

lindenkron

You can change this now in User CP
Reaction score
102
SOLVED

Trigger:
  • Track2nd
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Track
    • Actions
      • Set TempInt = 0
      • For each (Integer A) from 1 to 2, do (Actions)
        • Loop - Actions
          • Set TempReal = 1000000000.00
          • Set TempGroup = (Units in (Playable map area) matching ((Unit-type of (Matching unit)) Equal to Deer))
          • Unit Group - Pick every unit in TempGroup and do (Actions)
            • Loop - Actions
              • Set TempInt = (TempInt + 1)
              • Set TempLocation = (Position of (Triggering unit))
              • Set TempLocation2 = (Position of (Picked unit))
              • Set Distance[TempInt] = (Distance between TempLocation and TempLocation2)
              • Game - Display to (All players) for 30.00 seconds the text: (String(Distance[TempInt]))
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • Distance[TempInt] Less than TempReal
                  • ((Picked unit) is in TrackGroup) Equal to False
                • Then - Actions
                  • Set TempUnit = (Picked unit)
                  • Set TempReal = Distance[TempInt]
                • Else - Actions
              • Custom script: call RemoveLocation (udg_TempLocation2)
              • Custom script: call RemoveLocation (udg_TempLocation)
          • Unit Group - Add TempUnit to TrackGroup
          • Custom script: call DestroyGroup (udg_TempGroup)
      • Game - Display to (All players) for 30.00 seconds the text: ------------------2...
      • Unit Group - Pick every unit in TrackGroup and do (Actions)
        • Loop - Actions
          • Set TempLocation = (Position of (Triggering unit))
          • Set TempLocation2 = (Position of (Picked unit))
          • Set TempReal = (Distance between TempLocation and TempLocation2)
          • Game - Display to (All players) for 30.00 seconds the text: (Distance: + (String(TempReal)))
          • Custom script: call RemoveLocation (udg_TempLocation2)
          • Custom script: call RemoveLocation (udg_TempLocation)
          • Unit Group - Remove (Picked unit) from TrackGroup

________________________________________________

How would one go about finding the 2 closes units, to the unit using the spell?
What I have so far
Trigger:
  • Track
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Track
    • Actions
      • Set TempReal2 = 1000000000.00
      • Set TempGroup = (Units in (Playable map area) matching ((Unit-type of (Matching unit)) Equal to Deer))
      • Unit Group - Pick every unit in TempGroup and do (Actions)
        • Loop - Actions
          • Set TempLocation = (Position of (Triggering unit))
          • Set TempLocation2 = (Position of (Picked unit))
          • Set TempReal = (Distance between TempLocation and TempLocation2)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • TempReal Less than TempReal2
            • Then - Actions
              • Set TempReal2 = TempReal
              • Set TempUnit = (Picked unit)
            • Else - Actions
          • Custom script: call RemoveLocation (udg_TempLocation2)
          • Custom script: call RemoveLocation (udg_TempLocation)
      • Custom script: call DestroyGroup (udg_TempGroup)
      • Set TempLocation = (Position of TempUnit)
      • Cinematic - Ping minimap for (Player group((Owner of (Triggering unit)))) at TempLocation for 2.00 seconds
      • Custom script: call RemoveLocation (udg_TempLocation)


But it only finds one, since I don't know how to make that the 2 closes :)

Thanks,
-Lindenkron
 

Komaqtion

You can change this now in User CP.
Reaction score
469
Put all that in a loop of 2 and use an if there to check if the unit is in your unit group, then in the end of that loop, add the unit to the unit group.
 

lindenkron

You can change this now in User CP
Reaction score
102
Put all that in a loop of 2 and use an if there to check if the unit is in your unit group, then in the end of that loop, add the unit to the unit group.

Wha'? What unit group?

Maybe it's because you set TempReal2 to TempReal...
That's done so it can find the closest unit.. if it doesn't set it, then the TempReal would never become lower, indicating the closes unit.
 

AceHart

Your Friendly Neighborhood Admin
Reaction score
1,494
Sort them to an array and take the top two?


Alternatively, hope that something as simple as
Set Unit2 = Unit1
Set Unit1 = (Picked unit)
actually works :p
(Provided you compare the latest picked unit to both if it isn't closer than the current best)
 

lindenkron

You can change this now in User CP
Reaction score
102
Sort them to an array and take the top two?

Thats what I had in mind, since I've seen it some done somewhere before. Just don't really know how to do it :)

Edit:
I now got this, how do I pick the 2 lowest? Thx,
Trigger:
  • Track2nd
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Track
    • Actions
      • Set TempInt = 0
      • Set TempGroup = (Units in (Playable map area) matching ((Unit-type of (Matching unit)) Equal to Deer))
      • Unit Group - Pick every unit in TempGroup and do (Actions)
        • Loop - Actions
          • Set TempInt = (TempInt + 1)
          • Set TempLocation = (Position of (Triggering unit))
          • Set TempLocation2 = (Position of (Picked unit))
          • Set Distance[TempInt] = (Distance between TempLocation and TempLocation2)
          • Game - Display to (All players) the text: (Distance: + (String(Distance[TempInt])))
          • Custom script: call RemoveLocation (udg_TempLocation2)
          • Custom script: call RemoveLocation (udg_TempLocation)
      • Custom script: call DestroyGroup (udg_TempGroup)
 

Komaqtion

You can change this now in User CP.
Reaction score
469
Sorry for not helping you with your trigger instead but i have a working one here whuch i just put together... it hasn't been leakchecked much but. and you just change the condition first unitgroup variable to Deer, wasn't it :S and the messages are only to see that it worked ;)
Trigger:
  • Track
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Track
    • Actions
      • Set TempReal[1] = 1000000000.00
      • Set TempLocation[1] = (Position of (Triggering unit))
      • Set TempGroup[1] = (Units in (Playable map area) matching ((Matching unit) Not equal to (Triggering unit)))
      • For each (Integer A) from 1 to 2, do (Actions)
        • Loop - Actions
          • Unit Group - Pick every unit in TempGroup[1] and do (Actions)
            • Loop - Actions
              • Set TempLocation[2] = (Position of (Picked unit))
              • Set TempReal[2] = (Distance between TempLocation[1] and TempLocation[2])
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • TempReal[2] Less than TempReal[1]
                  • ((Picked unit) is in TempGroup[2]) Not equal to True
                • Then - Actions
                  • Set TempReal[1] = TempReal[2]
                  • Set TempUnit[(Integer A)] = (Picked unit)
                • Else - Actions
              • Custom script: call RemoveLocation(udg_TempLocation[2])
          • Unit Group - Add TempUnit[(Integer A)] to TempGroup[2]
          • Set TempReal[1] = 1000000000.00
      • Custom script: call RemoveLocation(udg_TempLocation[1])
      • Custom script: call DestroyGroup(udg_TempGroup[1])
      • Quest - Display to (All players) the Hint message: (Name of TempUnit[1])
      • Quest - Display to (All players) the Hint message: (Name of TempUnit[2])
      • Unit Group - Remove TempUnit[1] from TempGroup[2]
      • Unit Group - Remove TempUnit[2] from TempGroup[2]
 

lindenkron

You can change this now in User CP
Reaction score
102
Trigger:
  • Track2nd
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Track
    • Actions
      • Set TempInt = 0
      • Set TempReal = 1000000000.00
      • For each (Integer A) from 1 to 2, do (Actions)
        • Loop - Actions
          • Set TempGroup = (Units in (Playable map area) matching ((Unit-type of (Matching unit)) Equal to Deer))
          • Unit Group - Pick every unit in TempGroup and do (Actions)
            • Loop - Actions
              • Set TempInt = (TempInt + 1)
              • Set TempLocation = (Position of (Triggering unit))
              • Set TempLocation2 = (Position of (Picked unit))
              • Set Distance[TempInt] = (Distance between TempLocation and TempLocation2)
              • Game - Display to (All players) for 30.00 seconds the text: (String(Distance[TempInt]))
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • Distance[TempInt] Less than TempReal
                  • ((Picked unit) is in TrackGroup) Equal to False
                • Then - Actions
                  • Set TempUnit = (Picked unit)
                • Else - Actions
              • Custom script: call RemoveLocation (udg_TempLocation2)
              • Custom script: call RemoveLocation (udg_TempLocation)
          • Unit Group - Add TempUnit to TrackGroup
          • Custom script: call DestroyGroup (udg_TempGroup)
      • Game - Display to (All players) for 30.00 seconds the text: ------------------2...
      • Unit Group - Pick every unit in TrackGroup and do (Actions)
        • Loop - Actions
          • Set TempLocation = (Position of (Triggering unit))
          • Set TempLocation2 = (Position of (Picked unit))
          • Set TempReal = (Distance between TempLocation and TempLocation2)
          • Game - Display to (All players) for 30.00 seconds the text: (Distance: + (String(TempReal)))
          • Custom script: call RemoveLocation (udg_TempLocation2)
          • Custom script: call RemoveLocation (udg_TempLocation)
          • Unit Group - Remove (Picked unit) from TrackGroup


This gives me:
5me0ky.jpg


Clearly not the lowest... What am I doing wrong? :eek:
-Lindenkron
 

AceHart

Your Friendly Neighborhood Admin
Reaction score
1,494
Set Unit1 = No unit
Set Unit2 = No unit
Set Distance1 = 99999.0
Set Distance2 = 99999.0
Pick every unit in ...
- If Math-Distance(unit1, (Picked unit)) less than Distance1 then
- - Set Distance2 = Distance1
- - Set Distance1 = Math-Distance(unit1, (Picked unit))
- - Set Unit2 = Unit1
- - Set Unit1 = (Picked unit)
- Else if Math-Distance(unit2, (Picked unit)) less than Distance2 then
- - Set Distance2 = Math-Distance(unit2, (Picked unit))
- - Set Unit2 = (Picked unit)
 

lindenkron

You can change this now in User CP
Reaction score
102
Think I also messed AceHarts reply up... damn this is mighty fucking complicated for my little head.
Trigger:
  • Track3rd
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Track
    • Actions
      • Set DistanceUnit[1] = No unit
      • Set DistanceUnit[2] = No unit
      • Set Distance[1] = 1000000000.00
      • Set Distance[2] = 1000000000.00
      • Set TempGroup = (Units in (Playable map area) matching ((Unit-type of (Matching unit)) Equal to Deer))
      • Unit Group - Pick every unit in TempGroup and do (Actions)
        • Loop - Actions
          • Set TempLocation = (Position of DistanceUnit[1])
          • Set TempLocation2 = (Position of (Picked unit))
          • Game - Display to (All players) for 30.00 seconds the text: (String((Distance between TempLocation and TempLocation2)))
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Distance between TempLocation and TempLocation2) Less than Distance[1]
            • Then - Actions
              • Set Distance[2] = Distance[1]
              • Set Distance[1] = (Distance between TempLocation and TempLocation2)
              • Set DistanceUnit[2] = DistanceUnit[1]
              • Set DistanceUnit[1] = (Picked unit)
            • Else - Actions
              • Set TempLocation = (Position of DistanceUnit[2])
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Distance between TempLocation and TempLocation2) Less than Distance[2]
                • Then - Actions
                  • Set Distance[2] = (Distance between TempLocation and TempLocation2)
                  • Set DistanceUnit[2] = (Picked unit)
                • Else - Actions
          • Custom script: call RemoveLocation (udg_TempLocation2)
          • Custom script: call RemoveLocation (udg_TempLocation)
      • Game - Display to (All players) for 30.00 seconds the text: ------------------2...
      • Game - Display to (All players) for 30.00 seconds the text: (Distance: + (String((Distance between (Position of (Triggering unit)) and (Position of DistanceUnit[1])))))
      • Game - Display to (All players) for 30.00 seconds the text: (Distance: + (String((Distance between (Position of (Triggering unit)) and (Position of DistanceUnit[2])))))
      • Custom script: call DestroyGroup (udg_TempGroup)


None of these numbers are correct what so ever :(
rsscyd.jpg



On the other one I made, I just discovered that the numbers were correct, but it picked number 3,4 instead of 1,2 .. anyone know why?
Correction: Just checked many times, and it picks 1,3 .. instead of 1,2 o_O

thx,
-lindenkron
 
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