# [Solved] Trigger question

Discussion in 'World Editor Help Zone' started by Xzere, Oct 9, 2020.

Tags:
1. ### Xzere

Joined:
Feb 23, 2020
Messages:
152
Resources:
0
Resources:
0
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

2. ### Uncle

Joined:
Aug 10, 2018
Messages:
2,471
Resources:
0
Resources:
0
• 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: Oct 9, 2020
3. ### Xzere

Joined:
Feb 23, 2020
Messages:
152
Resources:
0
Resources:
0

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: Oct 9, 2020
4. ### Uncle

Joined:
Aug 10, 2018
Messages:
2,471
Resources:
0
Resources:
0
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.

5. ### Xzere

Joined:
Feb 23, 2020
Messages:
152
Resources:
0
Resources:
0
I understand, thank you very much! This solved my problem