Simple Locked Door
For my first tutorial, I am going to show you how to create a simple locked door that can be opened by a key or lockpick. The level of this tutorial is beginner, and requires no scripting knowledge. It'll also help you understand switches and conditional branches.
The first thing you want to do is to create two items; the key that will be used to open the door, and the lockpick that will be used to attempt to unlock the door in the event that the player has not got the key.
Here’s what each item should look like in the database:I made a mistake in the Database entry for Lockpick. Consumable should be set to "No".
Once that is done, you need to create ways for the player to access these items. In my example, I simply put each one in a separate treasure chest (using the Quick Event Creation option):
The treasure chest on the left gives the player the key, and the one on the right gives the player the lockpick.
Now for the locked door event.
Create a door event on the map, and choose an appropriate door graphic. Make three event pages. Leave page 1 alone for now. For pages 2 and 3, they should look like this:
That’s just basic door animation stuff.
Okay, switch back to page 1, which should be blank. This is what the left section of the event should look like:
We want the locked door to check whether the key is in the player’s inventory, and then take an action depending on this. Do this through a conditional branch:
Then, add a message saying that your key unlocked the door, and then turn self-switch A on. This hands control over to the door animation thing that we set up earlier:
The next thing we want to do is tell the event what to do if the key is NOT in the player’s inventory. That’s what the “else” thing is for.
Now, when the door can’t find the key in the player’s inventory, we want to look for ANOTHER thing; whether the lockpick is in the player’s inventory. To do this, make another conditional branch under the “else” – this time, make it check for a lockpick.
Under the conditional branch for the lockpick, make the game ask you a question on whether or not you want to pick the lock. (Obviously, the choices are yes and no)
Under yes, first make a command that creates a random number between 0 and 5 (you can choose other numbers to adjust the odds).
Now, we make yet ANOTHER conditional branch; this time, it checks what number the randomizer spat out. If the number is 1, then have the lockpick be a success; if it’s another number, have the lockpick fail.
*if you want, you can make it so you "break" the lockpick if you fail. Simply add a command under "else" removing 1 lockpick from the player's inventory*
Under this conditional branch, write a message saying that the lockpick was a success, and turn self-switch A on. Under the else, just write “lockpick failed”.
Under the “no” choice, no need to write anything. Just leave it blank.
Finally, under the final “else” (which would happen if the player didn’t have the key OR the lockpick) just write a message saying, “the door is locked”.
Here’s what the entire first page should look like when you’re finished:
And that’s it! You’re done! Try messing around with the variables, or try adding different types of lockpicks! For example, a master lockpick might have a 1 in 2 chance of being a success, while an apprentice lockpick only has a 1 in 8 chance. I strongly encourage you to mess around with it yourself!
One more thing. The way I have set it up means that the door stays unlocked whenever you unlock it.
Questions, comments? Reply here.
This post has been edited by SouthWall: Jul 22 2008, 10:53 PM