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

[Trigger] How do 'Pick All Units in Group' work?

Status
Not open for further replies.
Level 12
Joined
May 9, 2009
Messages
735
Hello, I am trying to figure out how exactly the PickAllUnits in a group line in GUI works... The trigger I am trying to make has multiple of these inside each other. According to my brain it should work but for some reason it doesn't. I really want to understand where the issue is because I just can't seem to get it... It looks like one of the If/Then/Else line doesn't run the way it should.

What I am trying to make: a new system where Siege Engines require to be pushed. Siege engines can be used as long as there's a unit nearby (that's not dead, or is a building, or is a horseman) but if that unit goes away it should turn passive. If an enemy comes near than there should be a chance for the siege engine to become 'contested' (pick random unit around it) and if it is 'contested' it becomes passive. Passive engines should be given to any unit who comes near as long as two hostile units aren't next to each other... so if an enemy unit and your unit are both near at the same time (after the engine is contested for example) it should remain passive until the conflict is resolved.

  • System 1 Copy
    • Events
      • Time - Every 1.00 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in SiegeUnits and do (Actions)
        • Loop - Actions
          • Set SiegeUN = (Picked unit)
          • Set AAAPositionSiege = (Position of SiegeUN)
          • Set AnyUnitsAtAll = (Units within 500.00 of AAAPositionSiege)
          • Unit Group - Pick every unit in AnyUnitsAtAll and do (Actions)
            • Loop - Actions
              • Set PusherUN = (Picked unit)
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (PusherUN is in SiegeUnits) Equal to False
                  • (Owner of PusherUN) Not equal to Neutral Passive
                  • (Owner of PusherUN) Not equal to Neutral Hostile
                  • (PusherUN is alive) Equal to True
                  • ((Unit-type of PusherUN) is A structure) Equal to False
                  • (PusherUN is in ALLcavalryGROUP) Equal to False
                • Then - Actions
                  • Unit Group - Add PusherUN to AAAGroupUnitsAroundSiege
                • Else - Actions
              • Unit Group - Pick every unit in AAAGroupUnitsAroundSiege and do (Actions)
                • Loop - Actions
                  • Set tempU = (Picked unit)
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • (Owner of SiegeUN) Equal to Neutral Passive
                    • Then - Actions
                      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                        • If - Conditions
                          • Or - Any (Conditions) are true
                            • Conditions
                              • (Owner of tempU) Equal to (Owner of tempU)
                              • (tempU belongs to an ally of (Owner of tempU)) Equal to True
                        • Then - Actions
                          • Unit - Change ownership of SiegeUN to (Owner of tempU) and Change color
                        • Else - Actions
                    • Else - Actions
                      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                        • If - Conditions
                          • Or - Any (Conditions) are true
                            • Conditions
                              • (Owner of tempU) Equal to (Owner of tempU)
                              • (tempU belongs to an ally of (Owner of tempU)) Equal to True
                        • Then - Actions
                        • Else - Actions
                          • Unit Group - Pick every unit in (Random 1 units from AAAGroupUnitsAroundSiege) and do (Actions)
                            • Loop - Actions
                              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                                • If - Conditions
                                  • ((Picked unit) belongs to an enemy of (Owner of SiegeUN)) Equal to True
                                • Then - Actions
                                  • Unit - Change ownership of SiegeUN to Neutral Passive and Change color
                                • Else - Actions
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • Or - Any (Conditions) are true
                        • Conditions
                          • (Owner of tempU) Equal to (Owner of SiegeUN)
                          • (tempU belongs to an ally of (Owner of SiegeUN)) Equal to True
                    • Then - Actions
                      • Set tempCOUNT = (tempCOUNT + 1)
                    • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • tempCOUNT Equal to 0
            • Then - Actions
              • Unit - Change ownership of SiegeUN to Neutral Passive and Change color
            • Else - Actions
      • Set moonshrine = 0
      • Custom script: call RemoveLocation(udg_AAAPositionSiege)
      • Custom script: call DestroyGroup (udg_AnyUnitsAtAll)
      • Custom script: call DestroyGroup (udg_AAAGroupUnitsAroundSiege)
 

Wrda

Spell Reviewer
Level 26
Joined
Nov 18, 2012
Messages
1,890
Which If/Then/else line doesn't work as expected?
You add PusherUN to AAAGroupUnitsAroundSiege, and then pick every unit in that group. It will repeat all actions to all units expect the last several times.
You should use the pick every unit in AAAGroupUnitsAroundSiege after AnyUnitsAtAll's all actions have been done.
 
You destroy group AAAGroupUnitsAroundSiege, but none of your actions recreate it. Therefore it can't contain units after the first time this trigger runs.
But destroying it would be wrong at all. Clear(remove all units from it) it as 1. action in SiegeUnits.

AAAGroupUnitsAroundSiege is a (Level 3) sub Loop of AnyUnitsAtAll UnitGroup-Loop, which looks wrong. It should be an (Level 2) sub group of SiegeUnits.
Better would be to do directly the counting when finding an valid pusher then you can skip the " AAAGroupUnitsAroundSiege" Loop.
And use a simple if then else to set the new owner.​

dat looks a bit redundant "(Owner of tempU) Equal to (Owner of tempU)", you proably want to compare to SiegeUn.

Edit: When using an Pick Units in Range/Rect/Player.. action in GUI it creates a new group object. This ones you need to destroy, cause they are temp groups only valid for the current moment.
 
Last edited:
Level 12
Joined
May 9, 2009
Messages
735
"(Owner of tempU) Equal to (Owner of tempU)" was my failed attempt at trying to make the condition "All units in this grouped are allied to each"... the thing should trigger when there is 1 non-allied enemy in the midst. Also I don't want to catapults to be capturable if there's 1 enemy nearby - all must be allied to secure it from neutral passive.

Thanks for the group deleting tip too turns out it was what was causing my AAAGroupUnitsAroundSiege not too run since it was deleted... and here I thought I was missing something a little bit less obvious.

Thanks for the help guys. Yeah the idea kinda fell flat on its face so I was forced to think... I thought of a method of identifying if the units around the neatral passive catapult are hostile to each other by selecting a random unit and seeing if the total amount of units around the catapult is equal to the amount of units around the catapult that are allies of the owner of the random unit. It was a bit buggy (catapults were randomly stolen every 5 seconds or so when contested directly from an enemy) so I was forced to add a neutral passive ownership condition too.

  • System 1 Copy
    • Events
      • Time - Every 1.00 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in SiegeUnits and do (Actions)
        • Loop - Actions
          • Set SiegeUN = (Picked unit)
          • Set AAAPositionSiege = (Position of SiegeUN)
          • Set AnyUnitsAtAll = (Units within 500.00 of AAAPositionSiege)
          • Unit Group - Pick every unit in AnyUnitsAtAll and do (Actions)
            • Loop - Actions
              • Set PusherUN = (Picked unit)
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (PusherUN is in SiegeUnits) Equal to False
                  • (Owner of PusherUN) Not equal to Neutral Passive
                  • (Owner of PusherUN) Not equal to Neutral Hostile
                  • (PusherUN is alive) Equal to True
                  • ((Unit-type of PusherUN) is A structure) Equal to False
                  • (PusherUN is in ALLcavalryGROUP) Equal to False
                • Then - Actions
                  • Unit Group - Add PusherUN to AAAGroupUnitsAroundSiege
                • Else - Actions
          • Unit Group - Pick every unit in (Random 1 units from AAAGroupUnitsAroundSiege) and do (Actions)
            • Loop - Actions
              • Set SiegeNew = (Picked unit)
              • Set SiegePlayer = (Owner of SiegeNew)
          • Unit Group - Pick every unit in AAAGroupUnitsAroundSiege and do (Actions)
            • Loop - Actions
              • Set tempCOUNTfull = (tempCOUNTfull + 1)
              • Set tempU = (Picked unit)
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • Or - Any (Conditions) are true
                    • Conditions
                      • (Owner of tempU) Equal to SiegePlayer
                      • (tempU belongs to an ally of SiegePlayer) Equal to True
                • Then - Actions
                  • Set tempCOUNTally = (tempCOUNTally + 1)
                • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (tempU belongs to an enemy of (Owner of SiegeUN)) Equal to True
                • Then - Actions
                  • Unit Group - Pick every unit in (Random 1 units from AAAGroupUnitsAroundSiege) and do (Actions)
                    • Loop - Actions
                      • Set Stealer = (Picked unit)
                      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                        • If - Conditions
                          • (Stealer belongs to an enemy of (Owner of SiegeUN)) Equal to True
                        • Then - Actions
                          • Unit - Change ownership of SiegeUN to Neutral Passive and Change color
                        • Else - Actions
                • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • Or - Any (Conditions) are true
                    • Conditions
                      • (Owner of tempU) Equal to (Owner of SiegeUN)
                      • (tempU belongs to an ally of (Owner of SiegeUN)) Equal to True
                • Then - Actions
                  • Set tempCOUNT = (tempCOUNT + 1)
                • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • tempCOUNT Equal to 0
            • Then - Actions
              • Unit - Change ownership of SiegeUN to Neutral Passive and Change color
            • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • tempCOUNTally Equal to tempCOUNTfull
              • (Owner of SiegeUN) Equal to Neutral Passive
            • Then - Actions
              • Unit - Change ownership of SiegeUN to SiegePlayer and Change color
            • Else - Actions
      • Set tempCOUNT = 0
      • Set tempCOUNTfull = 0
      • Set tempCOUNTally = 0
      • Unit Group - Remove all units from AAAGroupUnitsAroundSiege
      • Custom script: call RemoveLocation(udg_AAAPositionSiege)
      • Custom script: call DestroyGroup (udg_AnyUnitsAtAll)
 
(catapults were randomly stolen every 5 seconds or so when contested directly from an enemy)
Could be cause of the use of "1 random Unit of group" which is no valid option for reaching the wanted result.

Personaly I would solve the problem as I now mention below:
Use a different behaviour based on beeing currently contested or owned. "if then else"

In the owned situation you care about: alliance between siegeUnit and units around.
In the contest situation you care about: the amount of allied forces contesting for the siegeUnit, by having valid pusher-Units around the siegeUnit.
  1. Owned: Are there only allies nearby and is there atleast 1?
    • yes -> nothing happens.
    • no -> becomes contested (passive)
  2. Contested: Only units of one allied force nearby?
    • yes -> give ownership to one player of that allied force.
    • no -> nothing stay passive
 
Level 12
Joined
May 9, 2009
Messages
735
Could be cause of the use of "1 random Unit of group" which is no valid option for reaching the wanted result.

Personaly I would solve the problem as I now mention below:
Use a different behaviour based on beeing currently contested or owned. "if then else"

In the owned situation you care about: alliance between siegeUnit and units around.
In the contest situation you care about: the amount of allied forces contesting for the siegeUnit, by having valid pusher-Units around the siegeUnit.
  1. Owned: Are there only allies nearby and is there atleast 1?
    • yes -> nothing happens.
    • no -> becomes contested (passive)
  2. Contested: Only units of one allied force nearby?
    • yes -> give ownership to one player of that allied force.
    • no -> nothing stay passive
You are right. I did a larger test today and discovered something terribly wrong. It appeared all units around the siege engines (all the siege engines) were compared or something... It was madness.

"Only units of one allied force nearby?" I don't know how to put that in GUI though... I can't seem to think of a way.
 
Last edited:
"Only units of one allied force nearby?" I don't know how to put that in GUI though... I can't seem to think of a way.
You could loop all nearby units and Test alliance state of current picked unit to owner of previous picked Unit. (First unit needs to be handled different but that should work).
If owner of last Picked Unit and current Picked Unit are enemies set a boolean (true).
Then after the group loop if the boolean is false change ownership .
 
Status
Not open for further replies.
Top