Avoid using Wait in that situation

Level 4
Joined
Apr 8, 2021
Messages
31
So i've made these triggers :
  • Acolyte BarrackP0
    • Events
      • Unit - A unit Begins construction
    • Conditions
      • (Unit-type of (Constructing structure)) Equal to Barrack
    • Actions
      • Wait 2 seconds
      • Set VariableSet ClosestUnit = No unit
      • Set VariableSet ShortestDistance = 900000.00
      • Set VariableSet DummyBuilding = (Position of (Constructing structure))
      • Custom script: set bj_wantDestroyGroup = true
      • Unit Group - Pick every unit in (Units within 375.00 of DummyBuilding matching ((((Matching unit) is alive) Equal to Vrai) and ((Unit-type of (Matching unit)) Equal to Acolyte)).) and do (Actions)
        • Loop - Actions
          • Set VariableSet PickedUnit = (Picked unit)
          • Set VariableSet UnitLocation = (Position of PickedUnit)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Current order of (Picked unit)) Equal to (Order(stand down))
              • (Distance between DummyBuilding and UnitLocation) Less than ShortestDistance
            • Then - Actions
              • Set VariableSet ClosestUnit = PickedUnit
              • Set VariableSet ShortestDistance = (Distance between DummyBuilding and UnitLocation)
              • Unit - Order PickedUnit to Human Peasant - Repair (Constructing structure)
              • Custom script: call RemoveLocation(udg_UnitLocation)
            • Else - Actions
      • Custom script: call RemoveLocation( udg_DummyBuilding)
  • Acolyte BarrackP1
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Repair (Human)
      • (Unit-type of (Target unit of ability being cast)) Equal to Barrack
    • Actions
      • Unit - Remove (Target unit of ability being cast) from the game
      • Set VariableSet RemovedBuilding = (Position of (Target unit of ability being cast))
      • Unit - Create 1 dummy acolyte for (Owner of (Casting unit)) at RemovedBuilding facing Default building facing degrees
      • Unit - Order (Last created unit) to build a Barack Dummy at RemovedBuilding
      • Unit - Add a 1 second Generic expiration timer to (Last created unit)
      • Custom script: call RemoveLocation( udg_RemovedBuilding)
  • Acolyte BarrackP2
    • Events
      • Unit - A unit Begins construction
    • Conditions
      • (Unit-type of (Constructing structure)) Equal to Barack Dummy
    • Actions
      • Wait 1.50 seconds
      • Set VariableSet ClosestUnit = No unit
      • Set VariableSet ShortestDistance = 900000.00
      • Set VariableSet DummyBuilding = (Position of (Constructing structure))
      • Custom script: set bj_wantDestroyGroup = true
      • Unit Group - Pick every unit in (Units within 375.00 of DummyBuilding matching ((((Matching unit) is alive) Equal to Vrai) and ((Unit-type of (Matching unit)) Equal to Acolyte)).) and do (Actions)
        • Loop - Actions
          • Set VariableSet PickedUnit = (Picked unit)
          • Set VariableSet UnitLocation = (Position of PickedUnit)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Current order of (Picked unit)) Equal to (Order(stand down))
              • (Distance between DummyBuilding and UnitLocation) Less than ShortestDistance
            • Then - Actions
              • Set VariableSet ClosestUnit = PickedUnit
              • Set VariableSet ShortestDistance = (Distance between DummyBuilding and UnitLocation)
              • Unit - Order PickedUnit to Human Peasant - Repair (Constructing structure)
              • Custom script: call RemoveLocation(udg_UnitLocation)
            • Else - Actions
      • Custom script: call RemoveLocation( udg_DummyBuilding)
The thing is that i know that you should avoid using wait commands, so i tried doing this instead :

  • Acolyte BarrackP0
    • Events
      • Unit - A unit Begins construction
    • Conditions
      • (Unit-type of (Constructing structure)) Equal to Barrack
    • Actions
      • Set VariableSet CR = 1

  • Acolyte BarrackP05
    • Events
      • Time - Every 1.50 seconds of game time
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • CR Equal to 1
        • Then - Actions
          • Set VariableSet ClosestUnit = No unit
          • Set VariableSet ShortestDistance = 900000.00
          • Set VariableSet DummyBuilding = (Position of (Constructing structure))
          • Custom script: set bj_wantDestroyGroup = true
          • Unit Group - Pick every unit in (Units within 375.00 of DummyBuilding matching ((((Matching unit) is alive) Equal to Vrai) and ((Unit-type of (Matching unit)) Equal to Acolyte)).) and do (Actions)
            • Loop - Actions
              • Set VariableSet PickedUnit = (Picked unit)
              • Set VariableSet UnitLocation = (Position of PickedUnit)
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Current order of (Picked unit)) Equal to (Order(stand down))
                  • (Distance between DummyBuilding and UnitLocation) Less than ShortestDistance
                • Then - Actions
                  • Set VariableSet ClosestUnit = PickedUnit
                  • Set VariableSet ShortestDistance = (Distance between DummyBuilding and UnitLocation)
                  • Unit - Order PickedUnit to Human Peasant - Repair (Constructing structure)
                  • Custom script: call RemoveLocation(udg_UnitLocation)
                • Else - Actions
          • Custom script: call RemoveLocation( udg_DummyBuilding)
          • Set VariableSet CR = 0
        • Else - Actions

  • Acolyte BarrackP1
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Repair (Human)
      • (Unit-type of (Target unit of ability being cast)) Equal to Barrack
    • Actions
      • Unit - Remove (Target unit of ability being cast) from the game
      • Set VariableSet RemovedBuilding = (Position of (Target unit of ability being cast))
      • Unit - Create 1 dummy acolyte for (Owner of (Casting unit)) at RemovedBuilding facing Default building facing degrees
      • Unit - Order (Last created unit) to build a Barack Dummy at RemovedBuilding
      • Unit - Add a 1 second Generic expiration timer to (Last created unit)
      • Custom script: call RemoveLocation( udg_RemovedBuilding)

  • Acolyte BarrackP2
    • Events
      • Unit - A unit Begins construction
    • Conditions
      • (Unit-type of (Constructing structure)) Equal to Barack Dummy
    • Actions
      • Set VariableSet CDR = 1

  • Acolyte BarrackP25
    • Events
      • Time - Every 1.50 seconds of game time
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • CDR Equal to 1
        • Then - Actions
          • Set VariableSet ClosestUnit = No unit
          • Set VariableSet ShortestDistance = 900000.00
          • Set VariableSet DummyBuilding = (Position of (Constructing structure))
          • Custom script: set bj_wantDestroyGroup = true
          • Unit Group - Pick every unit in (Units within 375.00 of DummyBuilding matching ((((Matching unit) is alive) Equal to Vrai) and ((Unit-type of (Matching unit)) Equal to Acolyte)).) and do (Actions)
            • Loop - Actions
              • Set VariableSet PickedUnit = (Picked unit)
              • Set VariableSet UnitLocation = (Position of PickedUnit)
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Current order of (Picked unit)) Equal to (Order(stand down))
                  • (Distance between DummyBuilding and UnitLocation) Less than ShortestDistance
                • Then - Actions
                  • Set VariableSet ClosestUnit = PickedUnit
                  • Set VariableSet ShortestDistance = (Distance between DummyBuilding and UnitLocation)
                  • Unit - Order PickedUnit to Human Peasant - Repair (Constructing structure)
                  • Custom script: call RemoveLocation(udg_UnitLocation)
                • Else - Actions
          • Custom script: call RemoveLocation( udg_DummyBuilding)
          • Set VariableSet CDR = 0
        • Else - Actions
But it doesn't work if i do it like this, what did i do wrong please ?
 
Last edited:

Uncle

Warcraft Moderator
Level 73
Joined
Aug 10, 2018
Messages
7,866
Always use (Triggering unit) when you can, it will work properly with Waits.
I don't have time to comment on your issue but I may edit this or post later when I get a chance (if nobody else helps).
 
Level 4
Joined
Apr 8, 2021
Messages
31
Oh right ! i saw what i did wrong thanks uncle, i didn't saw that i still used "DummyBuilding = (Position of (Constructing structure))" if that structure isn't even in that one trigger, same for "Order PickedUnit to Human Peasant - Repair (Constructing structure)" ! Ty ! i've juste made a Variable in "BarrackP0" and "BarrackP2" that store the structure being built and now it work, thanks ! i've been on this for days lol

Edit: I'm going to edit my post later when i will have time, since it work only most of the time not always

Edit: So at the end of the day this is what i've done :

  • Acolyte BarrackP0
    • Events
      • Unit - A unit Begins construction
    • Conditions
      • (Unit-type of (Triggering unit)) Equal to Barrack
    • Actions
      • Set VariableSet CR = 1
      • Set VariableSet IndexCR = (Triggering unit)

  • Acolyte BarrackP05
    • Events
      • Time - Every 1.50 seconds of game time
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • CR Equal to 1
        • Then - Actions
          • Set VariableSet ClosestUnit = No unit
          • Set VariableSet ShortestDistance = 900000.00
          • Set VariableSet DummyBuilding = (Position of IndexCR)
          • Custom script: set bj_wantDestroyGroup = true
          • Unit Group - Pick every unit in (Units within 375.00 of DummyBuilding matching ((((Matching unit) is alive) Equal to Vrai) and ((Unit-type of (Matching unit)) Equal to Acolyte)).) and do (Actions)
            • Loop - Actions
              • Set VariableSet PickedUnit = (Picked unit)
              • Set VariableSet UnitLocation = (Position of PickedUnit)
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Distance between DummyBuilding and UnitLocation) Less than ShortestDistance
                • Then - Actions
                  • Set VariableSet ClosestUnit = PickedUnit
                  • Set VariableSet ShortestDistance = (Distance between DummyBuilding and UnitLocation)
                  • Unit - Order PickedUnit to Human Peasant - Repair IndexCR
                  • Custom script: call RemoveLocation(udg_UnitLocation)
                • Else - Actions
          • Custom script: call RemoveLocation( udg_DummyBuilding)
          • Set VariableSet CR = 0
        • Else - Actions

  • Acolyte BarrackP1
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Réparation (Humain)P
      • (Unit-type of (Target unit of ability being cast)) Equal to Barrack
    • Actions
      • Unit - Remove (Target unit of ability being cast) from the game
      • Set VariableSet RemovedBuilding = (Position of (Target unit of ability being cast))
      • Unit - Create 1 dummy acolyte for (Owner of (Casting unit)) at RemovedBuilding facing Default building facing degrees
      • Unit - Order (Last created unit) to build a Barack Dummy at RemovedBuilding
      • Unit - Add a 1.25 second Generic expiration timer to (Last created unit)
      • Custom script: call RemoveLocation( udg_RemovedBuilding)

  • Acolyte BarrackP2
    • Events
      • Unit - A unit Begins construction
    • Conditions
      • (Unit-type of (Triggering unit)) Equal to Barack Dummy
    • Actions
      • Set VariableSet CDR = 1
      • Set VariableSet IndexCDR = (Triggering unit)

  • Acolyte BarrackP25
    • Events
      • Time - Every 1.50 seconds of game time
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • CDR Equal to 1
        • Then - Actions
          • Set VariableSet ClosestUnit = No unit
          • Set VariableSet ShortestDistance = 900000.00
          • Set VariableSet DummyBuilding = (Position of IndexCDR)
          • Custom script: set bj_wantDestroyGroup = true
          • Unit Group - Pick every unit in (Units within 375.00 of DummyBuilding matching ((((Matching unit) is alive) Equal to Vrai) and ((Unit-type of (Matching unit)) Equal to Acolyte)).) and do (Actions)
            • Loop - Actions
              • Set VariableSet PickedUnit = (Picked unit)
              • Set VariableSet UnitLocation = (Position of PickedUnit)
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Current order of (Picked unit)) Equal to (Order(stand down))
                  • (Distance between DummyBuilding and UnitLocation) Less than ShortestDistance
                • Then - Actions
                  • Set VariableSet ClosestUnit = PickedUnit
                  • Set VariableSet ShortestDistance = (Distance between DummyBuilding and UnitLocation)
                  • Unit - Order PickedUnit to Human Peasant - Repair IndexCDR
                  • Custom script: call RemoveLocation(udg_UnitLocation)
                • Else - Actions
          • Custom script: call RemoveLocation( udg_DummyBuilding)
          • Set VariableSet CDR = 0
        • Else - Actions
The problem with that is that some of the time the "BarrackP05"&"BarrackP25" don't work, is that because it only check every 1,5 seconds? and because of that "BarrackP05"&"BarrackP25" never get to go?

Edit: Putting 1,5 sec check lower or higher didn't seem to change much i think?
Edit: Found out why, if i build multiple building "CDR" "CR" can still be 0 and so the trigger doesn't go off, what can i do?
Edit: Maybe i can solve it with arrays ? but i don't know how they work, simply making "CR" & "CDR" become "CR[0]" & "CDR[0]" arrays but nothing changed.
I think i may bump the thread since i'm not finding any solutions, sorry in advance for that.
 
Last edited:
Level 4
Joined
Apr 8, 2021
Messages
31
I didn't look at your trigger. But I just set everything to variables and use timers and break up each Wait into a different trigger, or try to think of a way to avoid the Wait.
Yeah that's what i tried to do :D
Angedayle:

Edit:
Putting 1,5 sec check lower or higher didn't seem to change much i think?
Edit: Found out why, if i build multiple building "CDR" "CR" can still be 0 and so the trigger doesn't go off, what can i do?
Edit: Maybe i can solve it with arrays ? but i don't know how they work, simply making "CR" & "CDR" become "CR[0]" & "CDR[0]" arrays but nothing changed.
I think i may bump the thread since i'm not finding any solutions, sorry in advance for that.
 
Top