[Solved] ¿How can I reduce the number of workers at the beginning of a melee game?

Uncle

Warcraft Moderator
Level 47
Joined
Aug 10, 2018
Messages
4,587
Look into Player Groups and Unit Groups. The Pick Every Player function and Pick Every Unit function can achieve this.

The idea being that you would have a trigger that Picks through each active user (player), figures out their race, and removes the appropriate workers.

Something like:
Pick every player in Users -> If Race of Picked player Equal to Undead -> Set Variable Counter = 0 -> Pick every unit owned by Picked player of type Acolyte -> Set Variable Counter = Counter + 1 -> If Counter <= 2 then Remove Picked unit.

So you would only remove 2 of their 3 acolytes if they were the Undead race. This is because Counter counts up by 1 for each Acolyte and once Counter reaches 3+ it would no longer be <= 2 and thus it would not Remove any more Picked acolytes.

You can then add extra If Then Else statements for the other Races. Then you could set unique numbers for what Counter needs to be for each of them. So if you wanted Human to only get 2 Peasants then you would set it's condition to check if Counter was <= 3.

This trigger (or just these actions) would need to run AFTER the workers have spawned in.
 
Last edited:

Uncle

Warcraft Moderator
Level 47
Joined
Aug 10, 2018
Messages
4,587
Did you search for Unit Groups or Player Groups? I'm sure there's visual triggers for these if you dig around. Forgive me for not creating the triggers myself, it's just that I know it's been done before.
 

Uncle

Warcraft Moderator
Level 47
Joined
Aug 10, 2018
Messages
4,587
  • Melee Initialization
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Melee Game - Use melee time of day (for all players)
      • Melee Game - Limit Heroes to 1 per Hero-type (for all players)
      • Melee Game - Give trained Heroes a Scroll of Town Portal (for all players)
      • Melee Game - Set starting resources (for all players)
      • Melee Game - Remove creeps and critters from used start locations (for all players)
      • Melee Game - Create starting units (for all players)
      • Melee Game - Run melee AI scripts (for computer players)
      • Melee Game - Enforce victory/defeat conditions (for all players)
      • -------- --------
      • -------- Remove unwanted workers: --------
      • Player Group - Pick every player in (All players) and do (Actions)
        • Loop - Actions
          • Set VariableSet WorkerGroup = (Units owned by (Picked player) matching (((Matching unit) is A peon-type unit) Equal to True).)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Number of units in WorkerGroup) Greater than 0
            • Then - Actions
              • Set VariableSet WorkerCounter = 0
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Race of (Picked player)) Equal to Human
                • Then - Actions
                  • Set VariableSet WorkerRemoveAmount = 2
                • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Race of (Picked player)) Equal to Orc
                • Then - Actions
                  • Set VariableSet WorkerRemoveAmount = 2
                • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Race of (Picked player)) Equal to Undead
                • Then - Actions
                  • Set VariableSet WorkerRemoveAmount = 2
                • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Race of (Picked player)) Equal to Night Elf
                • Then - Actions
                  • Set VariableSet WorkerRemoveAmount = 2
                • Else - Actions
              • Unit Group - Pick every unit in WorkerGroup and do (Actions)
                • Loop - Actions
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • WorkerCounter Less than WorkerRemoveAmount
                    • Then - Actions
                      • Set VariableSet WorkerCounter = (WorkerCounter + 1)
                      • Unit - Remove (Picked unit) from the game
                    • Else - Actions
            • Else - Actions
          • Custom script: call DestroyGroup(udg_WorkerGroup)
Variables:
WorkerGroup = Unit Group
WorkerCounter = Integer
WorkerRemoveAmount = Integer

Inside of the If Then Else statements that check the Picked player's Race you'll see the WorkerRemoveAmount variable. This variable defines how many workers will be removed for that particular race:
  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
    • If - Conditions
      • (Race of (Picked player)) Equal to Human
    • Then - Actions
      • Set VariableSet WorkerRemoveAmount = 2
    • Else - Actions
So you can choose to remove a different number based on the race.
 

Attachments

  • Worker Remove Example.w3m
    17.4 KB · Views: 9
Last edited:

Uncle

Warcraft Moderator
Level 47
Joined
Aug 10, 2018
Messages
4,587
One small mistake, you need to move this line up one row so it's a part of the Loop - Actions:
  • Custom script: call DestroyGroup(udg_WorkerGroup)
This way WorkerGroup is created/destroyed once for each player instead of how you have it now (destroyed once at the very end of the trigger).
 
Last edited:
Level 4
Joined
Mar 13, 2021
Messages
21
In this way?
 

Attachments

  • Error.png
    Error.png
    28.7 KB · Views: 15

Uncle

Warcraft Moderator
Level 47
Joined
Aug 10, 2018
Messages
4,587
Nope, you've placed it in the Else - Actions part of that If Then Else statement. The Else - Actions only run if the the Conditions aren't met.

So you're basically doing this:
Pick every player -> If the race of the Picked player is Undead then set WorkerRemoveAmount = 2 ELSE destroy the group.

So you're only destroying the group if the player ISN'T undead.

Look closely at my trigger example above. Minimize the If Then Else statement and notice how the Custom script is BELOW it. I attached a picture with how it should look.
 

Attachments

  • ex.png
    ex.png
    53.1 KB · Views: 21
Last edited:

Uncle

Warcraft Moderator
Level 47
Joined
Aug 10, 2018
Messages
4,587
Looks good to me. All you have to do is look closely when doing a side-by-side comparison to confirm whether or not you got it right.
 
Top