• 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.

[General] Triggering respawns based on unit amount?

Level 5
Joined
Nov 17, 2022
Messages
84
I hate to be a bother again but I am really lost. I tinkered with the triggers on and off all day last night and this morning but couldn't find a solution. I was hoping perhaps someone could provide a visual example as well, since I understand those better than being told. I was advised to set up variables to track this additionally but I am unsure which ones I need for this trigger.

I'm trying to do a thing where if a unit type population goes below a certain threshold, the unit population will run a trigger to create a replacement for it. I know how to create the basics, like, every X seconds create said unit but I need it to be pretty specific. I also need to know how to set up a unit population cap since what I've tried just ain't it. So ideally in this game it would be more like:

Time of Day becomes 18.00 or 6.00

Unit population cap is X, game would check to see if the population is low enough to warrent creating the replacement units, otherwise, it won't do it once the time arrives to replace the dead units of the previous night. This is to help prevent too many units on the map since with each passing night a new population of unit types is introduced to the mix. The caps may or may not increase in size after so many nights passing though depending on future play testing.

Issue is I can get the units to spawn at the desired times but if I do 6.00, it will spawn the next night units in prematurely instead of waiting until the 18.00 time to begin alongside the previous night units who need replacing due to death and also will spawn too many of the units that need to be replaced. So instead of the population remaining a constant number, the already say 10 units will double into 20 [this also happens if I set the time spawn to 18.00 too]

I hope I'm wording things correctly. I can post visual examples of my triggers once I get access to my computer again if anyone desires. Any help would be appreciated.
 

Uncle

Warcraft Moderator
Level 73
Joined
Aug 10, 2018
Messages
7,875
If your units are contained in Unit Groups then you can always get the number of units inside of the group. You just need to be on top of managing the groups:
  • Events
    • Unit - A unit Enters (Playable map area)
    • Unit - A unit Dies
  • Conditions
    • (Unit-type of (Triggering unit)) Equal to Wolf
  • Actions
    • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
      • If - Conditions
        • ((Triggering unit) is Alive) Equal to True
      • Then - Actions
        • Unit Group - Add (Triggering unit) to Wolf_Group
        • Unit Group - Add (Triggering unit) to Predator_Group
      • Else - Actions
        • Unit Group - Remove (Triggering unit) from Wolf_Group
        • Unit Group - Remove (Triggering unit) from Predator_Group
So now anytime a Wolf comes into play, regardless of how it was created, you will start tracking it in the Wolf specific Unit Group. Then whenever a Wolf dies you will stop tracking it. I also threw in the Predator_Group as a way to track ALL of the different Unit-types since you may want to interact with any kind of predator.

It can also be wise to rely on hidden Abilities as pseudo-Classifications instead of checking for a Unit-type. For example, if you have 5 different types of Wolves that are meant to share this single trigger then you can simplify your Conditions to check for a characteristic that they all share:
  • Conditions
    • (Level of Wolf Classification for (Triggering unit)) Equal to 1

Anyway, the Unit Group design allows you to keep track of things and always have up to date information. This will serve useful in your other triggers:
  • Events
    • ... It's time to spawn in some enemy units
  • Conditions
  • Actions
    • Set Variable Spawn_Count = 4
    • Set Variable Predator_Count = (Number of units in Predator_Group)
    • Set Variable Predator_Expected_Count = (Spawn_Count + Predator_Count)
    • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
      • If - Conditions
        • Predator_Expected_Count Greater than Population_Cap
      • Then - Actions
        • Set Variable Spawn_Count = (Predator_Expected_Count - Population_Cap)
      • Else - Actions
    • For each (Integer A) from 1 to Spawn_Count do (Actions)
      • Loop - Actions
        • Unit - Create 1 Wolf...
This trigger will attempt to spawn up to 4 Wolves. However, it will never exceed the Population_Cap thanks to some simple math. Note how Spawn_Count's value will vary based on the circumstances, ranging anywhere from 0 to 4. If it's <= 0 then nothing will spawn in, which would occur if you're already at the Population_Cap.
 
Last edited:
Level 5
Joined
Nov 17, 2022
Messages
84
If your units are contained in Unit Groups then you can always get the number of units inside of the group. You just need to be on top of managing the groups:
  • Events
    • Unit - A unit Enters (Playable map area)
    • Unit - A unit Dies
  • Conditions
    • (Unit-type of (Triggering unit)) Equal to Wolf
  • Actions
    • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
      • If - Conditions
        • ((Triggering unit) is Alive) Equal to True
      • Then - Actions
        • Unit Group - Add (Triggering unit) to Wolf_Group
        • Unit Group - Add (Triggering unit) to Predator_Group
      • Else - Actions
        • Unit Group - Remove (Triggering unit) from Wolf_Group
        • Unit Group - Remove (Triggering unit) from Predator_Group
So now anytime a Wolf comes into play, regardless of how it was created, you will start tracking it in the Wolf specific Unit Group. Then whenever a Wolf dies you will stop tracking it. I also threw in the Predator_Group as a way to track ALL of the different Unit-types since you may want to interact with any kind of predator.

It can also be wise to rely on hidden Abilities as pseudo-Classifications instead of checking for a Unit-type. For example, if you have 5 different types of Wolves that are meant to share this single trigger then you can simplify your Conditions to check for a characteristic that they all share:
  • Conditions
    • (Level of Wolf Classification for (Triggering unit)) Equal to 1

Anyway, the Unit Group design allows you to keep track of things and always have up to date information. This will serve useful in your other triggers:
  • Events
    • ... It's time to spawn in some enemy units
  • Conditions
  • Actions
    • Set Variable Spawn_Count = 4
    • Set Variable Predator_Count = (Number of units in Predator_Group)
    • Set Variable Predator_Expected_Count = (Spawn_Count + Predator_Count)
    • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
      • If - Conditions
        • Predator_Expected_Count Greater than Population_Cap
      • Then - Actions
        • Set Variable Spawn_Count = (Predator_Expected_Count - Population_Cap)
      • Else - Actions
    • For each (Integer A) from 1 to Spawn_Count do (Actions)
      • Loop - Actions
        • Unit - Create 1 Wolf...
This trigger will attempt to spawn in up to 4 Wolves. However, it will never exceed the Population_Cap thanks to some simple math. Note how Spawn_Count's value will vary based on the circumstances, ranging anywhere from 0 to 4. If it's <= 0 then nothing will spawn in, which would occur if you're already at the Population_Cap.
Ooo, okay. Thank you very much, this really spells it out for me.
 
Level 5
Joined
Nov 17, 2022
Messages
84
If your units are contained in Unit Groups then you can always get the number of units inside of the group. You just need to be on top of managing the groups:
  • Events
    • Unit - A unit Enters (Playable map area)
    • Unit - A unit Dies
  • Conditions
    • (Unit-type of (Triggering unit)) Equal to Wolf
  • Actions
    • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
      • If - Conditions
        • ((Triggering unit) is Alive) Equal to True
      • Then - Actions
        • Unit Group - Add (Triggering unit) to Wolf_Group
        • Unit Group - Add (Triggering unit) to Predator_Group
      • Else - Actions
        • Unit Group - Remove (Triggering unit) from Wolf_Group
        • Unit Group - Remove (Triggering unit) from Predator_Group
So now anytime a Wolf comes into play, regardless of how it was created, you will start tracking it in the Wolf specific Unit Group. Then whenever a Wolf dies you will stop tracking it. I also threw in the Predator_Group as a way to track ALL of the different Unit-types since you may want to interact with any kind of predator.

It can also be wise to rely on hidden Abilities as pseudo-Classifications instead of checking for a Unit-type. For example, if you have 5 different types of Wolves that are meant to share this single trigger then you can simplify your Conditions to check for a characteristic that they all share:
  • Conditions
    • (Level of Wolf Classification for (Triggering unit)) Equal to 1

Anyway, the Unit Group design allows you to keep track of things and always have up to date information. This will serve useful in your other triggers:
  • Events
    • ... It's time to spawn in some enemy units
  • Conditions
  • Actions
    • Set Variable Spawn_Count = 4
    • Set Variable Predator_Count = (Number of units in Predator_Group)
    • Set Variable Predator_Expected_Count = (Spawn_Count + Predator_Count)
    • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
      • If - Conditions
        • Predator_Expected_Count Greater than Population_Cap
      • Then - Actions
        • Set Variable Spawn_Count = (Predator_Expected_Count - Population_Cap)
      • Else - Actions
    • For each (Integer A) from 1 to Spawn_Count do (Actions)
      • Loop - Actions
        • Unit - Create 1 Wolf...
This trigger will attempt to spawn up to 4 Wolves. However, it will never exceed the Population_Cap thanks to some simple math. Note how Spawn_Count's value will vary based on the circumstances, ranging anywhere from 0 to 4. If it's <= 0 then nothing will spawn in, which would occur if you're already at the Population_Cap.
I managed to set this all up but it still prematurely spawned units in on the nights they shouldn't exist yet. Like Night 1 spawning Foxes when they shouldn't exist until Night 2. I was wondering if there's a condition I need to prevent the game from replacing predators that shouldn't exist yet?

EDIT: Ok, I THINK adding a condition like Night Cycles greater than or equal to X number seems to fix it. Tho I have messed something up because it seems like when each night passes, the unit populations increase, so I gotta dig into what I did wrong in my recreation.

EDIT 2: Ok, seems I put a wrong group when it should be predator group and not unit type group oop.
 
Last edited:
Top