Wouldn’t it be better if the contents of chests were randomized, rather than fixed? This adds an element of surprise and variety to the game, a sense of the unexpected, and often aids replayability.
Randomising The Contents
To set up randomised 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. For argument’s sake, let’s call the event "Random Contents", with the "Trigger" set to "None" (set by default). This way we can call the event whenever we want random contents.
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 for our Random Contents Common Event looks:
2K3 / XP
VX / VXA
@>Control Variables: [0001:Randomizer] = Random No. (1...3) @>Conditional Branch: Variable [0001:Randomizer] == 1 @>Text: -, -, Normal, Middle : : 5 Potions found! @>Change Items: [Potion], + 5 @> : Branch End @>Conditional Branch: Variable [0001:Randomizer] == 2 @>Text: -, -, Normal, Middle : :100 Gold found! @>Change Gold: + 100 @> : Branch End @>Conditional Branch: Variable [0001:Randomizer] == 3 @>Text: -, -, Normal, Middle : :5 Antidotes found! @>Change Items: [Antidote], + 5 @> : Branch End
Adding More Items
To add more items, increase the end range of the variable Randomizer and add another corresponding "Conditional Branch" for each additional item.
Creating The Chest
Create another chest on the map, named "Chest 3". You can copy the chest from the basic chests.
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 "Conditions" switch on Page 2 to "Chest 3 Opened" as well.
The completed code will look like this:
With every chest you want random content, simply call the "Random Contents" event and turn on the corresponding switch in a similar fashion.
We can now move onto Chapter 4a: Combination Locks (Basic).