Random Events?

The place to post your WML questions and answers.

Moderator: Forum Moderators

Forum rules
  • Please use [code] BBCode tags in your posts for embedding WML snippets.
  • To keep your code readable so that others can easily help you, make sure to indent it following our conventions.
Post Reply
Sarudak
Posts: 122
Joined: January 24th, 2008, 2:14 am

Random Events?

Post by Sarudak »

Does anyone know if there's a way of making use of the random number generator in your scenario to make certain events happen randomly?
User avatar
Mist
Inactive Developer
Posts: 753
Joined: February 15th, 2007, 8:44 am
Location: Milton Keynes, UK

Post by Mist »

Quite simple actualy

#define RANDOM_EVENT_1
[event]
<my event>
[/event]
#enddef
#define RANDOM_EVENT_2
[event]
<my event 2>
[/event]
#enddef

[event]
name=new turn
first_time_only=no
{RANDOM 1..<number of events>}
[if]
[variable]
name=random
equals=1
[/variable]
[then]
{RANDOM_EVENT_1}
[/then]
[/if]
[if]
[variable]
name=random
equals=2
[/variable]
[then]
{RANDOM_EVENT_2}
[/then]
[/if]
[/event]

That sets up two events to be performed randomly from turn two onwards. I'm quite sure you'll know how to expand it to your needs.
Somewhere, between the sacred silence and sleep.
Disorder.
Sarudak
Posts: 122
Joined: January 24th, 2008, 2:14 am

Post by Sarudak »

Sweet thanks... So can you set the probability for each random event?

The plan behind it is that I'm working on a modification to A New Land and one of the things I changed is that forests are really valuable... So the beginning of the game is a rush to get the forests with some skirmishing... Only I didn't want the map to just instantly get cleared of trees so I was hoping to set up the scenario so that in the woods farther from peoples starting base there was a chance that wild woses would appear and attack the peasants trying to harvest the trees.
User avatar
Mist
Inactive Developer
Posts: 753
Joined: February 15th, 2007, 8:44 am
Location: Milton Keynes, UK

Post by Mist »

Sure, do

{RANDOM 0..100}
[if]
[variable]
name=random
less_than=chance
[/variable]
[then]
{MY_RANDOM_EVENT}
[/then]
[/if]

for each event instead one general random for all.
Somewhere, between the sacred silence and sleep.
Disorder.
Sarudak
Posts: 122
Joined: January 24th, 2008, 2:14 am

Post by Sarudak »

Thanks! You rock!

Oh and another question related to the same problem scenariowise but not WMLwise... About filters... I was reading on the Wiki and it's dreadfully unclear... Even to me and I'm a developer by trade... When a filter test is passed where does the next line execute and if it fails where?
User avatar
Mist
Inactive Developer
Posts: 753
Joined: February 15th, 2007, 8:44 am
Location: Milton Keynes, UK

Post by Mist »

This basicaly works as elaborate and pretty fast [if]. If filter is passed for a given object (event, terrain tile, unit) the code the filter is embeded in is executed, if not that code is skipped altogether. Two quick examples :

[event]
[filter]

reads as

#if
[filter]
#then
[event]
#else
[null]
-------
[store_unit]
[filter]

reads as
#if
[filter]
#then
[store unit]
#else
[null]
Somewhere, between the sacred silence and sleep.
Disorder.
Sarudak
Posts: 122
Joined: January 24th, 2008, 2:14 am

Post by Sarudak »

Thanks... I really wish i could just keep you in my pocket or something... =D
Beastss
Posts: 15
Joined: December 23rd, 2007, 9:57 am

random really means random for everyone?

Post by Beastss »

using the original code, wouldn't it have different possibilities for every in the game? so if lets say player 1 was to have x happen, couldn't the game logic say y happened instead for player 2, and so on...?
Well, I kinda got that in the sticky on the top of the forum, but I'm curious because I would like to utilize that code to make is so that "random battles" can occur like in a platform rpg. So far, I am putting in battles that will occur when someone lands on a space (only once).
Post Reply