Age of Wonders II Heaven Julia with Gameplay background

Scenario Design

Random Events Generator

(Updated 10-26-2002)

Posted by: Talon-Thorn(09-27-2002) on the AOW2 Scenario Forum

The Initial Question: "I want to create random events at the start of every turn (storms, mana/ gold loss/gain, etc....), BUT I want to show a message to explain the event every time it happens." - Greenmonster

Talon-Thorn:

For sake of simplicity, let's do 8 random events rather than 10. Set up three events, each one to randomly set a flag. Then use the flags to select which event occurs.

I. First, clear the flags for each player:

player1flag1 - event: control flag 1 = false, trigger: new turn
player1flag2 - event: control flag 2 = false, trigger: new turn
player1flag3 - event: control flag 3 = false, trigger: new turn

II. Then generate the random number…in binary:

rand1 - event: control flag 1 = true, trigger: new turn, condition: random (50)

rand2 - event: control flag 2 = true, trigger: new turn, condition: random (50)

rand3 - event: control flag 3 = true, trigger: new turn, condition: random (50)

So, what you have is eight possible combinations.

flag1 false = 0, true = 1
flag2 false = 0, true = 2
flag3 flase = 0, true = 4

Add them up and you get your random number, between zero and 7.

III. Now apply the random binary number to your events:

randevent1msg - event: show message "bad crops", trigger: new turn, condition: flag1 and not flag2 and not flag 3 and (day condition)

randevent1act - event: gold reward -10, trigger: new turn, condition: flag1 and not flag2 and not flag 3 and (day condition)

randevent2msg - event: show message "good crops", trigger: new turn, condition: not flag1 and flag2 and not flag 3 and flag 1001 and not flag 1002 and (day condition)

randevent2act - event: gold reward +20, trigger: new turn, condition: not flag1 and flag2 and not flag 3 and flag 1001 and not flag 1002 and (day condition)

etc.

NOTE: be sure to put the random event events before the random number generator, or it won't work. This is a "feature" of how triggers work.

VI. Duplicate this for each player (if you want unique random events for each player).

Be sure you use a different flag for each player!! I suggest you number each player, and use that number in the flag. So, player 1 has flags 101, 102, 103, player 2 has 201, 202, 203, etc.


Week Counter

The only thing we didn't do is we didn't add a "day" condition so it will only occur once a week. Well, you could set up this whole thing for each event, each player, AND each week, or...let's look at setting up a "week" counter instead, shall we???

V. Binary Counter.

This one will be fun! ...at least for me, that is ;)

I'm going to show you how to set up a binary counter, so you can count any number of events or days. I also show how you can set it up to start counting. I'm going to assume that you want a counter to start based on some trigger (you choose), and have it reset each week.

Here is the start of it:

Triggering circumstance:

event: flag 1000 = true, trigger: (whatever you want), conditions (whatever you want).

When this trigger goes off, the counter will start it's countdown. You can just ignore it and let it begin at day 1, but I include it here for versatility.

Please note that the counter values take effect the day after they are set!!

This will look a lot like the previous binary number, and we only have to count to 7, so a counter of eight is just enough to do the trick. You will need two events per flag, with three flags total. Due to the "feature" of triggers, you have to put the counter backwards, counting the "4" position, then the "2" then the "1"'s. All the flags start at false (zero).

Counter:

event1004T: event: control flag 1004 = true, trigger: new turn, condition: flag 1001 and flag 1002 and not flag 1004 and flag 1000

event1004F: event: control flag 1004 = false, trigger: new turn, condition: flag 1001 and flag 1002 and flag 1004 and flag 1000

event1002F: event: control flag 1002 = true, trigger: new turn, condition: flag 1001 and not flag 1002 and flag 1000

event1002T: event: control flag 1002 = false, trigger: new turn, condition: flag 1001 and flag 1002 and flag 1000

event1001F: event: control flag 1001 = true, trigger: new turn, condition: not flag 1001 and flag 1000

event1001T: event: control flag 1001 = false, trigger: new turn, condition: flag 1001 and flag 1000


Next, let's set up the "reset" event, when the counter gets to 7. Since changing the flags will mess up later events, we have to assign the "reset" to another flag. Since the flag won't be set until the next turn, we have to make it go of a day early… here it is:

reset_counter - event: control flag 999 = true, trigger: new turn, condition: flag 1001 and not flag 1002 and flag 1004 and flag 1000

reset1 - event: control flag 1001 = false, trigger: new turn, condition: flag 999

reset2 - event: control flag 1002 = false, trigger: new turn, condition: flag 999

reset4 - event: control flag 1004 = false, trigger: new turn, condition: flag 999

reset_reset - event: control flag 999 = false, trigger: new turn, condition: flag 999

Thus, on day "6" of the counter, flag 999 is set to true. Since flag 999 was changed, no events basd on it occur. On day "7" of the counter, the counter is reset to zero (counter goes from zero to 6, making 7 days) -- all counter flags are set to false, and the reset flag 999 is set back to false too.

You don't have to reset flag 1002, since it will already be false. Place these events BEFORE the counter events!!


Note, with all the events having the flag 1000 in them, you could interrupt the count and then restart it by disabling this flag. An added bonus!

Now you just need to add the counter to the random events. The "target" day will be "flag 1001 and not flag 1002 and flag 1004." Just add it to each line like so:

randevent1msg - event: show message "bad crops", trigger: new turn, condition: flag1 and not flag2 and not flag 3 and flag 1001 and not flag 1002 and flag 1004

randevent1act - event: gold reward -10, trigger: new turn, condition: flag1 and not flag2 and not flag 3 and flag 1001 and not flag 1002 and flag 1004

randevent2msg - event: show message "good crops", trigger: new turn, condition: not flag1 and flag2 and not flag 3 and flag 1001 and not flag 1002 and flag 1004

randevent2act - event: gold reward +20, trigger: new turn, condition: not flag1 and flag2 and not flag 3 and flag 1001 and not flag 1002 and flag 1004

etc.


(Discussion of this script here.)

Back to Event Scripting Resource Database Menu


Back to Scenario Design Main Menu

HG Logo

Headlines

» AoW1 Summer 2008 Mapmaking Tournament

» Interview Kirky Picardo

» Scenario update

» The making of...

» A new PBEM Singles Champion is crowned - Swolte!!

Poll

What unit most resembles you?

Halfling peasant

Undead Vampire

Human Knight

Tigran Prowler

Orcish Warlord

Archon Saint

Dwarven Engineer

Chaos Spawn

Results :: Other Polls

Age of Wonders

Looking for info about the original AoW?
Visit AoW Heaven!

AoWH Logo

HeavenGames Sites

» Main Portal

» Age of Empires

» Age of Empires 3

» Age of Kings

» Age of Mythology

» Age of Wonders

» Age of Wonders 2

» Battle for Middle Earth 2

» Caesar 3

» Caesar 4

» Children of the Nile

» Dungeon Siege

» Empire at War

» Empire Earth

» Emperor: RotMK

» Medieval 2: Total War

» Pharaoh

» Rise & Fall: CaW

» Rise of Legends

» Rise of Nations

» Rome: Total War

» Stronghold

» Stronghold 2

» SW: Galactic Battlegrounds

» Zeus