• 🏆 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!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

Unit comes within range question

Status
Not open for further replies.
Level 17
Joined
Dec 11, 2014
Messages
2,004
  • Untitled Trigger 001
    • Events
      • Unit - A unit comes within 256.00 of Unit1
      • Unit - A unit comes within 256.00 of Unit2
      • Unit - A unit comes within 256.00 of Unit3
    • Conditions
    • Actions
      • Set Tiggering_Unit = (Triggering unit)
      • Set Temp_Point = (Position of Unit1)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Tiggering_Unit is in (Units within 256.00 of Temp_Point)) Equal to True
        • Then - Actions
          • -------- Whatever actions --------
          • Set Temp_Point = (Position of Unit2)
          • Custom script: call RemoveLocation (udg_Temp_Point)
        • Else - Actions
          • Custom script: call RemoveLocation (udg_Temp_Point)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Tiggering_Unit is in (Units within 256.00 of Temp_Point)) Equal to True
            • Then - Actions
              • -------- Whatever actions --------
              • Set Temp_Point = (Position of Peasant Unit3)
            • Else - Actions
              • Custom script: call RemoveLocation (udg_Temp_Point)
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Tiggering_Unit is in (Units within 256.00 of Temp_Point)) Equal to True
                • Then - Actions
                  • -------- Whatever actions --------
                • Else - Actions
      • Custom script: set udg_Triggering_Unit = null
This however might not work when Triggering_Unit Enters The Exact Collide point between Units. This can be Avoided by setting the units far from eachother.
 
If you enumerate the units again after the event fired, just to find the unit triggering it, why even use the event in the first place?

You can just enumerate periodically then and be done with it.

Also remember that "Unit comes within range of Unit" event is:
1) not instant
2) internally works by periodically enumerating all units in range anyway (at a timeout roughly between 0.05 and 0.1 seconds).


Conclusion: Don't use this event. Enumerate periodically.
 
How did you know that?
You can easily measure the delay by instantly moving the unit in range and starting a timer at the same time, then check the remaining timer duration as soon as the event fires.

Also, using this event on many units noticably slows the map down, which is a giveaway for periodic calculations.

I expect it to be a little bit faster than periodic enumeration, simply because it operates at a lower level (not on the JASS layer, but on the native layer), but considering you can not get the entering unit easily, it's not worth using it unless you don't care about the entering unit at all.
 
Level 24
Joined
Aug 1, 2013
Messages
4,657
I think it might be better to create a new trigger for unit1, unit2 and unit3 and store the unit1, unit2 and unit3 on the trigger which fires for those units in a hashtable.
In that case, you can make that new trigger run this trigger and you save the unit in a global variable.

The creation of these triggers has to be done in JASS though.

Also, do you only need this for unit1, unit2 and unit3 or will there be more units?
 
Status
Not open for further replies.
Top