Chapter 2: Locked Chests

Chapter 2: Locked Chests

As a continuation of the Complete Chests Tutorial, this tutorial details how to create a chest requiring a key to open.

In this case, an NPC has the key to open the chest, but the key can also be bought in a shop, dropped by a monster or rewarded after solving a puzzle.

Create A Locked Chest

First of all, we’ll need to create the key in the "Items" tab of the Database to open the chests.


2K3

XP

VX / VXA
Create the key as a "Normal Goods" type and give it a description.
RMXP has 3 default icons to use. Leave the other options for now and just give the key a description.
The default Icon set has 5 key icons. Type a description and leave the rest of the options for now.

Now, let’s lock "Chest 1" (from Chapter 1) by modifying the Event Commands slightly. Before adding any commands, press CTRL A (to select all) and CTRL X (to cut it).

We’ll need to add a conditional branch to check if the key item is in the party’s inventory. If it is, the chest can be opened; if not, a message is displayed stating that the chest is locked.

Add a Conditional Branch, set to "Item" and "Key", with the "Set handling when conditions do not apply" option checked.

Under the "Branch", paste (CTRL V) the previous commands. Then under the "Else" handler, create a message stating the chest is locked.

We can also add a key sound before the chest opens for a bit of realism.

The complete code in Page 1 should look like this:


2K3

XP

VX / VXA
Chapter 2: Fig. 1 (RM2K3)
Chapter 2: Fig. 1 (RM2K3)
@>Conditional Branch: [Key] in inventory
  @>Play SE: '024-Door01', 80, 100
  @>Wait: 2 frame(s)
  @>Set Move Route: This event
   :     : $>Turn Right
  @>Wait: 2 frame(s)
  @>Set Move Route: This event
   :     : $>Turn Up
  @>Wait: 2 frame(s)
  @>Set Move Route: This event
   :     : $>Turn Left
  @>Wait: 2 frames(s)
  @>Text: 5 Potions received!
  @>Change Items: [Potion], + 5
  @>Control Switches: [0001: Chest 1 Opened] = ON
  @>
:  Else
  @>Text: It's locked!
  @>
:  Branch End
@>Conditional Branch: [Key] in Inventory
  @>Play SE: 'Key', 80, 100
  @Wait: 2 frame(s)
  @>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)
  @>Text: -, -, Normal, Middle
  :     : 5 Potions received!
  @>Control Self Switch: A =ON
  @>
:  Else
  @>Text: -, -, Normal, Middle
  :     : It's locked!
:  Branch End

That’s it for the chest. When you playtest now, you won’t be able to open the chest without the key and you’ll get the "It’s locked!" message.

Obtaining The Key

To obtain the key, we’re going to set up another event, an NPC, who will give the key only once.

In the Event Commands of the NPC event, place the following:


2K3

XP

VX / VXA
Chapter 2: Fig. 2 (RM2K3)
Chapter 2: Fig. 2 (RM2K3)
@>Conditional Branch: [Key] in Inventory
  @>Text: Did you open the chest yet?
  @>
:  Else
  @>Text: Here's the key to that chest.
  :     : Keep whatever you find inside.
  @>Change Items: [Key], + 1
  @>
:  Branch End
@>Conditional Branch: [Key] in Inventory
  @>Text: -, -, Normal, Middle
  :     : Did you open the chest yet?
  @>
:  Else
  @>Text: -, -, Normal, Middle
  :     :Here's the key to that chest.
  :     : Keep whatever you find inside.
  @>Change Items: [Key], + 1
  @>
:  Branch End

What this does is check first to see if the NPC has already given the key. If not, add the Key to the inventory; if so, don’t give another key but display a message instead. And now the chest can be opened to obtain the Potions.

Next Chapter

We can now move onto Chapter 3: Random Contents.