Adding only 1 friendly unit of each type from the map in a group

Status
Not open for further replies.
Level 20
Joined
Feb 23, 2014
Messages
1,265
Set StartGroup to whatever you want (e.g. friendly units) and then run this trigger:

  • UnitSelectionTrigger
    • Events
    • Conditions
    • Actions
      • Set SelectedUnit = (Random unit from StartGroup)
      • Unit Group - Add SelectedUnit to EndGroup
      • Set UnitType = (Unit-type of SelectedUnit)
      • Unit Group - Pick every unit in StartGroup and do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Unit-type of (Picked unit)) Equal to UnitType
            • Then - Actions
              • Unit Group - Remove (Picked unit) from StartGroup
            • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Number of units in StartGroup) Not equal to 0
        • Then - Actions
          • Trigger - Run (This trigger) (checking conditions)
        • Else - Actions
          • Custom script: call DestroyGroup(udg_StartGroup)

It should leave exactly 1 of each unit type from StartGroup inside EndGroup. At least it did when I tested it :)
 
Last edited:
Level 27
Joined
Dec 3, 2018
Messages
896
a4.png

Why doesn t this work?
 
Level 20
Joined
Feb 23, 2014
Messages
1,265
First of all: How To Post Your Trigger

As for the actual trigger:

1. What I posted above should be a separate trigger, because it's meant to run itself over and over again until the selection is completed. This means that everything else that you put in that trigger (such as creating units) would also be run multiple times, which you probably don't want.

2. You picked the wrong unit group in the block where you're comparing unit types - you should pick all units in NeFarstriderGroup, not FarstriderGroup.

3. As for picking every unit in FarstriderGroup, I'd put it in the second trigger below removing the NeFarstriderGroup (inside the If/Then/Else block).

4. You shouldn't destroy the unit group inside the Pick All Units in Unit Group loop. Also, be warned that if you're going to destroy FarstriderGroup, you're not going to have an empty group to transfer units to, i.e. this set of triggers will only work once. If you want it to work multiple times, I'd recommend simply removing all units from FarstriderGroup instead of destroying the group.

5. You're leaking points when creating units.

It's possible I missed something, so do try to fix the above first, test it and tell me if it works - if not, I'll take another look at it.
 
Last edited:
Level 27
Joined
Dec 3, 2018
Messages
896
  • OuoetT1
    • Events
      • Time - Every 1.00 seconds of game time
    • Conditions
    • Actions
      • Set VariableSet NeFarstriderGroupT1 = (Units owned by Player 9 (Gray) matching (((Matching unit) is A structure) Equal to False).)
      • Set VariableSet FarstriderUnitT1 = (Random unit from NeFarstriderGroupT1)
      • Unit Group - Add FarstriderUnitT1 to FarstriderGroupT1
      • Set VariableSet FarstriderUnitTypeT1 = (Unit-type of FarstriderUnitT1)
      • Unit Group - Pick every unit in NeFarstriderGroupT1 and do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Unit-type of (Picked unit)) Equal to FarstriderUnitTypeT1
            • Then - Actions
              • Unit Group - Remove (Picked unit) from NeFarstriderGroupT1.
            • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Number of units in NeFarstriderGroupT1) Not equal to 0
        • Then - Actions
          • Trigger - Run (This trigger) (checking conditions)
        • Else - Actions
          • Custom script: call DestroyGroup(udg_NeFarstriderGroupT1)
 
Last edited:
Level 20
Joined
Feb 23, 2014
Messages
1,265
Okay, so... I guess I didn't explain the whole idea properly - you should have 2 separate triggers:

TRIGGER 1
  • Has an event
  • Does all things you want to do BEFORE selecting units
  • You set your entry group (NeFarstriderGroupT1) here
  • At the end of this trigger, you run Trigger 2 (ONCE!)

TRIGGER 2:
  • Doesn't have an event, it's started by Trigger 1
  • You absolutely do NOT set the entry group here
  • You had the content on this trigger almost right:

  • OuoetT1
    • Events
    • Conditions
    • Actions
      • Set VariableSet FarstriderUnitT1 = (Random unit from NeFarstriderGroupT1)
      • Unit Group - Add FarstriderUnitT1 to FarstriderGroupT1
      • Set VariableSet FarstriderUnitTypeT1 = (Unit-type of FarstriderUnitT1)
      • Unit Group - Pick every unit in NeFarstriderGroupT1 and do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Unit-type of (Picked unit)) Equal to FarstriderUnitTypeT1
            • Then - Actions
              • Unit Group - Remove (Picked unit) from NeFarstriderGroupT1.
            • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Number of units in NeFarstriderGroupT1) Not equal to 0
        • Then - Actions
          • Trigger - Run (This trigger) (checking conditions)
        • Else - Actions
          • Custom script: call DestroyGroup(udg_NeFarstriderGroupT1)
          • IF YOU WANT TO DO ANYTHING WITH SELECTED UNITS (FarstriderGroupT1) YOU CAN PUT IT HERE
 
Last edited:
Status
Not open for further replies.
Top