- Joined
- Aug 7, 2004
- Messages
- 875
Foreword:
In this tutorial you will learn how to make a system based on GUI for multiple creep spawning. Creep spawning is commonly used in map types such as Tower Defense, Castle Defense, Survival, and Hero Defense.
The system you are about to learn is user friendly, easy to understand once you know the functions. It is also feasible and is easy to be adjusted to any frequency of difficulty and style you want.
Why use this method? It is efficient and it only requires three simple trigger packages. This system method will have an initVar, which sets the unitType and amount for each lvlNum, it will also have the callOperate, which creates the creeps and orders it to move to a specific location, and it will also have a roundTimer, which is a countdown timer for every round.
The Code:
Firstly create these variables in your map
Array unit_type = variable unit type
Array unit_type_var_two = variable unit type
Array unit_type_var_three = variable unit type
int lvlNum = variable integer value
Array unit_amount = variable integer value
Array unit_amount_var_two = variable integer value
Array unit_amount_var_three = variable integer value
roundwindow = countdown timer
The variable unit_type and unit_amount depends on how many unit types you want in each level. For this code example, there will be three unit types so I'd create three unit_type variables and three unit_amount variable.
To start with I'm going to create a countdown timer first that will end in 60 seconds but is repeating.
You can go on forever to any maximum level you want. For this code example, lets stick to 3 levels only.
Right now you have completed the second package which is initVar. All it does is initializing the variables of unit_type and unit_amount. The unit_type is to declare a unit type that will be created during each level. The unit_amount is to declare how many units of a unit type will be created during each level. The number you put in the array index; set unit_type[1] = Ghoul, is the number of the lvlNum or the index number of the level.
In this package you can create as many level as you want, many unit types for each level, and different amounts. It is easily adjusted for you to change the frequency of the difficulty and style in the map.
Now lets start making the final package which is the callOperate. This method will run a loop that will create the initialized creep units. Note that in this tutorial example, the loop will create the initialized creep at 8 locations in the corners of the map. It will then issue an order for the created creep unit to move to the center of the map. In your own version you can set different creep spawn locations if you want, you can have 6 locations instead but before modifying the method you must understand the concept first.
Before moving on please create this variables in your map,
Array loc = variable location (a variable for the eight spawning locations)
int incrementx = variable integer (a variable used for the loop)
int incrementy = variable integer (a variable used for the loop)
You have completed the Multiple Creep Spawn system. Test it now and see if it works. If you found bugs and errors please contact me at [email protected] or else submit your report at this thread.
Things to note if you want to modify the code:
• If you want to change the number of multiple units for every level in your map, the corresponding variables are: unit_type and unit_amount, don't forget the loop.
• If you want to change the time the countdown timer will last, modify the countDown code.
• If you want to make it so that the countdown timer does not repeat itself and waits for condition that the enemy attackers have zero attacking units, read the countDown package section.
• This system can be done more efficiently in Jass. Next tutorial will be about implementing a Smart Pathing system and AI for spawned creeps with Jass.
Thank you and have fun coding
In this tutorial you will learn how to make a system based on GUI for multiple creep spawning. Creep spawning is commonly used in map types such as Tower Defense, Castle Defense, Survival, and Hero Defense.
The system you are about to learn is user friendly, easy to understand once you know the functions. It is also feasible and is easy to be adjusted to any frequency of difficulty and style you want.
Why use this method? It is efficient and it only requires three simple trigger packages. This system method will have an initVar, which sets the unitType and amount for each lvlNum, it will also have the callOperate, which creates the creeps and orders it to move to a specific location, and it will also have a roundTimer, which is a countdown timer for every round.
The Code:
Firstly create these variables in your map
Array unit_type = variable unit type
Array unit_type_var_two = variable unit type
Array unit_type_var_three = variable unit type
int lvlNum = variable integer value
Array unit_amount = variable integer value
Array unit_amount_var_two = variable integer value
Array unit_amount_var_three = variable integer value
roundwindow = countdown timer
The variable unit_type and unit_amount depends on how many unit types you want in each level. For this code example, there will be three unit types so I'd create three unit_type variables and three unit_amount variable.
To start with I'm going to create a countdown timer first that will end in 60 seconds but is repeating.
-
Actions
- Game - Display to (All players) the text: Countdown started...
- Countdown Timer - Start RoundWindow as a Repeating timer that will expire in 60.00 seconds
- Set RoundWindow = (Last started timer)
- Countdown Timer - Create a timer window for (Last started timer) with title Enemy Wave in...
-
Event
- timer expires
-
Actions
- bj_wantDestroyGroup = true
- Wait until ((All units of (Units owned by Player 12 (Brown)) are dead)Equal to True), checking every 1.00 seconds
- Game - Display to (All players) the text: Countdown started...
- Countdown Timer - Start RoundWindow as a Repeating timer that will expire in 60.00 seconds
- Set RoundWindow = (Last started timer)
- Countdown Timer - Create a timer window for (Last started timer) with title Enemy Wave in...
-
Event
- Game Initialization
-
Actions
- Set Lvl_num = 0
- -------- Level 1 --------
- Set unit_type[1] = Ghoul
- Set unit_type_var_two[1] = Troll
- Set unit_type_var_three[1] = Zombies
- Set unit_amount[1] = 3
- Set unit_amount_var_two[1] = 1
- Set unit_amount_var_three[1] = 1
- -------- Level 2 --------
- Set unit_type[2] = Troll
- Set unit_type_var_two[2] = Ghoul
- Set unit_type_var_three[2] = Zombies
- Set unit_amount[2] = 2
- Set unit_amount_var_two[2] = 2
- Set unit_amount_var_three[2] = 1
- -------- Level 3 --------
- Set unit_type[3] = Zombies
- Set unit_type_var_two[3] = Troll
- Set unit_type_var_three[3] = Light Trolls
- Set unit_amount[3] = 2
- Set unit_amount_var_two[3] = 2
- Set unit_amount_var_three[3] = 1
- ...
You can go on forever to any maximum level you want. For this code example, lets stick to 3 levels only.
Right now you have completed the second package which is initVar. All it does is initializing the variables of unit_type and unit_amount. The unit_type is to declare a unit type that will be created during each level. The unit_amount is to declare how many units of a unit type will be created during each level. The number you put in the array index; set unit_type[1] = Ghoul, is the number of the lvlNum or the index number of the level.
In this package you can create as many level as you want, many unit types for each level, and different amounts. It is easily adjusted for you to change the frequency of the difficulty and style in the map.
Now lets start making the final package which is the callOperate. This method will run a loop that will create the initialized creep units. Note that in this tutorial example, the loop will create the initialized creep at 8 locations in the corners of the map. It will then issue an order for the created creep unit to move to the center of the map. In your own version you can set different creep spawn locations if you want, you can have 6 locations instead but before modifying the method you must understand the concept first.
Before moving on please create this variables in your map,
Array loc = variable location (a variable for the eight spawning locations)
int incrementx = variable integer (a variable used for the loop)
int incrementy = variable integer (a variable used for the loop)
-
Events
- Map Initialization
-
Actions
- Set loc[1] = (Center of Corner BR <gen>)
- Set loc[2] = (Center of Corner BL <gen>)
- Set loc[3] = (Center of Corner BL2 <gen>)
- Set loc[4] = (Center of Corner TL2 <gen>)
- Set loc[5] = (Center of Corner TL <gen>)
- Set loc[6] = (Center of Corner TR <gen>)
- Set loc[7] = (Center of Corner TR2 <gen>)
- Set loc[8] = (Center of Corner BR2 <gen>)
-
Spawn
-
Events
- Time - RoundWindow expires
- Conditions
-
Actions
- Set Lvl_num = (Lvl_num + 1)
-
For each (Integer A) from 1 to unit_amount[Lvl_num], do (Actions)
-
Loop - Actions
- Set incrementx = 1
- Set incrementy = 1
-
For each (Integer B) from 1 to 4, do (Actions)
-
Loop - Actions
- Unit - Create 1 unit_type[Lvl_num] for Player 12 (Brown) at loc[incrementy] facing Default building facing degrees
- Unit - Order (Last created unit) to Attack-Move To center of map
- Unit - Create 1 unit_type[Lvl_num] for Player 12 (Brown) at loc[(incrementy + 1)] facing Default building facing degrees
- Unit - Order (Last created unit) to Attack-Move To center of map Set incrementx = (incrementx + 1)
- Set incrementy = (incrementy + 2)
-
Loop - Actions
- Wait 0.75 seconds
-
Loop - Actions
-
For each (Integer A) from 1 to unit_amount_var_three[Lvl_num], do (Actions)
-
Loop - Actions
- Set incrementx = 1
- Set incrementy = 1
-
For each (Integer B) from 1 to 4, do (Actions)
-
Loop - Actions
- Unit - Create 1 unit_type_var_three[Lvl_num] for Player 12 (Brown) at loc[incrementy] facing Default building facing degrees
- Unit - Order (Last created unit) to Attack-Move To center of map
- Unit - Create 1 unit_type_var_three[Lvl_num] for Player 12 (Brown) at loc[(incrementy + 1)] facing Default building facing degrees
- Unit - Order (Last created unit) to Attack-Move To center of map
- Set incrementx = (incrementx + 1)
- Set incrementy = (incrementy + 2)
-
Loop - Actions
- Wait 0.75 seconds
-
Loop - Actions
-
For each (Integer A) from 1 to unit_amount_var_two[Lvl_num], do (Actions)
-
Loop - Actions
- Set incrementx = 1
- Set incrementy = 1
-
For each (Integer B) from 1 to 4, do (Actions)
-
Loop - Actions
- Unit - Create 1 unit_type_var_two[Lvl_num] for Player 12 (Brown) at loc[incrementy] facing Default building facing degrees
- Unit - Order (Last created unit) to Attack-Move To center of map
- Unit - Create 1 unit_type_var_two[Lvl_num] for Player 12 (Brown) at loc[(incrementy + 1)] facing Default building facing degrees
- Unit - Order (Last created unit) to Attack-Move To center of map
- Set incrementx = (incrementx + 1)
- Set incrementy = (incrementy + 2)
-
Loop - Actions
- Wait 0.75 seconds
-
Loop - Actions
-
Events
You have completed the Multiple Creep Spawn system. Test it now and see if it works. If you found bugs and errors please contact me at [email protected] or else submit your report at this thread.
Things to note if you want to modify the code:
• If you want to change the number of multiple units for every level in your map, the corresponding variables are: unit_type and unit_amount, don't forget the loop.
• If you want to change the time the countdown timer will last, modify the countDown code.
• If you want to make it so that the countdown timer does not repeat itself and waits for condition that the enemy attackers have zero attacking units, read the countDown package section.
• This system can be done more efficiently in Jass. Next tutorial will be about implementing a Smart Pathing system and AI for spawned creeps with Jass.
Thank you and have fun coding
Attachments
Last edited by a moderator: