[Trigger] Unit Group - Move randomly with specific points

Level 4
Joined
Sep 27, 2018
Messages
61
Hello, I have a question for random movement, I have a unit group for example 5 Spellbreak in the group and I want them to move 4 points each one, also order 2 of them move one point for dialog. So I have the trigger:
  • OrdAttaDestructible
    • Events
      • Unit - A unit comes within 256.00 of Paladín 0008 <gen>
    • Conditions
      • (Owner of (Entering unit)) Equal to Player 1 (Red)
    • Actions
      • Trigger - Turn off (This trigger)
      • Set VariableSet Victoriosos = (Units owned by Player 2 (Blue) of type Rompehechizos)
      • Unit Group - Pick every unit in Victoriosos and do (Actions)
        • Loop - Actions
          • AI - Ignore (Picked unit)'s guard position
      • Game - Display to (All players) the text: (String((Number of units in Victoriosos)))
      • For each (Integer A) from 1 to (Number of units in Victoriosos), do (Actions)
        • Loop - Actions
          • For each (Integer B) from 1 to 4, do (Actions)
            • Loop - Actions
              • Unit - Order (Random unit from (Random (Integer A) units from Victoriosos)) to Move To Guardias[(Integer B)]
They move to the points randomly between 4 points:

  • Inicio
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Set VariableSet Guardias[1] = (Center of Region 018 <gen>)
      • Set VariableSet Guardias[2] = (Center of Región 001 <gen>)
      • Set VariableSet Guardias[3] = (Center of Región 000 <gen>)
      • Set VariableSet Guardias[4] = (Random point in Rescatables <gen>)
However each time I reset game, they go randomly but I can't specify the 2 specific units to move the exactly point. So, there is a way to move the 2 units for dialog in that point?
 

Uncle

Warcraft Moderator
Level 73
Joined
Aug 10, 2018
Messages
7,866
You could do it like this:
  • OrdAttaDestructible
    • Events
      • Unit - A unit comes within 256.00 of Paladín 0008 <gen>
    • Conditions
      • (Owner of (Entering unit)) Equal to Player 1 (Red)
    • Actions
      • Trigger - Turn off (This trigger)
      • Set VariableSet Victoriosos = (Units owned by Player 2 (Blue) of type Rompehechizos)
      • Set VariableSet X = 0
      • Unit Group - Pick every unit in Victoriosos and do (Actions)
        • Loop - Actions
          • Set VariableSet X = (Min((X + 1), 4))
          • AI - Ignore (Picked unit)'s guard position
          • Unit - Order (Picked unit) to Move To Guardias[X]
1741292522035.png


That trigger will order the last two Units in the Unit Group to Move to Guardias[4]. The other three Units will move to Guardias[1 -> 3].

Edit: Note that this will only work if you have exactly 5 Spellbreakers in Victoriosos. For example, if you had 6 breakers then the last 3 would move to Guardias[4]. If you want it to be more flexible then you can use two Unit Groups and manually Add the "special" units to the second group. Something like this:
  • OrdAttaDestructible
    • Events
      • Unit - A unit comes within 256.00 of Paladín 0008 <gen>
    • Conditions
      • (Owner of (Entering unit)) Equal to Player 1 (Red)
    • Actions
      • Trigger - Turn off (This trigger)
      • Set VariableSet Victoriosos = (Units owned by Player 2 (Blue) of type Rompehechizos)
      • Unit Group - Remove all units from Victoriosos_2
      • Unit Group - Add Spellbreaker <0001> to Victoriosos_2
      • Unit Group - Add Spellbreaker <0002> to Victoriosos_2
      • Unit Group - Add Spellbreaker <0003> to Victoriosos_2
      • Unit Group - Pick every unit in Victoriosos_2 and do (Actions)
        • Loop - Actions
          • Unit Group - Remove (Picked unit) from Victoriosos
          • AI - Ignore (Picked unit)'s guard position
          • Unit - Order (Picked unit) to Move To Guardias[4]
      • Set VariableSet X = 0
      • Unit Group - Pick every unit in Victoriosos and do (Actions)
        • Loop - Actions
          • Set VariableSet X = (X + 1)
          • AI - Ignore (Picked unit)'s guard position
          • Unit - Order (Picked unit) to Move To Guardias[X]
          • If (X Equal to 3) Then (Set VariableSet X = 0) Else (do nothing)
^ This makes the "non-special" Units move to Guardias[1 -> 3] in a pattern, ensuring that all three Points are used. The "special" Units always move to Guardias[4].
 
Last edited:
Level 4
Joined
Sep 27, 2018
Messages
61
You could do it like this:
  • OrdAttaDestructible
    • Events
      • Unit - A unit comes within 256.00 of Paladín 0008 <gen>
    • Conditions
      • (Owner of (Entering unit)) Equal to Player 1 (Red)
    • Actions
      • Trigger - Turn off (This trigger)
      • Set VariableSet Victoriosos = (Units owned by Player 2 (Blue) of type Rompehechizos)
      • Set VariableSet X = 0
      • Unit Group - Pick every unit in Victoriosos and do (Actions)
        • Loop - Actions
          • AI - Ignore (Picked unit)'s guard position
          • Set VariableSet X = (Min((X + 1), 4))
          • Unit - Order (Picked unit) to Move To Guardias[X]
View attachment 516490

That trigger will order the last two Units in the Unit Group to Move to Guardias[4]. The other three Units will move to Guardias[1 -> 3].
Nice. Thank u!
 
Top