Hello since I actually care about the content I'm writing for the Map Tricks and Help Archive I'm posting this for suggestions / feed back. I feel Randomization needs a good tutorial since the question comes up quite often and It always takes a long time to explain. Also i would rather people understand what there doing rather than copy triggers somone posted then ask for help again when they need to randomize something else.
Anyways please reply and answer the thread truthfully. Point out any thing that doesn't make since or anything you don't understand.
<hr>
Random Triggers.
LESSON ONE:
The first thing you need to know about random triggers is they require switches. When you randomize trigger you take advantage of the randomize switch action. If you do not understand switches I suggest figure that out before continuing. When you randomize a switch the state (clear or set) of the switch is randomly determined. The current state of the switch doesn’t matter, it will be ether set or clear 50/50 chance.
When your creating a random effect first thing you need to ask yourself is “How many different things can happen?” Or how many possibilities are there. For simplicity I will first explain how to randomize between two different things.
Example: Your creating a random unit 1 minute into the game.
Conditions:
-Elapsed Time is at least 60 game seconds.
Actions:
-Randomize ‘Switch A’
-Set Switch ‘Randomize On’
Now when you randomize Switch A there are two possible states the switch can be. Set or Clear. So to create your unit you will need a trigger for each of the possible solutions that can occur.
Conditions:
-Switch ‘Switch A” is set
-Switch ‘Randomize On’ is set
Actions:
-Create one ‘random unit 1’ for current player at location
Conditions:
-‘Switch A” is clear
-‘Randomize On’ is set
Actions:
-Create one ‘random unit 2’ for current player at location
At this point you might be asking yourself “What is purpose of the extra switch?” Well, whenever the game starts all switches are clear by default. If the condition for the second trigger was ONLY “switch a” is clear then it would fire at the very start of the game. For this reason I always have a extra switch.
LESSON TWO
Ok now that we have the basics down lets take it a step up. As we all know Starcraft isn’t a perfect world and we don’t always want our random events to only have two results or a 50/50 chance. So this is where Combining Random Switches comes in handy. For example, Say you randomize two switches instead of only 1. When you look at the two switches together the first can be ether set or clear and so can the second. This leaves you with 4 possible solutions. Set/Set, Set/Clear, Clear/Set, and Clear/Clear.
For my next example I will describe a madness map with a random unit spawn. Say we want our players to get hydralisk 25% of the time marines 25% of the time and zerglings 50% of the time.
So lets take this step by step, First off you have more than 2 units so you will need more than 1 random switch. Also you want the zerglings to spawn 50% of the time. The solution isn’t hard. Use two random switches so you get 4 possible results and designate two of the results to give you zerglings.
Now before I go off writing my triggers I need to point something else out. I stated this was a madness map. Meaning the random triggers need to happen more than once. Preserving randomization is a little bit more complex than just adding preserve trigger to the end of all the triggers.
First off lets make our starting trigger (the condition)
Players:
-Player 1
Conditions:
-Always
Actions:
-Randomize ‘Switch A’
-Randomize ‘Switch B’
-Set Switch ‘Randomization On’
-Preserve Trigger
Then we will need our 4 triggers, one for each possibility.
Set/Set, Set/Clear, Clear/Set, and Clear/Clear
Players:
-Player 1
Conditions:
-‘Switch A’ is set
-‘Switch B’ is set
-‘Randomization On’ is set
Actions:
-Create one hydralisk at ‘spawn location’ for current player
-Clear switch ‘Randomization On
-Preserve Trigger.
Then you would create this trigger for each of the above combinations changing the unit it creates. (keep in mind two of the triggers would create a zergling)
Also pay close attention to the fact that I cleared the ‘Randomization On’ switch This isn’t really important for this trigger since it randomizes all the time but if you had to wait a long time for your unit you wouldn’t want the random trigger to just keep creating hydralisk. As far as clearing the random switches (switch A and B), it isn’t needed. Since the switches have no other effect on the map you will not need to clear them. You will just randomize them again next time you need a unit and what state there in doesn’t matter.
LESSON THREE
Ok lets get into the more advanced stuff now. Say you want a whole bunch of different random things to happen. Say any one of 15 questions for a quiz map.
The first thing that should be going though your head is “how many switches do I need?” This is where an the equation comes in handy. Rather than guessing the amount of switches and trying to find all there combinations then counting use this equation.
(# of Possibilities) = 2 ^ (# of Switches)
Or quite simply each time you add a switch it doubles. (IE: 2, 4, 8, 16, 32, …)
So once you have figured that out you will realize that there isn’t a amount of switches that has 15 solutions. Well relax this can still be done, Whenever the number of desired possibilities isn’t a even power of 2 then you just pick the next number up. 4 switches with 16 possibilities in our case.
So first things first how do I determine what possibilities will there be? To make this process simpler I’ll use binary, 1 to represent set and 0 to represent clear So if I use 2 switches the possibilities would look like this
00
01
10
11
Now what if I have 4 or even 6 switches?
Take the same basic row structure and add to it.
(3 switches)
000
001
010
011
100
101
110
111
(4 switches)
0000
0001
0010
0011
0100
0101
0110
0111
1000
1001
1010
1011
1100
1101
1110
1111
If you look at the first digit in each row you will realize that all the Zeros line up and all the Ones line up. If I wanted to create a list for 5 switches I would first copy the list for 4, Then I would put a 0 in front of each possibility. Then copy the list for 4 switches again and put a 1 in front of the rest.
Now that we have figured out how many switches to use and what all the combinations of switches are were ready to write our trigger. Our starting trigger (the randomizer) is the same.
Conditions:
-Whatever
Actions:
-Randomize Switch A
-Randomize Switch B
-Randomize Switch C
-Randomize Switch D
-Set Switch Randomizer On
Now we know how to write triggers for each combination but remember we only want 15 results NOT 16. To do this you can’t just leave one of them out (wouldn’t that be nice). Since it is still possible that that solution come up you will need to create what I call a “rerandomizer”.
Basically you just make the actions for the 16th possibility to start the randomization process again. The trigger would look like this.
Conditions:
-Switch A is clear
-Switch B is clear
-Switch C is clear
-Switch D is clear (you can use any of the possibilities, you don’t have to use all clears)
-Switch Randomizer On is set
Actions:
-Randomize Switch A
-Randomize Switch B
-Randomize Switch C
-Randomize Switch D
-Preserve Trigger
Now this trigger runs a little bit different than the rest. First off you MUST preserve it. Even if you only use the randomization once. This is because it is always possible to get the exact same results twice in a row. Secondly this trigger should be located before the rest of your possibility triggers (the other 15 in this case). This is more of a performance issue than anything else. If the rerandomizer actually runs the other triggers will be following it directly and you won’t have to wait for the triggers to come around next time. (I suggest this even if your using hyper triggers)