09 March 2010

Chapter 3: Random Contents - The Complete Chests Tutorial

Wouldn't it be better if the contents of chests were randomized, rather than fixed? This adds an element of surprise to the game, a sense of the unexpected.

To set up randomized items, we'll be using a Common Event, which can then be called from within the chest events.

So, let's create the Common Event (in the Database) first of all. Create a new Common Event, called "Random Contents", with the Trigger set to "Call" (the default).

In the Event Commands, we'll be generating a random number between 1 and 3, which will then correspond to the item given. To do this, we need to set up a variable (Randomizer or similar) and some Conditional Branches, each pointing to the random number generated.

For this tutorial, the goodies I've chosen are 5 Potions, 100 GP and 5 Antidotes.

This is how the finished code looks:
<>Variable Oper: [0001:Randomizer] Set, Rnd[1-3]
<>Branch if Var [0001:Randomizer] is 1
<>Message: 5 Potions found!
<>Change Items: Potion 5 Add
: End
<>Branch if Var [0001:Randomizer] is 2
<>Message: 100 GP found!
<>Change Money: 100 Add
: End
<>Branch if Var [0001:Randomizer] is 3
<>Message: 5 Antidotes found!
<>Change Items: Antidote 5 Add
: End

To add more items, increase the end range of the variable Randomizer and add another corresponding Conditional Branch.

Using the map from the previous tutorials, create another chest on the map, named "Chest 3". You can copy the locked chest and paste it onto the map, deleting the Event Commands in Page 1, except "Play Sound" through to the third "Wait" command.

At the end, add the Call Event command to call the "Random Contents" Common Event we just created. Then turn the switch "Chest 3 Opened" to ON and change the Preconditions switch to "Chest 3 Opened" as well.

The completed code will look like this:

<>Play Sound: open1
<>Move Event: This Event, Face Right
<>Wait: 0.2 Sec
<>Move Event: This Event, Face Up
<>Wait: 0.2 Sec
<>Move Event: This Event, Face Left
<>Wait: 0.2 Sec
<>Call Event: Random Contents
<>Switch Operation: [0001: Chest 3 Opened] ON

With every chest you want random content, simply call the "Random Contents" event and turn turn on the corresponding switch in a similar fashion.

0 Comments So Far:

Post a Comment

Related Posts with Thumbnails
Template Design "Perfect World" by SkinCorner