A Simple TD Part 7: Creating Waves and a Countdown Timer
Here is a link to the map if you want to see my progress so far:
Feel free to test it out, but beware my there isn’t really a lot to it yet.
In the last tutorial I covered how to make the waves move, but I didn’t really cover how to spawn the units or create a countdown timer. This sample only covers 5 waves for now, but you should be able to expand it as you wish. I at first tried to work with creating an array to hold each wave but I ran into a few difficulties, so I decided to use an if, then, else structure. It works but it is a little messy.
Setting up Variables
The first thing I do is define two variables in the trigger editor. This is done by right clicking in the left pane, going to new > then variable.
Creating a new variable will take you into the following screen where you define the variables name, type and value. For those who aren’t familiar with programming, variables are ways to store different types of data. This timer variable will store data of the type Timer. It will be used to reference our timer throughout the trigger editor. This allows us to use the same timer in multiple triggers. If we didn’t do this we couldn’t easily refer to the timer.
The first thing you will do is enter a name for the timer. Since we will only use 1 timer, I simply call it timer. Under type, select Timer and set the default to a new timer by double clicking where it says “initial value” on the right.
You will also want to follow the same process to create a variable called EnemyWaveNumber. This will keep track of which wave the player is on. Here is what it looks like, make sure you set the default value to 1 and the type to integer. An integer is a common variable type in programming to hold whole numbers.
These variables will assist us with keeping track of wave spawns and which number we are on.
So we have a timer variable but it really isn’t doing anything yet. Lets get it running. Create a new trigger that has a map initialization event.
Now create a new action for the trigger, it should look like this:
Make sure you click on the “Timer” link and go to variables, and select your timer variable.
Next you need to create another action for your Timer Window. The timer window is used to display your timer.
After you are finished it should look like this:

Your timer is now set up, so lets start with the enemy spawns!
Setting up Enemy Spawns
You now need to set up a trigger to keep track of enemy spawning. I assume you have a point on your map already so that you know where to make them spawn from.
1) Create a new Trigger, giving it the name of something like Wave.
2) Simply create a single action,using Unit – Create Unit. I put the number at 5 and the unit at SCV. I also told the action to place them at waypoint 1, which is my spawning point for my TD. This is what it looks like at the bottom of the editor. Make sure you set it for the player that will be the enemy. I used player 2.
3) You can copy this trigger on the left side and paste it to duplicate it. Now you just need to change the unit type and perhaps the number of units and you are good! I made 5 waves. Be sure to name each trigger something useful. You can also do Right Click > New > Folder to create a folder to organize your triggers.
Creating the Master Spawn Trigger
1) Create a new trigger and name it something like EnemySpawn.
2) Give it a new event, timer every X seconds of game time.
The two conditions I have are optional, and you can ignore them if you wish. The first one just tells it to make sure that .5 of a minute has passed before the trigger can be executed. The second makes sure that the trigger will only be executed if the 5th wave hasn’t occurred.
The actions, however are important. Add a new action, selecting if then else
You will then receive a new action that looks like this:
For those not familiar with programming, an if then else statement is used to see if a certain condition is true. A ridiculous real world example for this would be:
If Vegetable equals Carrot; Then Eat Vegetable; Else Do Nothing.
You can also string these together and put another If Then Else statement inside another. So our example could be extended to:
If Vegetable equals Carrot; Then Eat Vegetable; Else If Vegetable equals Tomato; Then Give Vegetable to Friend; Else Do Nothing
This is kind of what I did for waves here.
1) In your newly created trigger right click on the If Statement and select New > Condition,
2) Select New Comparison and press OK.
3) In the bottom of the trigger editor, double click on Value 1: Owner of Triggering Unit.
4) Select the Variable Radio Box, and select Enemy Wave Number and press OK. It should look like this at the bottom.
5) You will now want to right click on “Then” and click New Action.
6) In the New Action menu Select Trigger – Run Trigger.
It should look like this:
7) Now you will want to right click on the Else statement and select new If Then Else statement. You then repeat it for each of your waves. You can copy and paste your previous if then else, it saves a lot of work. Then you just need to change the key values. It should look like this:
It is a little messy but it gets the job done. You can minimize the main IF THEN ELSE so it isn’t so overwhelming.
Almost there! We just need to add 2 more quick things. First, we need to increment our wave number variable so each time a wave is run, it will know where it left off.
1) In the same trigger, right click the Actions and select new > Action.
2) Select Modify Variable.
The end result should look like this:
Next, we will want to reset the timer window for another 30 seconds, add another action that looks like this:
Make sure you point to your timer variable like you did before!
You now have a timer that displays in a timer window and waves that spawn every 30 seconds!
There is a link to the map at the top of the tutorial if you would like it.
Notes:
You could probably get away with using a repeating timer instead of a one shot timer, but I decided to use these in case I decided to incorporate variable times.
Related posts:

















Great guide! Just as a side note, as an alternative to doing a bunch of nested if-else statements, there is a switch function in the trigger editor that makes the process a little cleaner if you have a larger number waves or whatever you’re checking.
Cool, thanks Ethan, I didn’t think about checking for a switch.
Might be more prudent to utilize a pair of arrays. Have a Unit Array and a Quantity Array. Have a trigger that fires at the beginning that populates these arrays and then you don’t have to use if/thens or switch statements. Just use the array index to figure out what unit and how many.
Only problem im having is when i go to designate the timer, the step where u get the timer running, i dont have the ability to designate Timer -New timer, i can only do new timer or last created timer.
Hello!
How can I create more than one respaw per wave?
Thanks!
To create a array of waves. I do this way.
First i create an variable type unit amd mark selection (size will be the number of waves you want, i put 10)
Note: my editor is on spanish since i have spanish edition of the game hope you understand the image.
I also create a int variable that is number of waves and start at 1 (first wave)
http://img809.imageshack.us/i/array.jpg/
Then i create a units that i want to attack on the terrain for a neutral player and assing the array units to units i want on every wave sine 1 to 10
http://img824.imageshack.us/i/unitassings.jpg/
For the waves i do a bucle activator that execute itself after some time again and plus 1 to the wave variable and assing the units selecting creating unit by type of unit: unit of variable. something like this
http://img843.imageshack.us/i/waves.jpg/
I read a guide on SC2 mapster on how to make a button that sends the next wave rather than a timer. I want to try and put a lives counter into the dialog box aswell but i cant figure out how??? Can someone msg me and tell me how i might go about doing this plz???
I have been trying to replicate the
(Game time for player 1) > .5
line but absolutely no luck. How do I get this condition?
Awesome!! Thanks so much! I always wanted to make a td!
Great, but what happens is it creates wave one and then immediately goes on to wave 5. How to fix?