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,495
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,495
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.
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though
  • Ghan Ghan:
    Heard Houston got hit pretty bad by storms last night. Hope all is well with TH.
  • The Helper The Helper:
    Power back on finally - all is good here no damage
    +2
  • V-SNES V-SNES:
    Happy Friday!
    +1
  • The Helper The Helper:
    New recipe is another summer dessert Berry and Peach Cheesecake - https://www.thehelper.net/threads/recipe-berry-and-peach-cheesecake.194169/

      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