• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

How do I create a trigger when all enemy units die within a region?

Level 2
Joined
Mar 5, 2023
Messages
18
I'm thinking about setting a trigger like when the undead base that I created is destroyed like all units and buildings there and the trigger that I want is to create units that will go to my base on a periodic basis from a starting point. I was also thinking that after I destroyed the undead base, there's gonna be like a transport ship coming from a beach to rebuild the undead base and start over again. How do I make this happen?
 

Uncle

Warcraft Moderator
Level 73
Joined
Aug 10, 2018
Messages
7,866
There's a variable called Unit Group which allows you to store multiple units at a time in one single "place":
  • Events
    • Time - Elapsed game time is 0.00 seconds
  • Conditions
  • Actions
    • Set Variable Undead_Base_Group = (Units in UndeadBaseRegion <gen>)
Here I am using it in combination with a Region to store all of the units inside of the Undead Base.

This Unit Group allows you to interact with ALL of these units in your different triggers, for example:
  • Events
    • Time - Elapsed game time is 5.00 seconds
  • Conditions
  • Actions
    • Unit Group - Pick every unit in Undead_Base_Group and do (Actions)
      • Loop - Actions
        • Unit - Kill (Picked unit)
This example would kill all of the units stored inside of the Undead_Base_Group, but obviously you'll want to do something else with them. (Picked unit) represents each of the units in the group so whatever you do to it will happen to ALL of them.

If new units come into play, for example if a Barracks were to train a Ghoul, you would want to make sure that they get added to the Unit Group as well:
  • Events
    • Unit - A unit Finishes training a unit
  • Conditions
    • ((Trained unit) is in UndeadBaseRegion <gen>) Equal to True
  • Actions
    • Unit Group - Add (Trained unit) to Undead_Base_Group
To know when all of the units in the base have died you will need to manage your Unit Group whenever a unit dies:
  • Events
    • Unit - A unit Dies
  • Conditions
    • ((Dying unit) is in Undead_Base_Group) Equal to True
  • Actions
    • Unit Group - Remove (Dying unit) from Undead_Base_Group
Dead units don't automatically get removed from a Unit Group so you will have to remove them yourself.

But this is the perfect place to check if ALL of the units are dead. Let's expand the trigger to do so:
  • Events
    • Unit - A unit Dies
  • Conditions
    • ((Dying unit) is in Undead_Base_Group) Equal to True
  • Actions
    • Unit Group - Remove (Dying unit) from Undead_Base_Group
    • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
      • If - Conditions
        • (Undead_Base_Group is empty) Equal to True
      • Then - Actions
        • -------- The very last unit in the undead base has died! --------
        • Trigger - Run SomeOtherTrigger (ignoring conditions)
      • Else - Actions
So whenever a unit in the Undead Base dies, we remove it from the Unit Group and check to see if the group is now empty. The group will be empty when ALL of the units have been removed, in other words, when all of the units have died. We can use the If Then Else action to ask questions at different stages throughout our trigger. In this case we use it to ask if the group is empty. If it's empty we run another trigger which would handle the rest of your logic, like creating the transport ship and having it rebuild the base. You can Add the rebuilt units to Undead_Base_Group as they're being constructed/created in order to start the process over again.

From there, I recommend looking up some tutorials. A basic understanding of triggers/variables is all that's needed.
 
Last edited:
Top