Run an Object/System at Random

Cokemonkey11

New Member
In mapping there is a simple, but effective way to make 1 random thing out of a group of things happen.
For example:
make a unit walk towards a random point
Create Random Game Message (Tip System)
For this tutorial We are going to make a Random Tip System.

What You Should know how to do for this tutorial:
Open the World Editor.
Open the Trigger Editor.
Create a new Trigger.
Changing Data in a Trigger.

Step One: Create a Variable
Open the trigger Editor and click the x button at the top, on the toolbar.
variq9.jpg

For this variable, we want an "intiger." name it "rndm_words" and leave array unchecked, and default value at 0.
intnq5.jpg


Step Two: Tell the Game When to Show Your Message
For this tutorial, we aren't going to show a random message once, but we are going to show it periodicly. So create a new trigger called "tips."
Click the "New Event" Button at the top, on the toolbar.
eventrx9.jpg

The event type is "time," because we are giving it a specific time to run the trigger, rather then basing it off of something else.
The event is "Periodic Event," because it is going to happen more then once, rather then just one time.
For this tutorial, the trigger will run ever 2 minutes (120 Seconds)
einfogy2.jpg


Step Three: Tell the Game What to Do
[Take note, we are skipping conditions, this is because there are none]
This is where it gets a little more complicated. Pay careful attention.
Click the "New Action" button at the top, on the toolbar.
actionxq5.jpg

The action type is "- General," because it's not classified as any other Action type.
The action is "Set Variable" because we are going to set that variable as a random number, in this case between 1 and 2 to keep the tutorial short, but you can have 3, 4, 5, 600 if you want. (although I dont recomend it)
Right now it says "Set (Variable) = (Value)"
Click Variable, and change it to "rndm_words," the variable we made earlier.
Click Value, and change the function from "Arithmetic," to "Math - Random Number."
The Text will change to "Random number between (1) and (10)."
Click 10 and, for this tutorial, change it to 2.
Click Ok (Twice) so your back at the main trigger editor.
You should have this:
sfar1wh3.jpg

Next, we create the messages.
Click the "New Action" button again,
actionxq5.jpg

change the action type to "-General," and the action to "If/Then/Else, Multiple Functions," Press Ok.
If you've never used an If/Then/Else action before, it may seem odd, just remember the If is like a condition, then, like an action, and else, like a seperate action.
We need to give our If/Then/Else information for it to run, so click the "If - Conditions," go to the top, and click "New Condition."
condud3.jpg

This Condition will check to see if the randomly generated number is 1, before it decides what to write.
Leave the Condition Type as "All," and select "Intiger Comparison" for the Condition.
It should say "(Number of units in (Units in (Playable Map Area))) (equal to) (0)." Select the first link, "(Number of units in (Units in (Playable Map Area)))," and change it from "Function," to "Variable," and pick our variable, "rndm_words." Press Ok, and it should now say "(rndm_words) (equal to) (0)." Click 0, and change it to 1. Press Ok (twice) so ur at the trigger editor, once more.
You should have this:
sfar2im0.jpg

Now we need to tell the Game what to do, now that it has recognized the intiger as 1, Select "Then - Actions," and click the new action button.
The action type should be "Game," and the action type "Text Message (Explicitly Timed)." Now it should say "Display to (All Players) for (30) seconds, the text: (text)." Select the word text, and input your first tip. For this tutorial the first tip would be "Hi there!"
Press Ok (twice) so your back to your trigger editor. Select the current If/Then/Else Trigger, and copy paste it (Cntrl+C, Cntrl+V) But, now you have 2 actions for if our variable is 1, but you have nothing for 2, so select the second one, and change "(rndm_words) (equal to) (1)" to "(rndm_words) (equal to) (2)." and change the text in the second one from "Hi There!" to, whatever your second tip is. For this tutorial, "Good Luck, Have Fun."
Now you should have this:
sfar3uy4.jpg

And thats it! your finished, later you can make more Tips by changing the "set variable" trigger.

Let me know what you think, my first warcraft 3 tutorial.
 
Werbung:

Mini-Me

New Member
That works, but if you got like 30 tips, there will be 30 if/then/else, making it a very long trigger and maybe bit confusing. There is an other way to do this that i think is simpler and more efficiant.

Create a string variable, set it array 30, name it for example "tips". Then have a trigger set up the variables at map beginning:

event - map iniziliation
conditions- none
actions:
-set variable Tips [1] = "Hello everybody"
-set variable Tips [2] = "What's up?"
-set variable Tips [3] = "This map pwns"
-set variable Tips [4] = "This map is tha greatest"

Then in that periodic trigger of yours in actions:

-set variable rndm_words = (random integer between 1 and 30)
-Game display "Tips [rndm_words]" for all players for 30 sec

But as said, your way works too.
 
Werbung:
Top