• 🏆 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] Trigger question

Status
Not open for further replies.
Level 7
Joined
Feb 23, 2020
Messages
253
Hello guys, how do i make a trigger like this only being able to create 1 unit every 5 seconds. At this point the number on every "random integer number" could be less than 60, which would create 3 units. Which is something that i dont want too happen.

  • Draenei Spawn
    • Events
      • Time - Every 5.00 seconds of game time
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Random integer number between 1 and 100) Less than or equal to 80
        • Then - Actions
          • Unit - Create 1 Draenei Warrior (1) for Player 7 (Green) at (Center of Draenei Spawn <gen>) facing Default building facing degrees
        • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Random integer number between 1 and 100) Less than or equal to 70
        • Then - Actions
          • Unit - Create 1 Draenei Disciple (2) for Player 7 (Green) at (Center of Draenei Spawn <gen>) facing Default building facing degrees
        • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Random integer number between 1 and 100) Less than or equal to 60
        • Then - Actions
          • Unit - Create 1 Draenei Fighter (3) for Player 7 (Green) at (Center of Draenei Spawn <gen>) facing Default building facing degrees
        • Else - Actions
 

Uncle

Warcraft Moderator
Level 63
Joined
Aug 10, 2018
Messages
6,457
  • Untitled Trigger 001
    • Events
      • Time - Every 5.00 seconds of game time
    • Conditions
    • Actions
      • Set VariableSet RandomNumber = (Random integer number between 1 and 100)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • RandomNumber Less than 60
        • Then - Actions
          • Set VariableSet TempPoint = (Center of (Playable map area))
          • Unit - Create 1 Footman for Player 1 (Red) at TempPoint facing Default building facing degrees
          • Custom script: call RemoveLocation (udg_TempPoint)
        • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • RandomNumber Greater than or equal to 60
              • RandomNumber Less than 90
            • Then - Actions
              • Set VariableSet TempPoint = (Center of (Playable map area))
              • Unit - Create 1 Rifleman for Player 1 (Red) at TempPoint facing Default building facing degrees
              • Custom script: call RemoveLocation (udg_TempPoint)
            • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • RandomNumber Greater than or equal to 90
                • Then - Actions
                  • Set VariableSet TempPoint = (Center of (Playable map area))
                  • Unit - Create 1 Knight for Player 1 (Red) at TempPoint facing Default building facing degrees
                  • Custom script: call RemoveLocation (udg_TempPoint)
                • Else - Actions
Make sure to take advantage of the Else - Actions in your If Then Else statements. This is how you can structure your trigger so that only 1 of the If Then Else statements will occur at a time. It also helps with performance since the rest of the Else - Actions are ignored once one set of Conditions are True.

Also, you probably want to adjust the numbers so that you guarantee that a unit will spawn. I did this in my example, there's a 60% chance for a Footman, 30% chance for a Rifleman, and 10% chance for a Knight.

TempPoint is used to prevent a Memory Leak. This helps with map performance. You can read more about this by clicking the link in my signature -> Things That Leak.

And to get super optimal (not a big deal), you can even delete the condition "RandomNumber Greater than or equal to 90" in our last If Then Else since it's the only possible option left.
 
Last edited:
Level 7
Joined
Feb 23, 2020
Messages
253
  • Untitled Trigger 001
    • Events
      • Time - Every 5.00 seconds of game time
    • Conditions
    • Actions
      • Set VariableSet RandomNumber = (Random integer number between 1 and 100)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • RandomNumber Less than 60
        • Then - Actions
          • Set VariableSet TempPoint = (Center of (Playable map area))
          • Unit - Create 1 Footman for Player 1 (Red) at TempPoint facing Default building facing degrees
          • Custom script: call RemoveLocation (udg_TempPoint)
        • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • RandomNumber Greater than or equal to 60
              • RandomNumber Less than 90
            • Then - Actions
              • Set VariableSet TempPoint = (Center of (Playable map area))
              • Unit - Create 1 Rifleman for Player 1 (Red) at TempPoint facing Default building facing degrees
              • Custom script: call RemoveLocation (udg_TempPoint)
            • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • RandomNumber Greater than or equal to 90
                • Then - Actions
                  • Set VariableSet TempPoint = (Center of (Playable map area))
                  • Unit - Create 1 Knight for Player 1 (Red) at TempPoint facing Default building facing degrees
                  • Custom script: call RemoveLocation (udg_TempPoint)
                • Else - Actions
Make sure to take advantage of the Else - Actions in your If Then Else statements. This is how you can structure your trigger so that only 1 of the If Then Else statements will occur at a time. It also helps with performance since the rest of the Else - Actions are ignored once one set of Conditions are True.

Also, you probably want to adjust the numbers so that you guarantee that a unit will spawn. I did this in my example, there's a 60% chance for a Footman, 30% chance for a Rifleman, and 10% chance for a Knight.

TempPoint is used to prevent a Memory Leak. This helps with map performance. You can read more about this by clicking the link in my signature -> Things That Leak.

And to get super optimal (not a big deal), you can even delete the condition "RandomNumber Greater than or equal to 90" in our last If Then Else since it's the only possible option left.


Okay i see, this helped me a lot, thank you mate!

Altough, does it get more tricky if i want to use more units like this?

  • Draenei Spawn
    • Events
      • Time - Every 5.00 seconds of game time
    • Conditions
    • Actions
      • Set VariableSet RandomNumber = (Random integer number between 1 and 100)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • RandomNumber Less than 80
        • Then - Actions
          • Set VariableSet MonsterSpawnPoint[1] = (Center of Draenei Spawn <gen>)
          • Unit - Create 1 Draenei Warrior (1) for Player 7 (Green) at (Center of Draenei Spawn <gen>) facing Default building facing degrees
          • Custom script: call RemoveLocation(udg_MonsterSpawnPoint[1])
        • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • RandomNumber Less than 70
            • Then - Actions
              • Set VariableSet MonsterSpawnPoint[1] = (Center of Draenei Spawn <gen>)
              • Unit - Create 1 Draenei Disciple (2) for Player 7 (Green) at (Center of Draenei Spawn <gen>) facing Default building facing degrees
              • Custom script: call RemoveLocation(udg_MonsterSpawnPoint[1])
            • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • RandomNumber Less than 70
                • Then - Actions
                  • Set VariableSet MonsterSpawnPoint[1] = (Center of Draenei Spawn <gen>)
                  • Unit - Create 1 Draenei Fighter (3) for Player 7 (Green) at (Center of Draenei Spawn <gen>) facing Default building facing degrees
                  • Custom script: call RemoveLocation(udg_MonsterSpawnPoint[1])
                • Else - Actions
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • RandomNumber Less than 70
                    • Then - Actions
                      • Set VariableSet MonsterSpawnPoint[1] = (Center of Draenei Spawn <gen>)
                      • Unit - Create 1 Draenei Watcher (4) for Player 7 (Green) at (Center of Draenei Spawn <gen>) facing Default building facing degrees
                      • Custom script: call RemoveLocation(udg_MonsterSpawnPoint[1])
                    • Else - Actions
                      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                        • If - Conditions
                          • RandomNumber Less than 70
                        • Then - Actions
                          • Set VariableSet MonsterSpawnPoint[1] = (Center of Draenei Spawn <gen>)
                          • Unit - Create 1 Draenei Darkslayer (5) for Player 7 (Green) at (Center of Draenei Spawn <gen>) facing Default building facing degrees
                          • Custom script: call RemoveLocation(udg_MonsterSpawnPoint[1])
                        • Else - Actions
                          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                            • If - Conditions
                              • RandomNumber Less than 70
                            • Then - Actions
                              • Set VariableSet MonsterSpawnPoint[1] = (Center of Draenei Spawn <gen>)
                              • Unit - Create 1 Draenei Harbinger (6) for Player 7 (Green) at (Center of Draenei Spawn <gen>) facing Default building facing degrees
                              • Custom script: call RemoveLocation(udg_MonsterSpawnPoint[1])
                            • Else - Actions
                              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                                • If - Conditions
                                  • RandomNumber Greater than or equal to 90
                                • Then - Actions
                                  • Set VariableSet MonsterSpawnPoint[1] = (Center of Draenei Spawn <gen>)
                                  • Unit - Create 1 Draenei Assassin (7) for Player 7 (Green) at (Center of Draenei Spawn <gen>) facing Default building facing degrees
                                  • Custom script: call RemoveLocation(udg_MonsterSpawnPoint[1])
                                • Else - Actions
Note, i did not change the number of the RandomNumber yet. And i want it to be from 80-20% spawn chance of the units. So 80, 70, 60, 50, 40, 30 and 20% chance of certain units to spawn.
 
Last edited:

Uncle

Warcraft Moderator
Level 63
Joined
Aug 10, 2018
Messages
6,457
That's perfectly fine, but with my setup you will need to give each spawn a fraction of 100%. Their chances need to always add up to 100%.

It looks like you probably want to do something more like this:
  • Actions
    • Set VariableSet TempPoint = (Center of (Playable map area))
    • Set VariableSet RandomNumber = (Random integer number between 1 and 100)
    • -------- --------
    • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
      • If - Conditions
        • RandomNumber Less than or equal to 60
      • Then - Actions
        • Set VariableSet RandomNumber = (Random integer number between 1 and 3)
        • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
          • If - Conditions
            • RandomNumber Equal to 1
          • Then - Actions
            • Unit - Create 1 Footman for Player 1 (Red) at TempPoint facing Default building facing degrees
          • Else - Actions
            • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
              • If - Conditions
                • RandomNumber Equal to 2
              • Then - Actions
                • Unit - Create 1 Rifleman for Player 1 (Red) at TempPoint facing Default building facing degrees
              • Else - Actions
                • Unit - Create 1 Knight for Player 1 (Red) at TempPoint facing Default building facing degrees
      • Else - Actions
        • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
          • If - Conditions
            • RandomNumber Less than or equal to 90
          • Then - Actions
            • Set VariableSet RandomNumber = (Random integer number between 1 and 2)
            • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
              • If - Conditions
                • RandomNumber Equal to 1
              • Then - Actions
                • Unit - Create 1 Flying Machine for Player 1 (Red) at TempPoint facing Default building facing degrees
              • Else - Actions
                • Unit - Create 1 Dragonhawk Rider for Player 1 (Red) at TempPoint facing Default building facing degrees
          • Else - Actions
            • Unit - Create 1 Gryphon Rider for Player 1 (Red) at TempPoint facing Default building facing degrees
    • -------- --------
    • Custom script: call RemoveLocation (udg_TempPoint)
I break the units up into "groups".

So there's a 60% chance to spawn a:
Footman, Rifleman, or Knight

A 30% chance to spawn a:
Flying Machine or Dragonhawk Rider

And a 10% chance to spawn a:
Gryphon Rider

Note that if all of the units are going to spawn at the same place then you only need to set TempPoint once at the start of the trigger. This helps keep the trigger clean and organized.
 
Level 7
Joined
Feb 23, 2020
Messages
253
That's perfectly fine, but with my setup you will need to give each spawn a fraction of 100%. Their chances need to always add up to 100%.

It looks like you probably want to do something more like this:
  • Actions
    • Set VariableSet TempPoint = (Center of (Playable map area))
    • Set VariableSet RandomNumber = (Random integer number between 1 and 100)
    • -------- --------
    • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
      • If - Conditions
        • RandomNumber Less than or equal to 60
      • Then - Actions
        • Set VariableSet RandomNumber = (Random integer number between 1 and 3)
        • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
          • If - Conditions
            • RandomNumber Equal to 1
          • Then - Actions
            • Unit - Create 1 Footman for Player 1 (Red) at TempPoint facing Default building facing degrees
          • Else - Actions
            • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
              • If - Conditions
                • RandomNumber Equal to 2
              • Then - Actions
                • Unit - Create 1 Rifleman for Player 1 (Red) at TempPoint facing Default building facing degrees
              • Else - Actions
                • Unit - Create 1 Knight for Player 1 (Red) at TempPoint facing Default building facing degrees
      • Else - Actions
        • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
          • If - Conditions
            • RandomNumber Less than or equal to 90
          • Then - Actions
            • Set VariableSet RandomNumber = (Random integer number between 1 and 2)
            • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
              • If - Conditions
                • RandomNumber Equal to 1
              • Then - Actions
                • Unit - Create 1 Flying Machine for Player 1 (Red) at TempPoint facing Default building facing degrees
              • Else - Actions
                • Unit - Create 1 Dragonhawk Rider for Player 1 (Red) at TempPoint facing Default building facing degrees
          • Else - Actions
            • Unit - Create 1 Gryphon Rider for Player 1 (Red) at TempPoint facing Default building facing degrees
    • -------- --------
    • Custom script: call RemoveLocation (udg_TempPoint)
I break the units up into "groups".

So there's a 60% chance to spawn a:
Footman, Rifleman, or Knight

A 30% chance to spawn a:
Flying Machine or Dragonhawk Rider

And a 10% chance to spawn a:
Gryphon Rider

Note that if all of the units are going to spawn at the same place then you only need to set TempPoint once at the start of the trigger. This helps keep the trigger clean and organized.

I understand, thank you very much! This solved my problem :)
 
Status
Not open for further replies.
Top