• 🏆 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!

"Detect if unit is coming to another unit" trigger

Status
Not open for further replies.
Level 5
Joined
May 26, 2012
Messages
76
Hello!
I am trying to make a simple dialogue system.
I want a dialogiue to start when:

1)UnitA is given an order to go to UnitB (Right Click)
2)UnitA should be close to UnitB (Distance <=256).


Here's what I come up with so far:

UniversalDialogueStarter
Events
Unit - A unit owned by Player 1 (Red) Is issued an order targeting an object
Conditions
(Ordered unit) Equal to aaPlayerRef
Or - Any (Conditions) are true
Conditions
(Target unit of issued order) Equal to BuddyRef
(Target unit of issued order) Equal to MorrisRef
Actions
Game - Display to (All players) the text: TEST01-OBJECT
Game - Display to (All players) the text: (Name of (Target unit of issued order))

I cannot find a condition which compares the distance between 2 units.
I also tried a "Unit within range" Event but it only allows me to choose between Pre-placed units and not my references.
Am I missing something obvious?
 
Level 12
Joined
Jan 30, 2020
Messages
875
Hello !
Just use Event Type -> Unit, Unit Within Range, then A unit comes within 256.0 of UnitB

Hope this helps.
 
Level 5
Joined
May 26, 2012
Messages
76
Well I figured it out:
That condition function to return distance is located under "Real comparison" condition type.

Code:
UniversalDialogueStarter
    Events
        Unit - A unit owned by Player 1 (Red) Is issued an order targeting an object
    Conditions
        (Distance between (Position of (Target unit of issued order)) and (Position of aaPlayerRef)) Less than or equal to 256.00
        (Ordered unit) Equal to aaPlayerRef
        Or - Any (Conditions) are true
            Conditions
                (Target unit of issued order) Equal to BuddyRef
                (Target unit of issued order) Equal to MorrisRef
    Actions
        Set VariableSet zTempDialogueTargetRef = (Target unit of issued order)
        Game - Display to (All players) the text: (Name of (Target unit of issued order))
 
Level 12
Joined
Jan 30, 2020
Messages
875
Oh ok sorry I misunderstood what you wanted.

It seems you only wanted to initiate the dialog when the unit was close enough while being given the order.

My bad.
Happy you figured it out though, good luck :)
 
Level 28
Joined
Feb 18, 2014
Messages
3,579
Well I figured it out:
That condition function to return distance is located under "Real comparison" condition type.

Code:
UniversalDialogueStarter
    Events
        Unit - A unit owned by Player 1 (Red) Is issued an order targeting an object
    Conditions
        (Distance between (Position of (Target unit of issued order)) and (Position of aaPlayerRef)) Less than or equal to 256.00
        (Ordered unit) Equal to aaPlayerRef
        Or - Any (Conditions) are true
            Conditions
                (Target unit of issued order) Equal to BuddyRef
                (Target unit of issued order) Equal to MorrisRef
    Actions
        Set VariableSet zTempDialogueTargetRef = (Target unit of issued order)
        Game - Display to (All players) the text: (Name of (Target unit of issued order))
You may want to store the two point in variables as they may cause leaks.
  • Trigger
    • Events
      • Unit - A unit owned by Player 1 (Red) Is issued an order targeting an object
    • Conditions
      • (Ordered unit) Equal to aaPlayerRef
      • Or - Any (Conditions) are true
        • Conditions
          • (Target unit of issued order) Equal to BuddyRef
          • (Target unit of issued order) Equal to MorrisRef
    • Actions
      • Set Point01 = (Position of (Target unit of issued order))
      • Set Point02 = (Position of aaPlayerRef))
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Distance between Point01 and Point02) Less than or equal to 256.00
        • Then - Actions
          • Set VariableSet zTempDialogueTargetRef = (Target unit of issued order)
          • Game - Display to (All players) the text: (Name of (Target unit of issued order))
        • Else - Actions
      • Custom script: call RemoveLocation (udg_Point01)
      • Custom script: call RemoveLocation (udg_Point02)
 
Level 5
Joined
May 26, 2012
Messages
76
You may want to store the two point in variables as they may cause leaks.
  • Trigger
    • Events
      • Unit - A unit owned by Player 1 (Red) Is issued an order targeting an object
    • Conditions
      • (Ordered unit) Equal to aaPlayerRef
      • Or - Any (Conditions) are true
        • Conditions
          • (Target unit of issued order) Equal to BuddyRef
          • (Target unit of issued order) Equal to MorrisRef
    • Actions
      • Set Point01 = (Position of (Target unit of issued order))
      • Set Point02 = (Position of aaPlayerRef))
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Distance between Point01 and Point02) Less than or equal to 256.00
        • Then - Actions
          • Set VariableSet zTempDialogueTargetRef = (Target unit of issued order)
          • Game - Display to (All players) the text: (Name of (Target unit of issued order))
        • Else - Actions
      • Custom script: call RemoveLocation (udg_Point01)
      • Custom script: call RemoveLocation (udg_Point02)
Thank you!!
Do you know any good articles about what other variables may leak?
 
Status
Not open for further replies.
Top