• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[Solved] How to make difficulty Button/trigger

Status
Not open for further replies.
Level 3
Joined
Dec 30, 2020
Messages
19
Helloooo peeps. I'm trying to a make wave based a map and im having alot of trouble with setting triggers since i suck at them. So I'm wondering if any one could help me to get a idea how to make a difficulty options so when the game starts the options pop -Easy normal etc....- and how to i make it so it affects the game like if player chooses a hard mode then it add stats + something new into the wave??

Ps:i tried to search how to make it but ended up with noting, so here i am.

:vw_wtf:
 
Level 20
Joined
Aug 29, 2012
Messages
828
Here's the basics of how you create a dialog:

  • Create
    • Events
      • Time - Elapsed game time is 5.00 seconds
    • Conditions
    • Actions
      • Dialog - Clear MyDialog
      • Dialog - Change the title of MyDialog to Select your difficu...
      • -------- ----------------- --------
      • Dialog - Create a dialog button for MyDialog labelled Easy
      • Set VariableSet MyDialogButton[1] = (Last created dialog Button)
      • -------- ----------------- --------
      • Dialog - Create a dialog button for MyDialog labelled Medium
      • Set VariableSet MyDialogButton[2] = (Last created dialog Button)
      • -------- ----------------- --------
      • Dialog - Create a dialog button for MyDialog labelled Hard
      • Set VariableSet MyDialogButton[3] = (Last created dialog Button)
      • -------- ----------------- --------
      • Dialog - Show MyDialog for Player 1 (Red)
Create as many buttons as you need and store them in a variable so that you can refer to them later. Then, you need as many other triggers as you have difficulties to detect when somebody clicks on them:

  • Button Easy
    • Events
      • Dialog - A dialog button is clicked for MyDialog
    • Conditions
      • (Clicked dialog button) Equal to MyDialogButton[1]
    • Actions
      • Set VariableSet Difficulty = 0
      • -------- Your actions here --------
The variable "Difficulty" is just an example of how you can retrieve it in your trigger that creates your creeps. For instance you can do something like this:

  • Nerf HP
    • Events
      • Unit - A unit enters (Playable map area)
    • Conditions
      • (Owner of (Triggering unit)) Equal to Neutral Hostile
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Difficulty Equal to 0
        • Then - Actions
          • Unit - Set Max HP of (Triggering unit) to ((Max HP of (Triggering unit)) / 2)
        • Else - Actions
And all creeps would have 50% less health if the Easy button was selected
 
Level 3
Joined
Dec 30, 2020
Messages
19
Here's the basics of how you create a dialog:

  • Create
    • Events
      • Time - Elapsed game time is 5.00 seconds
    • Conditions
    • Actions
      • Dialog - Clear MyDialog
      • Dialog - Change the title of MyDialog to Select your difficu...
      • -------- ----------------- --------
      • Dialog - Create a dialog button for MyDialog labelled Easy
      • Set VariableSet MyDialogButton[1] = (Last created dialog Button)
      • -------- ----------------- --------
      • Dialog - Create a dialog button for MyDialog labelled Medium
      • Set VariableSet MyDialogButton[2] = (Last created dialog Button)
      • -------- ----------------- --------
      • Dialog - Create a dialog button for MyDialog labelled Hard
      • Set VariableSet MyDialogButton[3] = (Last created dialog Button)
      • -------- ----------------- --------
      • Dialog - Show MyDialog for Player 1 (Red)
Create as many buttons as you need and store them in a variable so that you can refer to them later. Then, you need as many other triggers as you have difficulties to detect when somebody clicks on them:

  • Button Easy
    • Events
      • Dialog - A dialog button is clicked for MyDialog
    • Conditions
      • (Clicked dialog button) Equal to MyDialogButton[1]
    • Actions
      • Set VariableSet Difficulty = 0
      • -------- Your actions here --------
The variable "Difficulty" is just an example of how you can retrieve it in your trigger that creates your creeps. For instance you can do something like this:

  • Nerf HP
    • Events
      • Unit - A unit enters (Playable map area)
    • Conditions
      • (Owner of (Triggering unit)) Equal to Neutral Hostile
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Difficulty Equal to 0
        • Then - Actions
          • Unit - Set Max HP of (Triggering unit) to ((Max HP of (Triggering unit)) / 2)
        • Else - Actions
And all creeps would have 50% less health if the Easy button was selected
Hey thanks for taking ur time to reply and sorry for the late reply didn't get any info that i got a message in here. Anyway I'm kind of lost what I'm suppose do with this one. I have created 4 Dialog variables and 3 dialog buttons but i cant seem to understand the (Last created dialog button) since i cant add the dialog buttons that i have created.
"Set VariableSet MyDialogButton[2] = (Last created dialog Button)"
 
Level 3
Joined
Dec 30, 2020
Messages
19
Hey thanks for taking ur time to reply and sorry for the late reply didn't get any info that i got a message in here. Anyway I'm kind of lost what I'm suppose do with this one. I have created 4 Dialog variables and 3 dialog buttons but i cant seem to understand the (Last created dialog button) since i cant add the dialog buttons that i have created.
Okey. so i think that was meant for the very first dialog. Went to try and the menu pops up (y)
 
Level 20
Joined
Aug 29, 2012
Messages
828
Make sure that they are the proper type

1681587756890.png
 
Level 3
Joined
Dec 30, 2020
Messages
19
Here's the basics of how you create a dialog:

  • Create
    • Events
      • Time - Elapsed game time is 5.00 seconds
    • Conditions
    • Actions
      • Dialog - Clear MyDialog
      • Dialog - Change the title of MyDialog to Select your difficu...
      • -------- ----------------- --------
      • Dialog - Create a dialog button for MyDialog labelled Easy
      • Set VariableSet MyDialogButton[1] = (Last created dialog Button)
      • -------- ----------------- --------
      • Dialog - Create a dialog button for MyDialog labelled Medium
      • Set VariableSet MyDialogButton[2] = (Last created dialog Button)
      • -------- ----------------- --------
      • Dialog - Create a dialog button for MyDialog labelled Hard
      • Set VariableSet MyDialogButton[3] = (Last created dialog Button)
      • -------- ----------------- --------
      • Dialog - Show MyDialog for Player 1 (Red)
Create as many buttons as you need and store them in a variable so that you can refer to them later. Then, you need as many other triggers as you have difficulties to detect when somebody clicks on them:

  • Button Easy
    • Events
      • Dialog - A dialog button is clicked for MyDialog
    • Conditions
      • (Clicked dialog button) Equal to MyDialogButton[1]
    • Actions
      • Set VariableSet Difficulty = 0
      • -------- Your actions here --------
The variable "Difficulty" is just an example of how you can retrieve it in your trigger that creates your creeps. For instance you can do something like this:

  • Nerf HP
    • Events
      • Unit - A unit enters (Playable map area)
    • Conditions
      • (Owner of (Triggering unit)) Equal to Neutral Hostile
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Difficulty Equal to 0
        • Then - Actions
          • Unit - Set Max HP of (Triggering unit) to ((Max HP of (Triggering unit)) / 2)
        • Else - Actions
And all creeps would have 50% less health if the Easy button was selected
Hey so i did everything in here and it WORKS so thank you so much for this but i do have 1 more question how do i make it that units get like 125% max up. Since i the "unit - set max hp of (triggering unit) to ((Max hp of (Triggering unit)) / 2 doesnt seem to do it. I cant find anyway to change number after the second max unit option.
 
Level 25
Joined
Sep 26, 2009
Messages
2,378
you could also use handicap which by default changes health of all player's units - existing and future ones.
Here are some relevant actions beside just handicap that could affect difficulty:
  • Actions
    • Set VariableSet handicapPlayer = Neutral Hostile
    • Player - Set handicapPlayer.Gold upkeep rate to 40 //will basically receive only 100-40 = 60% gold from gold mine
    • Player - Set handicapPlayer.Lumber upkeep rate to 40 //same but with harvesting lumber
    • Player - Set handicapPlayer handicap to 50.00% //affects health of all units including structures
    • Player - Make handicapPlayer's units deal 50.00% of normal damage //seems to affect both standard attacks as well as damage from spells
    • Hero - Make handicapPlayer Heroes' revive time rate to be 200.00% of normal rate //double the time to revive
    • Hero - Make handicapPlayer Heroes gain 50.00% experience from future kills //half XP from kills
While the description of 'Player - Set handicapPlayer handicap to 50.00%' actions says heroes are less affected by the handicap, so far that does not seem to be the case (at all levels a 50% handicap halved hero's health).
Also, for action 'Player - Make handicapPlayer's units deal 50.00% of normal damage' the UI will not get updated for some reason. So if a unit deals 40 damage at 100%, then you handicap it to 50%, the UI will still show that the unit will deal 40 damage, but the actual damage from the unit will be 20.

You can also turn this the other way around, for example setting
  • Player - Set handicapPlayer handicap to 200.00%
will double the hp of units, similar approach can be used for the other actions except for the gold and lumber upkeep rate - if the number is not between 0 and 99, then the player will not receive anything (even if gold in the gold mine will decrease and trees will be cut down). Also, you can't receive a fraction of gold, so setting gold upkeep rate to 99% will not give you 0.1 gold from 10 gold mined, it will get rounded down to 0 gold.


Edit:
For adding "something new to wave" - you would need to add logic to your triggers that spawn a wave to also check the value in 'Difficulty' variable Chaosy wrote about - then you could have something like
  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
    • If - Conditions
      • Difficulty Equal to 1
    • Then - Actions
      • -------- spawn additional unit --------
    • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Difficulty Equal to 2
        • Then - Actions
          • -------- spawn even more powerful unit than for difficulty 1 --------
        • Else - Actions
You could also add some abilities which require a tech to be researched.
For example imagine one of the wave units is a Death Knight - this unit could have two custom non-hero abilities - 'Death Pact' and 'Unholy Aura'.
The 'Death Pact' ability would require a tech called 'Hard Difficulty' and the 'Unholy Aura' would require a tech called 'Evil Difficulty'.
When you choose difficulty, you could have something like this in your trigger:
  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
    • If - Conditions
      • Difficulty Equal to 1
    • Then - Actions
      • Player - Set the current research level of Hard Difficulty to 1 for Player 1 (Red)
    • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Difficulty Equal to 2
        • Then - Actions
          • Player - Set the current research level of Evil Difficulty to 1 for Player 1 (Red)
        • Else - Actions
Or you could use a single tech with multiple levels which may scale even better:
  • Player - Set the current research level of Difficulty Tech to Difficulty for Player 1 (Red)
The good thing about techs is that they can for example increase movement speed of all units that use that tech, allow some spells when researched, etc.
Another good things about techs is that you could have just those X techs (one for each difficulty) or a single multi-level tech and then you would use that tech(s) as requirement for all your wave spells. You would not need any complicated triggers to determine which ability to add to what unit for which difficulty, instead the unit would have all its spells set in object editor, they would just be blocked by the tech and to allow the spells for given difficulty you would just research a single tech via triggers.
 
Last edited:
Level 3
Joined
Dec 30, 2020
Messages
19
you could also use handicap which by default changes health of all player's units - existing and future ones.
Here are some relevant actions beside just handicap that could affect difficulty:
  • Actions
    • Set VariableSet handicapPlayer = Neutral Hostile
    • Player - Set handicapPlayer.Gold upkeep rate to 40 //will basically receive only 100-40 = 60% gold from gold mine
    • Player - Set handicapPlayer.Lumber upkeep rate to 40 //same but with harvesting lumber
    • Player - Set handicapPlayer handicap to 50.00% //affects health of all units including structures
    • Player - Make handicapPlayer's units deal 50.00% of normal damage //seems to affect both standard attacks as well as damage from spells
    • Hero - Make handicapPlayer Heroes' revive time rate to be 200.00% of normal rate //double the time to revive
    • Hero - Make handicapPlayer Heroes gain 50.00% experience from future kills //half XP from kills
While the description of 'Player - Set handicapPlayer handicap to 50.00%' actions says heroes are less affected by the handicap, so far that does not seem to be the case (at all levels a 50% handicap halved hero's health).
Also, for action 'Player - Make handicapPlayer's units deal 50.00% of normal damage' the UI will not get updated for some reason. So if a unit deals 40 damage at 100%, then you handicap it to 50%, the UI will still show that the unit will deal 40 damage, but the actual damage from the unit will be 20.

You can also turn this the other way around, for example setting
  • Player - Set handicapPlayer handicap to 200.00%
will double the hp of units, similar approach can be used for the other actions except for the gold and lumber upkeep rate - if the number is not between 0 and 99, then the player will not receive anything (even if gold in the gold mine will decrease and trees will be cut down). Also, you can't receive a fraction of gold, so setting gold upkeep rate to 99% will not give you 0.1 gold from 10 gold mined, it will get rounded down to 0 gold.


Edit:
For adding "something new to wave" - you would need to add logic to your triggers that spawn a wave to also check the value in 'Difficulty' variable Chaosy wrote about - then you could have something like
  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
    • If - Conditions
      • Difficulty Equal to 1
    • Then - Actions
      • -------- spawn additional unit --------
    • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Difficulty Equal to 2
        • Then - Actions
          • -------- spawn even more powerful unit than for difficulty 1 --------
        • Else - Actions
You could also add some abilities which require a tech to be researched.
For example imagine one of the wave units is a Death Knight - this unit could have two custom non-hero abilities - 'Death Pact' and 'Unholy Aura'.
The 'Death Pact' ability would require a tech called 'Hard Difficulty' and the 'Unholy Aura' would require a tech called 'Evil Difficulty'.
When you choose difficulty, you could have something like this in your trigger:
  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
    • If - Conditions
      • Difficulty Equal to 1
    • Then - Actions
      • Player - Set the current research level of Hard Difficulty to 1 for Player 1 (Red)
    • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Difficulty Equal to 2
        • Then - Actions
          • Player - Set the current research level of Evil Difficulty to 1 for Player 1 (Red)
        • Else - Actions
Or you could use a single tech with multiple levels which may scale even better:
  • Player - Set the current research level of Difficulty Tech to Difficulty for Player 1 (Red)
The good thing about techs is that they can for example increase movement speed of all units that use that tech, allow some spells when researched, etc.
Another good things about techs is that you could have just those X techs (one for each difficulty) or a single multi-level tech and then you would use that tech(s) as requirement for all your wave spells. You would not need any complicated triggers to determine which ability to add to what unit for which difficulty, instead the unit would have all its spells set in object editor, they would just be blocked by the tech and to allow the spells for given difficulty you would just research a single tech via triggers.
Sir. I like your thinking and thank you for this
 
Level 3
Joined
Dec 30, 2020
Messages
19
you could also use handicap which by default changes health of all player's units - existing and future ones.
Here are some relevant actions beside just handicap that could affect difficulty:
  • Actions
    • Set VariableSet handicapPlayer = Neutral Hostile
    • Player - Set handicapPlayer.Gold upkeep rate to 40 //will basically receive only 100-40 = 60% gold from gold mine
    • Player - Set handicapPlayer.Lumber upkeep rate to 40 //same but with harvesting lumber
    • Player - Set handicapPlayer handicap to 50.00% //affects health of all units including structures
    • Player - Make handicapPlayer's units deal 50.00% of normal damage //seems to affect both standard attacks as well as damage from spells
    • Hero - Make handicapPlayer Heroes' revive time rate to be 200.00% of normal rate //double the time to revive
    • Hero - Make handicapPlayer Heroes gain 50.00% experience from future kills //half XP from kills
While the description of 'Player - Set handicapPlayer handicap to 50.00%' actions says heroes are less affected by the handicap, so far that does not seem to be the case (at all levels a 50% handicap halved hero's health).
Also, for action 'Player - Make handicapPlayer's units deal 50.00% of normal damage' the UI will not get updated for some reason. So if a unit deals 40 damage at 100%, then you handicap it to 50%, the UI will still show that the unit will deal 40 damage, but the actual damage from the unit will be 20.

You can also turn this the other way around, for example setting
  • Player - Set handicapPlayer handicap to 200.00%
will double the hp of units, similar approach can be used for the other actions except for the gold and lumber upkeep rate - if the number is not between 0 and 99, then the player will not receive anything (even if gold in the gold mine will decrease and trees will be cut down). Also, you can't receive a fraction of gold, so setting gold upkeep rate to 99% will not give you 0.1 gold from 10 gold mined, it will get rounded down to 0 gold.


Edit:
For adding "something new to wave" - you would need to add logic to your triggers that spawn a wave to also check the value in 'Difficulty' variable Chaosy wrote about - then you could have something like
  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
    • If - Conditions
      • Difficulty Equal to 1
    • Then - Actions
      • -------- spawn additional unit --------
    • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Difficulty Equal to 2
        • Then - Actions
          • -------- spawn even more powerful unit than for difficulty 1 --------
        • Else - Actions
You could also add some abilities which require a tech to be researched.
For example imagine one of the wave units is a Death Knight - this unit could have two custom non-hero abilities - 'Death Pact' and 'Unholy Aura'.
The 'Death Pact' ability would require a tech called 'Hard Difficulty' and the 'Unholy Aura' would require a tech called 'Evil Difficulty'.
When you choose difficulty, you could have something like this in your trigger:
  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
    • If - Conditions
      • Difficulty Equal to 1
    • Then - Actions
      • Player - Set the current research level of Hard Difficulty to 1 for Player 1 (Red)
    • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Difficulty Equal to 2
        • Then - Actions
          • Player - Set the current research level of Evil Difficulty to 1 for Player 1 (Red)
        • Else - Actions
Or you could use a single tech with multiple levels which may scale even better:
  • Player - Set the current research level of Difficulty Tech to Difficulty for Player 1 (Red)
The good thing about techs is that they can for example increase movement speed of all units that use that tech, allow some spells when researched, etc.
Another good things about techs is that you could have just those X techs (one for each difficulty) or a single multi-level tech and then you would use that tech(s) as requirement for all your wave spells. You would not need any complicated triggers to determine which ability to add to what unit for which difficulty, instead the unit would have all its spells set in object editor, they would just be blocked by the tech and to allow the spells for given difficulty you would just research a single tech via triggers.
  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
    • If - Conditions
      • Difficulty Equal to 1
    • Then - Actions
      • -------- spawn additional unit --------
    • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Difficulty Equal to 2
        • Then - Actions
          • -------- spawn even more powerful unit than for difficulty 1 --------
        • Else - Actions
 
Level 3
Joined
Dec 30, 2020
Messages
19
  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
    • If - Conditions
      • Difficulty Equal to 1
    • Then - Actions
      • -------- spawn additional unit --------
    • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Difficulty Equal to 2
        • Then - Actions
          • -------- spawn even more powerful unit than for difficulty 1 --------
        • Else - Actions
I dont know how to use this site anymore my lord. So anyway how would i be able to do this part?
 
Level 25
Joined
Sep 26, 2009
Messages
2,378
I dont know how to use this site anymore my lord. So anyway how would i be able to do this part?
Well, it's hard to give you an example, as it depends on how you spawn wave in the triggers in your own map, so what I will show you may not necessarily be applicable in your triggers.
But let's assume that the following (very simplified) trigger is what you use to spawn waves:
  • Spawn Wave
    • Events
      • Time - SpawnWaveTimer expires
    • Conditions
    • Actions
      • Set VariableSet CurrentWaveNumber = (CurrentWaveNumber + 1)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • CurrentWaveNumber Equal to 1
        • Then - Actions
          • Unit - Create 10 Footman for Player 24 (Peanut) at (Center of WaveSpawnPoint) facing Default building facing degrees
          • Set VariableSet WaveGroup = (Last created unit group)
        • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • CurrentWaveNumber Equal to 2
        • Then - Actions
          • Unit - Create 10 Rifleman for Player 24 (Peanut) at (Center of WaveSpawnPoint) facing Default building facing degrees
          • Set VariableSet WaveGroup = (Last created unit group)
        • Else - Actions
      • Unit Group - Order WaveGroup to Move To (Center of WaveTargets[1])
In this trigger, wave #1 will spawn 10 footmen while wave #2 will spawn 10 riflemen and order them to move to 'WaveTargets[1]'.
If you wanted to spawn some additional types of units based on the difficulty, you could add nested If/Then/Else in each wave to spawn additional units:

  • Spawn Wave
    • Events
      • Time - SpawnWaveTimer expires
    • Conditions
    • Actions
      • Set VariableSet CurrentWaveNumber = (CurrentWaveNumber + 1)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • CurrentWaveNumber Equal to 1
        • Then - Actions
          • Unit - Create 10 Footman for Player 24 (Peanut) at (Center of WaveSpawnPoint) facing Default building facing degrees
          • Set VariableSet WaveGroup = (Last created unit group)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Difficulty Equal to 1
            • Then - Actions
              • Unit - Create 5 Spellbreaker for Player 24 (Peanut) at (Center of WaveSpawnPoint) facing Default building facing degrees
              • Unit Group - Add all units of (Last created unit group) to WaveGroup
            • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • Difficulty Equal to 2
                • Then - Actions
                  • Unit - Create 5 Knight for Player 24 (Peanut) at (Center of WaveSpawnPoint) facing Default building facing degrees
                  • Unit Group - Add all units of (Last created unit group) to WaveGroup
                • Else - Actions
        • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • CurrentWaveNumber Equal to 2
        • Then - Actions
          • Unit - Create 10 Rifleman for Player 24 (Peanut) at (Center of WaveSpawnPoint) facing Default building facing degrees
          • Set VariableSet WaveGroup = (Last created unit group)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Difficulty Equal to 1
            • Then - Actions
              • Unit - Create 5 Mortar Team for Player 24 (Peanut) at (Center of WaveSpawnPoint) facing Default building facing degrees
              • Unit Group - Add all units of (Last created unit group) to WaveGroup
            • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • Difficulty Equal to 2
                • Then - Actions
                  • Unit - Create 5 Siege Engine for Player 24 (Peanut) at (Center of WaveSpawnPoint) facing Default building facing degrees
                  • Unit Group - Add all units of (Last created unit group) to WaveGroup
                • Else - Actions
        • Else - Actions
      • Unit Group - Order WaveGroup to Move To (Center of WaveTargets[1])
So in the example above, for wave #1 if difficulty is set to '1', then additional 5 spell breakers will be spawned, if difficulty is set to '2', then 5 additional knights will be spawned instead.
But you can see that this can bloat your entire trigger by a lot - in the example I had only 3 difficulties (0-2) and 2 waves and you can see how big the trigger got (not to mention I am not cleaning up any memory leaks, which would bloat the trigger even more).

A more optimized way of doing things would be to use the power of arrays where you set up the unit types. The below triggers will achieve the same as the one above, but will scale better with more waves and difficulties:

  • Map Initialization
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Set VariableSet MaxDifficulty = 2
      • -------- ---------------------------------------------------------------------- --------
      • -------- Set the creep-types that always spawn per wave. The array index matches the wave number --------
      • Set VariableSet BaseWaveCreeps[1] = Footman
      • Set VariableSet BaseWaveCreeps[2] = Rifleman
      • -------- ---------------------------------------------------------------------- --------
      • -------- Set additional creep-types per difficulty --------
      • -------- This uses "(wave_number - 1) * maxDifficulty" as offset in the array --------
      • -------- so if maxDifficulty = 2, then for wave #1 the offset is 0 --------
      • -------- and bonus creeps for wave #1 are under indices 1 and 2 --------
      • -------- for wave #2 it would be indices 3 and 4, etc. --------
      • Set VariableSet BonusWaveCreeps[1] = Spellbreaker
      • Set VariableSet BonusWaveCreeps[2] = Knight
      • Set VariableSet BonusWaveCreeps[3] = Mortar Team
      • Set VariableSet BonusWaveCreeps[4] = Siege Engine
  • Spawn Wave 2
    • Events
      • Time - SpawnWaveTimer expires
    • Conditions
    • Actions
      • Set VariableSet CurrentWaveNumber = (CurrentWaveNumber + 1)
      • Unit - Create 10 BaseWaveCreeps[CurrentWaveNumber] for Player 24 (Peanut) at (Center of WaveSpawnPoint) facing Default building facing degrees
      • Set VariableSet WaveGroup = (Last created unit group)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Difficulty Greater than 0
        • Then - Actions
          • -------- If difficulty = 1, then this will result to 1 for wave #1 (spell breaker) or 3 for wave #2 (mortar team) --------
          • -------- If difficulty = 2, then this will result to 2 for wave #1 (knight) or 4 for wave #2 (siege engine) --------
          • Set VariableSet BonusWaveIndex = (((CurrentWaveNumber - 1) x MaxDifficulty) + Difficulty)
          • Unit - Create 5 BonusWaveCreeps[BonusWaveIndex] for Player 24 (Peanut) at (Center of WaveSpawnPoint) facing Default building facing degrees
          • Unit Group - Add all units of (Last created unit group) to WaveGroup
        • Else - Actions
      • Unit Group - Order WaveGroup to Move To (Center of WaveTargets[1])
 
Level 3
Joined
Dec 30, 2020
Messages
19
Well, it's hard to give you an example, as it depends on how you spawn wave in the triggers in your own map, so what I will show you may not necessarily be applicable in your triggers.
But let's assume that the following (very simplified) trigger is what you use to spawn waves:
  • Spawn Wave
    • Events
      • Time - SpawnWaveTimer expires
    • Conditions
    • Actions
      • Set VariableSet CurrentWaveNumber = (CurrentWaveNumber + 1)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • CurrentWaveNumber Equal to 1
        • Then - Actions
          • Unit - Create 10 Footman for Player 24 (Peanut) at (Center of WaveSpawnPoint) facing Default building facing degrees
          • Set VariableSet WaveGroup = (Last created unit group)
        • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • CurrentWaveNumber Equal to 2
        • Then - Actions
          • Unit - Create 10 Rifleman for Player 24 (Peanut) at (Center of WaveSpawnPoint) facing Default building facing degrees
          • Set VariableSet WaveGroup = (Last created unit group)
        • Else - Actions
      • Unit Group - Order WaveGroup to Move To (Center of WaveTargets[1])
In this trigger, wave #1 will spawn 10 footmen while wave #2 will spawn 10 riflemen and order them to move to 'WaveTargets[1]'.
If you wanted to spawn some additional types of units based on the difficulty, you could add nested If/Then/Else in each wave to spawn additional units:

  • Spawn Wave
    • Events
      • Time - SpawnWaveTimer expires
    • Conditions
    • Actions
      • Set VariableSet CurrentWaveNumber = (CurrentWaveNumber + 1)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • CurrentWaveNumber Equal to 1
        • Then - Actions
          • Unit - Create 10 Footman for Player 24 (Peanut) at (Center of WaveSpawnPoint) facing Default building facing degrees
          • Set VariableSet WaveGroup = (Last created unit group)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Difficulty Equal to 1
            • Then - Actions
              • Unit - Create 5 Spellbreaker for Player 24 (Peanut) at (Center of WaveSpawnPoint) facing Default building facing degrees
              • Unit Group - Add all units of (Last created unit group) to WaveGroup
            • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • Difficulty Equal to 2
                • Then - Actions
                  • Unit - Create 5 Knight for Player 24 (Peanut) at (Center of WaveSpawnPoint) facing Default building facing degrees
                  • Unit Group - Add all units of (Last created unit group) to WaveGroup
                • Else - Actions
        • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • CurrentWaveNumber Equal to 2
        • Then - Actions
          • Unit - Create 10 Rifleman for Player 24 (Peanut) at (Center of WaveSpawnPoint) facing Default building facing degrees
          • Set VariableSet WaveGroup = (Last created unit group)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Difficulty Equal to 1
            • Then - Actions
              • Unit - Create 5 Mortar Team for Player 24 (Peanut) at (Center of WaveSpawnPoint) facing Default building facing degrees
              • Unit Group - Add all units of (Last created unit group) to WaveGroup
            • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • Difficulty Equal to 2
                • Then - Actions
                  • Unit - Create 5 Siege Engine for Player 24 (Peanut) at (Center of WaveSpawnPoint) facing Default building facing degrees
                  • Unit Group - Add all units of (Last created unit group) to WaveGroup
                • Else - Actions
        • Else - Actions
      • Unit Group - Order WaveGroup to Move To (Center of WaveTargets[1])
So in the example above, for wave #1 if difficulty is set to '1', then additional 5 spell breakers will be spawned, if difficulty is set to '2', then 5 additional knights will be spawned instead.
But you can see that this can bloat your entire trigger by a lot - in the example I had only 3 difficulties (0-2) and 2 waves and you can see how big the trigger got (not to mention I am not cleaning up any memory leaks, which would bloat the trigger even more).

A more optimized way of doing things would be to use the power of arrays where you set up the unit types. The below triggers will achieve the same as the one above, but will scale better with more waves and difficulties:

  • Map Initialization
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Set VariableSet MaxDifficulty = 2
      • -------- ---------------------------------------------------------------------- --------
      • -------- Set the creep-types that always spawn per wave. The array index matches the wave number --------
      • Set VariableSet BaseWaveCreeps[1] = Footman
      • Set VariableSet BaseWaveCreeps[2] = Rifleman
      • -------- ---------------------------------------------------------------------- --------
      • -------- Set additional creep-types per difficulty --------
      • -------- This uses "(wave_number - 1) * maxDifficulty" as offset in the array --------
      • -------- so if maxDifficulty = 2, then for wave #1 the offset is 0 --------
      • -------- and bonus creeps for wave #1 are under indices 1 and 2 --------
      • -------- for wave #2 it would be indices 3 and 4, etc. --------
      • Set VariableSet BonusWaveCreeps[1] = Spellbreaker
      • Set VariableSet BonusWaveCreeps[2] = Knight
      • Set VariableSet BonusWaveCreeps[3] = Mortar Team
      • Set VariableSet BonusWaveCreeps[4] = Siege Engine
  • Spawn Wave 2
    • Events
      • Time - SpawnWaveTimer expires
    • Conditions
    • Actions
      • Set VariableSet CurrentWaveNumber = (CurrentWaveNumber + 1)
      • Unit - Create 10 BaseWaveCreeps[CurrentWaveNumber] for Player 24 (Peanut) at (Center of WaveSpawnPoint) facing Default building facing degrees
      • Set VariableSet WaveGroup = (Last created unit group)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Difficulty Greater than 0
        • Then - Actions
          • -------- If difficulty = 1, then this will result to 1 for wave #1 (spell breaker) or 3 for wave #2 (mortar team) --------
          • -------- If difficulty = 2, then this will result to 2 for wave #1 (knight) or 4 for wave #2 (siege engine) --------
          • Set VariableSet BonusWaveIndex = (((CurrentWaveNumber - 1) x MaxDifficulty) + Difficulty)
          • Unit - Create 5 BonusWaveCreeps[BonusWaveIndex] for Player 24 (Peanut) at (Center of WaveSpawnPoint) facing Default building facing degrees
          • Unit Group - Add all units of (Last created unit group) to WaveGroup
        • Else - Actions
      • Unit Group - Order WaveGroup to Move To (Center of WaveTargets[1])
Took me literally 4-5h to understand this since im garbage at triggers but now i got everything working. Thank you so much for this It's huge help for the waves!
 
Status
Not open for further replies.
Top