EVENT – Random Treasure in Chests

twitter

The default option for the Quick Event Treasure Chest only lets you have one type of treasure.  But that can get boring and its more fun to have some randomly generated loot.   Fortunately that’s not hard to do using nested Condition Branches.   In this tutorial I’m going to show you how to create such an event and a couple of different options for creating random treasure.

We can start by using the Quick Event option to create a normal treasure chest event.  The event script it produces will look something like this:

@>Play SE: ‘Chest’, 80, 100
@>Set Move Route: This event (Wait)
:                   : $>Direction Fix OFF
:                   : $>Turn Left
:                   :  $>Wait: 3 frame(s)
: : $>Turn Right
:                   : $>Wait: 3 frame(s)
@>Control Self Switch: A =ON
@>Change Gold: +10
@>Text: -,-, Normal, Bottom
:         : 10\G were found!
@>

As a side note and pet peeve, gramatically it should be :10\G was found, not were.

There is also a second event page, but we can leave that as it is.   We can also use most of the script above as is.  Just delete everything from after the @>Control Self Switch command

To create a random treasure we need to create a table and random number.   We can easily do this using conditional branches nested inside each other.  We’ll start by adding a Control Variable to the script to create a random number from 1-4.  You could make it a larger number range, but 1-4 will be fine for this example.

@>Play SE: ‘Chest’, 80, 100
@>Set Move Route: This event (Wait)
:                   : $>Direction Fix OFF
:                   : $>Turn Left
:                   :  $>Wait: 3 frame(s)
:                   : $>Turn Right
:                   : $>Wait: 3 frame(s)
@>Control Self Switch: A =ON
@>Control Variables: [0001] = Random No. (1…4)
@>

Now we need to set up a chain of nested condition branches to produce our random treasures.  We’ll need 4 such branches, which should look like this:

@>Play SE: ‘Chest’, 80, 100
@>Set Move Route: This event (Wait)
:                   : $>Direction Fix OFF
:                   : $>Turn Left
:                   :  $>Wait: 3 frame(s)
:                   : $>Turn Right
:                   : $>Wait: 3 frame(s)
@>Control Self Switch: A =ON
@>Control Variables: [0001] = Random No. (1…4)
@Conditional Branch: Variable [0001] == 1
@>
:    Else
@Conditional Branch: Variable [0001] == 2
@>
:    Else
@Conditional Branch: Variable [0001] == 3
@>
:    Else
@Conditional Branch: Variable [0001] == 4
@>
:    Branch End
@>
:    Branch End
@>
:    Branch End
@>
:     Branch End
@>

This gives us the “frame” for our table with four possible results.  The last of the Condition Branches doesn’t have an Else statement, this is done by unchecking the bock at the bottom of the options ‘Set handling when conditions do not apply’.  If left checked it would give out table an extra Else statement that would never happen.

For treasure you can add whatever you like.   For example the first option might be to add only 1 Gold, the next might add 100 Gold, the third might give a Potion.  I’m going to fill in the table with some options and I’m also going to add something special for the 1st variable by adding another Conditional Branch to demonstrate another option.  Here’s what the table looks like once completed:

@>Play SE: ‘Chest’, 80, 100
@>Set Move Route: This event (Wait)
:                   : $>Direction Fix OFF
:                   : $>Turn Left
:                   :  $>Wait: 3 frame(s)
:                   : $>Turn Right
:                   : $>Wait: 3 frame(s)
@>Control Self Switch: A =ON
@>Control Variables: [0001] = Random No. (1…4)
@Conditional Branch: Variable [0001] == 1
@Conditional Branch: [Magic Gem] in Inventory
@>Change Gold: + 100
@>Change Items: [Potion] + 1
@>Text: -,-, Normal, Bottom
:      : 100\G and a Potion were found!
@>
:    Else
@>Change Items: [Magic Gem] + 1
@>Text: -,-, Normal, Bottom
:      : A Magic Gem was found!
@>
:    Branch End
@>
:    Else
@Conditional Branch: Variable [0001] == 2
@>Change Gold: + 100
@>Text: -,-, Normal, Bottom
:      : 100\G was found!
@>
:    Else
@Conditional Branch: Variable [0001] == 3
@>Text: -,-, Normal, Bottom
:      : All you found were some old moth eaten clothes!
@>
:    Else
@Conditional Branch: Variable [0001] == 4
@>Change Gold: + 20
@>Change Items: [Potion] + 1
@>Text: -,-, Normal, Bottom
:      : 20\G and a Potion were found!
@>
:    Branch End
@>
:    Branch End
@>
:    Branch End
@>
:     Branch End
@>

If our random number comes up 2, the player finds 100 gold.  If it comes up 3, they get nothing.   If it comes up 4, they get 20 gold and a Potion.   However, if it comes up 1, something special happens.  First the event checks to see if they have a ‘magic gem’ item in their inventory, we’ll assume this is an item we don’t want the player to have more than one of at a time.   If they do have a magic gem already then they get 100 Gold and a Potion.  But if they don’t, then they find a Magic Gem.

So there you have it, a simple way to generate random treasure using conditional branches within an event.  You can set this up as an event for each treasure chest, changing it from chest to chest or map to map.  Or you could set the conditional branches up in a Common Event and then call that.   You could even set up several ‘loot’ tables as Common Events and call different ones for different chests in different areas.  I think you get the idea how you can modify this to customize it for your own needs.

Hope you found this useful, keep being creative!

twitter

Comments are closed.