Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
lets say i put the trigger
random number from 1-4
or any numbers
is there a way to prevent it from selecting the same # twice when i roll 8 times or so?
You need a boolean array variable to indicate if number[#] has already been selected.
Then you can use a simple code to get a non-selected number:
Custom script: loop
Set RandomInteger = Random number between 1 and 4
Custom script: exitwhen not udg_Selected[udg_RandomInteger]
Custom script: endloop
Set Selected[tmpInteger] = true
This loop will continue until Selected[tmpInteger] is false, and select a random number for tmpInteger every execution.
After a number is successfuly selected, the number will be marked as selected. That is, Selected[tmpInteger] will be set to true.
Note that if all the numbers have already been selected it will get into an inifine loop and halt the trigger, and possibly cause lags if too many infinite loops are created...
I believe exitwhen scripts will end the entire trigger. You'll use If/Then/Else triggers with a RANDOM variable, so add as Then - Action 'Set PreviousNumber = x', where x is the same number as the number being picked. This will get you a trigger like:
Actions
Set RANDOM = Random number between 1 and 4
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
RANDOM equal to 1
Then - Actions
<YOUR ACTOINS>
Set PreviousNumber = 1
Else - Actions
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
RANDOM equal to 2
Then - Actions
<YOUR ACTOINS>
Set PreviousNumber = 2
Else - Actions
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
RANDOM equal to 3
Then - Actions
<YOUR ACTOINS>
Set PreviousNumber = 3
Else - Actions
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
RANDOM equal to 4
Then - Actions
<YOUR ACTOINS>
Set PreviousNumber = 4
Else - Actions
Then to prevent it from doing the previous number again you check if the number from RANDOM is greater then or equal to PreviousNumber. If that's so, you set RANDOM = RANDOM + 1, so it uses the actions of the next number. If that number would be 5 (which would be the case if 4 was picked before), you set RANDOM to 1 and do those actions.
I believe exitwhen scripts will end the entire trigger. You'll use If/Then/Else triggers with a RANDOM variable, so add as Then - Action 'Set PreviousNumber = x', where x is the same number as the number being picked. This will get you a trigger like:
Actions
Set RANDOM = Random number between 1 and 4
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
RANDOM equal to 1
Then - Actions
<YOUR ACTOINS>
Set PreviousNumber = 1
Else - Actions
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
RANDOM equal to 2
Then - Actions
<YOUR ACTOINS>
Set PreviousNumber = 2
Else - Actions
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
RANDOM equal to 3
Then - Actions
<YOUR ACTOINS>
Set PreviousNumber = 3
Else - Actions
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
RANDOM equal to 4
Then - Actions
<YOUR ACTOINS>
Set PreviousNumber = 4
Else - Actions
Then to prevent it from doing the previous number again you check if the number from RANDOM is greater then or equal to PreviousNumber. If that's so, you set RANDOM = RANDOM + 1, so it uses the actions of the next number. If that number would be 5 (which would be the case if 4 was picked before), you set RANDOM to 1 and do those actions.
This would only stop it from picking the same number twice in a row.
I use an random rolling trigger in my map. You'll have to use an integer[array], an integer for the random number, and an integer for max_random. When your number is picked, replace the top integer array number with the random integer, then reduce the max by 1.
So say you have 8 total numbers to random. It chooses #5. What happens is the max_random number becomes 7, and the number at 8 swaps with the number at 5, so that the random pool is still accurate.
Do you catch my drift? To reset it, you only need to reset the integer_max and integer[array] values.
Sorry, my mistake. I thought he asked twice in a row, but now I read it again, I see he wanted twice at all.
Another way to do like you did is to just keep the arrayed integer and set the first choice to Set Integer[(8 - Integer_Max)] = RANDOM. This way, the integer variable will even show which of the random numbers got which picked ^^
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.