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

Limited reinforcement waves

Level 23
Joined
Nov 20, 2005
Messages
1,256
Hello. I have a problem with triggers in the map I'm creating, where you lead an army of mixed units, and a scoreboard displays how many remaining additional waves you have before Game Over, sort of acting like a "Player Life" counter on screen.
  • When you have 6 remaining units, a new wave spawns at the starting point of the map.
  • When you destroy gates to advance into the next sector, 2 additional waves are added to the HUD scoreboard and the variable that stores the number of available waves.
  • When you reach 1 waves, that's the last reinforcement wave you get, before it turns to 0, then when all units get killed it's Game Over.

Now, what's the problem? I get only 1 additional wave, but by the time that new wave dies, it's game over.
Anyone can help me to build an accurate working system for this, please?
 

Dr Super Good

Spell Reviewer
Level 65
Joined
Jan 18, 2005
Messages
27,296
To track waves remaining, use an integer global variable (which are just regular variables in GUI). If your map is multiplayer and you want this mechanic to apply to many players, then turn that integer global variable into an array where the array index is the player slot, mapping player slot number to their units remaining.

  • At map initialisation you set the integer variable to the number of additional waves the players should start with.
  • Another trigger adds 2 to the integer variable in response to the gates being destroyed. If this is a team game you might need to loop through all relevant, allied, players and add 2 to the integer for them.
  • An on unit death trigger counts how many appropriate units a player has remaining. When units remaining is less than or equal to 6 and the integer variable is greater than 0 run your reinforcement wave logic which spawns the new units and reduces the integer variable by 1. If units remaining is 0, run your defeat logic. Be aware that counting units typically involves unit groups which are prone to resource leaks, I strongly recommend you read up about this and add the appropriate clean up code to prevent such leaks.
 
Level 23
Joined
Nov 20, 2005
Messages
1,256
At map initialisation you set the integer variable to the number of additional waves the players should start with.
First off, thank you so much for the help! 🙏
This is the only step that I seemingly haven't accurately done: setting the integer variable to the number of additional waves the players should start with.
I did it out of map initialisation.
Everything else has been set exactly as you explained. The matter about the units counting which involves resource leaks is something that I need to address as well.
Also, it looks like whenever I want to increase or decrease the waves variable, it increases/decreases by 2 instead of 1. I still haven't understood why. There appear to be no more than 1 trigger to handle that function.
I just tested the map and it successfully gave me reinforcement 2 times, before I managed to complete it.
It's a campaign map, so it doesn't involve teams or other human players.
 
Would you be able to share your triggers? It sounds like you're on the right track, but the trigger may be running multiple times. But it is hard for us to tell without knowing the code.

Otherwise we could come up with a sample map that you could use, if that helps to compare your code against.
 
Level 23
Joined
Nov 20, 2005
Messages
1,256
Would you be able to share your triggers? It sounds like you're on the right track, but the trigger may be running multiple times. But it is hard for us to tell without knowing the code.

Otherwise we could come up with a sample map that you could use, if that helps to compare your code against.
Yes, I agree. I'm gonna do this tomorrow; I'm in serious hurry of going to sleep now! 😅🥱
 
Level 23
Joined
Nov 20, 2005
Messages
1,256
Would you be able to share your triggers? It sounds like you're on the right track, but the trigger may be running multiple times. But it is hard for us to tell without knowing the code.

Otherwise we could come up with a sample map that you could use, if that helps to compare your code against.
As suggested from @Dr Super Good , I've reset the value of OrcAvailableWaves to 0, and set it via trigger in the map initialization.
It was initially set to 4, directly through the variables tab, but for some reason the value would display as 5 in the leaderboard.

screenshot-2025-06-08-121741-png.536606


This is the trigger👇 that detects when the current wave you command drops to/under 6 elements.

screenshot-2025-06-08-121847-png.536607


This is the trigger👇 that activates when all units in the current wave are dead, and therefore when waves are down to 0 (otherwise the "6 remaining elements" threshold would trigger instead).

screenshot-2025-06-08-115027-png.536605


I've double-checked and there are no additional triggers that raise the amount of OrcAvailableWaves together with the ones whenever a gate is destroyed. Once again, this value seems to increase by 2 instead of 1.

I haven't tested the map with the updated function in the Map Initialization. I shall give it another go later and report.
 

Dr Super Good

Spell Reviewer
Level 65
Joined
Jan 18, 2005
Messages
27,296
You can use actions that display messages to help debug triggers. For example you can print one every time the decrement action runs, and print values such as number of units in the wave.

Although really poor compared to more professional debuggers such as in StarCraft II, it still is good enough to give some insight into the order and values of logic being run.
 
Could you also show the trigger you use to spawn units? Ideally it would run after you decrement OrcAvailableWaves. You'll want to make sure you add those units to the group "OrcCurrentWave". In addition, when a unit dies, you'll want to remove them from that unit group--or else they'll remain in the group even when they're dead.

I whipped up a quick sample that follows a more event-based approach, similar to the method that Dr Super Good mentioned. Timers work fine too, but timers can sometimes lead to subtle bugs when you have multiple triggers running simultaneously. For example, in your case, it is possible that the "Defeat Units Dead" timer ticked and detected that all the units in the group were dead before "Wave depleted lower waves counter" ticked to grant a wave. (you could fix that by enabling the "OrcAvailableWaves Equal to 0" condition again, but I still recommend using the direct death events where possible)

I've attached the map below (requires patch v.2.0.2+ to open). If you don't mod on that patch, I'll post the sample triggers below:
  • Setup
    • Events
      • Map initialization
    • Conditions
    • Actions
      • -------- --------
      • -------- Grant 3 initial waves --------
      • -------- --------
      • Set VariableSet RemainingWaves = 3
      • -------- --------
      • -------- Spawn an initial wave of orcs --------
      • -------- --------
      • Set VariableSet SW_InputPlayer = Player 4 (Purple)
      • Set VariableSet SW_InputSpawnRegion = WaveSpawnRegion <gen>
      • Trigger - Run SpawnWave <gen> (ignoring conditions)

  • SpawnWave
    • Events
    • Conditions
    • Actions
      • -------- --------
      • -------- Spawn 3 grunts --------
      • -------- --------
      • For each (Integer SW_LoopInteger) from 1 to 3, do (Actions)
        • Loop - Actions
          • Set VariableSet SW_TempLoc = (Random point in SW_InputSpawnRegion)
          • Unit - Create 1 Grunt for SW_InputPlayer at SW_TempLoc facing Default building facing degrees
          • Unit Group - Add (Last created unit) to OrcCurrentWave
          • Custom script: call RemoveLocation(udg_SW_TempLoc)
      • -------- --------
      • -------- Spawn 3 shaman --------
      • -------- --------
      • For each (Integer SW_LoopInteger) from 1 to 3, do (Actions)
        • Loop - Actions
          • Set VariableSet SW_TempLoc = (Random point in SW_InputSpawnRegion)
          • Unit - Create 1 Shaman for SW_InputPlayer at SW_TempLoc facing Default building facing degrees
          • Unit Group - Add (Last created unit) to OrcCurrentWave
          • Custom script: call RemoveLocation(udg_SW_TempLoc)
      • -------- --------
      • -------- Spawn 1 tauren --------
      • -------- --------
      • Set VariableSet SW_TempLoc = (Random point in SW_InputSpawnRegion)
      • Unit - Create 1 Tauren for SW_InputPlayer at SW_TempLoc facing Default building facing degrees
      • Unit Group - Add (Last created unit) to OrcCurrentWave
      • Custom script: call RemoveLocation(udg_SW_TempLoc)

  • OrcDies
    • Events
      • Unit - A unit Dies
    • Conditions
      • ((Triggering unit) is in OrcCurrentWave.) Equal to True
    • Actions
      • -------- --------
      • -------- Remove this unit from the group so it no longer counts towards the total --------
      • -------- --------
      • Unit Group - Remove (Triggering unit) from OrcCurrentWave.
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Number of units in OrcCurrentWave) Less than or equal to 6
        • Then - Actions
          • -------- --------
          • -------- If there are more than 0 remaining waves, spawn a new wave --------
          • -------- --------
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • RemainingWaves Greater than 0
            • Then - Actions
              • Set VariableSet RemainingWaves = (RemainingWaves - 1)
              • Set VariableSet SW_InputPlayer = Player 4 (Purple)
              • Set VariableSet SW_InputSpawnRegion = WaveSpawnRegion <gen>
              • Trigger - Run SpawnWave <gen> (ignoring conditions)
              • Trigger - Run RefreshWaveLeaderboard <gen> (ignoring conditions)
              • Game - Display to (All players) the text: Spawned a new wave ...
              • Sound - Play Warning <gen>
            • Else - Actions
              • -------- --------
              • -------- If there are no more waves, check if all units are dead --------
              • -------- If all units are dead, then trigger defeat --------
              • -------- --------
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Number of units in OrcCurrentWave) Equal to 0
                • Then - Actions
                  • Game - Defeat Player 4 (Purple) with the message: Defeat!
                • Else - Actions
        • Else - Actions

  • GateDies
    • Events
      • Destructible - City Entrance 0213 <gen> dies
      • Destructible - City Entrance 0382 <gen> dies
      • Destructible - City Entrance 0460 <gen> dies
    • Conditions
    • Actions
      • Sound - Play GoodJob <gen>
      • Game - Display to (All players) the text: Granted 2 waves for...
      • Set VariableSet RemainingWaves = (RemainingWaves + 2)
      • Trigger - Run RefreshWaveLeaderboard <gen> (ignoring conditions)

  • InitializeLeaderboard
    • Events
      • Time - Elapsed game time is 0.00 seconds
    • Conditions
    • Actions
      • Leaderboard - Create a leaderboard for (All players) titled Remaining Waves
      • Set VariableSet WaveLeaderboard = (Last created leaderboard)
      • Leaderboard - Change the display style for WaveLeaderboard to Show the title, Show labels, Show values, and Hide icons
      • Leaderboard - Add Player 4 (Purple) to WaveLeaderboard with label (Name of Player 4 (Purple)) and value RemainingWaves
      • Leaderboard - Show WaveLeaderboard
  • RefreshWaveLeaderboard
    • Events
    • Conditions
    • Actions
      • Leaderboard - Change the value for Player 4 (Purple) in WaveLeaderboard to RemainingWaves

At a high-level, when a unit dies in the "OrcCurrentWave", remove it from the unit group. If there are 6 or fewer units remaining after that, then try to spawn a wave if possible--otherwise we just need to check when the number of units drops to 0 to trigger defeat.

Other than that, it is mostly just leaderboard updates. It is quite similar to what you already have--but the event-based approach makes it more reliable and simpler overall. Let me know if you have any questions!
 

Attachments

  • WaveSample.w3m
    29.2 KB · Views: 0
Top