First of all, we'll need to create the key to open the chests. In the "Item" tab of the Database, create the key as a "Common Item" type and description.
Now, let's lock "Chest 1" (from Part 1) by modifying the Event Commands slightly. Before adding any commands, press CTRL A (to select all) and CTRL X (to cut it).
Add a Conditional Branch (Tab 3), set to "Item" (second tab), "Party Possesses" and "Key", with the "Execute Custom Handler" option checked.
Under the Branch, paste (CTRL V) the previous commands. Then under the "Else Handler", create a message stating the chest is locked.
The complete script in Page 1 should look like this:
<>Branch if Key Possessed
<>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
<>Message: 5 Potions received!
<>Change Items: Potion 5 Add
<>Switch Operation: [0001: Chest 2 Opened] ON
<>
: Else Handler
<>Message: It's locked! You need a key to open it!
<>
: 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.
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:
<>Branch if Key Possessed
<>Message: Did you open the chest yet?
<>
: Else Handler
<>Message: Here's the key to that chest.
: Keep whatever you find inside.
<>Change Items: Key 1 Add
<>
: 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.
We can now move onto Chapter 3: Random Contents.