I need to spawn a random number of units but i want to customize it so i don't need to use random integer, this is how my trigger is set up now.
Events
Unit - Any Unit Enters Goliath DMG Region
Actions
General - If (Conditions) then do (Actions) else do (Actions)
If
And
Conditions
(Number of Living units in ((Unit type of (Triggering unit)) units in Goliath DMG Region owned by player (Owner of (Triggering unit)) matching Excluded: Missile, Dead, Hidden, with at most Any Amount)) >= 2
Then
Unit Group - Pick each unit in ((Unit type of (Triggering unit)) units in (Triggering region) owned by player (Triggering player) matching Excluded: Missile, Dead, Hidden, with at most 2) and do (Actions)
Actions
Unit - Kill (Picked unit)
Unit - Create (Random integer between 1 and 4) Goliath DMG for player (Triggering player) at (Start location of player (Triggering player)) facing 270.0 degrees (No Options)
Random integer works but it spawns to much units.So i want to spawn more units less of the time and less units more of the time. Is this possible?
First of all, I'd much rather use a local variable to deal with that unit group, but that's just personal preference. :)
I'm confused by your question, but if I'm correct you want there to be a higher chance to spawn 1-3 units, and a lower chance to spawn 4-8 units. (or any combination..)
What you could do, for full customization, is create a local real variable that creates a random real between 0.0 and 100.0. You then evaluate the real number that's been randomly generated to create a set amount of units. The trigger would states, after "Unit - Kill (Picked unit)", another If Then Else-If action, where you could have these conditions, as an example:
IF localrealvariable < 20.0 THEN Create 5 Goliath DMG for player (...)
IF localrealvariable >= 20.0 AND localrealvariable < 50.0 THEN Create 3 Goliath DMG for player (...)
IF localrealvariable >= 50.0 AND localrealvariable <= 100.0 THEN Create 1 Goliath DMG for player (...)
Hope you understand. What you could also do, is make a quick formula. Because formulas are cute.
For example, create another random variable, from 0.0 to 90.0, then create (round(10-(sqr^randomvariable)) units. You will see that if
random variable = 5 then units created will be 8.
random variable = 25 then units created will be 5.
random variable = 50 then units created will be 3. (so half the time units created will be less than 4)
random variable = 75 then units created will be 1.
random variable = 90 then units created will be 1. (above 90 would make the result less than 1, which I don't believe you want)
You can tweak the formula to your liking. But that's just because I like formulas. In fact, I suggest the above example for you to use :P
Thank you so much! Yeah the second method does seem a bit easier but the first method seems to have more customization, I'm probably going to try out both ways just because I'm still new to the editor and need practice :) Thanks again for the well explained answer.
Rollback Post to RevisionRollBack
To post a comment, please login or register a new account.
I need to spawn a random number of units but i want to customize it so i don't need to use random integer, this is how my trigger is set up now.
Events
Unit - Any Unit Enters Goliath DMG Region
Actions
General - If (Conditions) then do (Actions) else do (Actions)
If
And
Conditions
(Number of Living units in ((Unit type of (Triggering unit)) units in Goliath DMG Region owned by player (Owner of (Triggering unit)) matching Excluded: Missile, Dead, Hidden, with at most Any Amount)) >= 2
Then
Unit Group - Pick each unit in ((Unit type of (Triggering unit)) units in (Triggering region) owned by player (Triggering player) matching Excluded: Missile, Dead, Hidden, with at most 2) and do (Actions)
Actions
Unit - Kill (Picked unit)
Unit - Create (Random integer between 1 and 4) Goliath DMG for player (Triggering player) at (Start location of player (Triggering player)) facing 270.0 degrees (No Options)
Random integer works but it spawns to much units.So i want to spawn more units less of the time and less units more of the time. Is this possible?
a big thanks in advance!
First of all, I'd much rather use a local variable to deal with that unit group, but that's just personal preference. :)
I'm confused by your question, but if I'm correct you want there to be a higher chance to spawn 1-3 units, and a lower chance to spawn 4-8 units. (or any combination..)
What you could do, for full customization, is create a local real variable that creates a random real between 0.0 and 100.0. You then evaluate the real number that's been randomly generated to create a set amount of units. The trigger would states, after "Unit - Kill (Picked unit)", another If Then Else-If action, where you could have these conditions, as an example: IF localrealvariable < 20.0 THEN Create 5 Goliath DMG for player (...) IF localrealvariable >= 20.0 AND localrealvariable < 50.0 THEN Create 3 Goliath DMG for player (...) IF localrealvariable >= 50.0 AND localrealvariable <= 100.0 THEN Create 1 Goliath DMG for player (...)
Hope you understand. What you could also do, is make a quick formula. Because formulas are cute.
For example, create another random variable, from 0.0 to 90.0, then create (round(10-(sqr^randomvariable)) units. You will see that if random variable = 5 then units created will be 8. random variable = 25 then units created will be 5. random variable = 50 then units created will be 3. (so half the time units created will be less than 4) random variable = 75 then units created will be 1. random variable = 90 then units created will be 1. (above 90 would make the result less than 1, which I don't believe you want)
You can tweak the formula to your liking. But that's just because I like formulas. In fact, I suggest the above example for you to use :P
@XGDragon: Go
Thank you so much! Yeah the second method does seem a bit easier but the first method seems to have more customization, I'm probably going to try out both ways just because I'm still new to the editor and need practice :) Thanks again for the well explained answer.