simplekey.c
inherit "/std/lockkey";
void create()
{
::create();
// One array item within set_id must exactly match the "keyname"
// argument in set_door() in /std/room.c. The lock/unlock code will
// check if the player is carrying either a "keyname" item or a
// "keyname"+" key" item.
set_id(({"key","blacksmithkey","blacksmith's key"}));
set_keyname("blacksmithkey");
set_short("Blacksmith's key");
set_long("This is the blacksmith's key.");
}
Writing a key is very simple. Keys work on locked doors and chests - when making a key, you don't need to specify which (you don't say this key is for a chest or a door).
For doors, the argument passed to set_keyname() is checked against the
set_door() code in the room. In our last room discussion, the locked door
was set by:
set_door("west", 0, 1, "blacksmithkey");
That means a key with set_keyname("blacksmithkey"); will open this door.
Please try to pick unique names for your keys/locks. The lock/keyname will not
be visible to players, so you can choose longer names if you need to
(such as "greyfloor1door2" or "orcquestdoor3"). The lock/keyname doesn't
need to be included in set_long or set_short, but it does need to be contained
within set_id.
Now let's see how to make a chest.
trapchest.c
inherit "/std/obj/chest";
void create()
{
::create();
// Syntax of set_trapped:
// 1st argument: HP damage received
// 2nd argument: Message room receives when trap is sprung
// 3rd argument: 0=opener is damaged, 1=everyone in room is damaged
set_trapped(2, "A trap on the chest %^RED%^EXPLODES%^RESET%^ as "+
"it is triggered!", 0);
set_locked(1);
set_dclock(25);
set_keyname("blacksmithkey");
}
All chests are automatically "closed" when created. The above chest is locked and trapped.
set_locked(1);
This locks the chest. Chests are unlocked by default.
set_dclock(25);
This sets the DC (difficulty class) for the lock. You don't need to use this function
if the chest isn't locked. The default DC for a chest's lock is 25. Consult
the Players' Handbook for more information on lock DCs.
set_keyname("blacksmithkey");
This is optional. Use this function call if you want to have a special key
that unlocks the chest. Note that you can use the same keyname for chests
and rooms. This is useful if you're making a castle that has a "master key"
capable of opening many different doors and chests.
set_trapped(2, "A trap on the chest explodes!", 0);
By default, chests are not trapped. You trap them with this function call.
The first argument is the Hit Point damage if the trap isn't disarmed
properly. The second argument is the damage message. Avoid using
the word "you" in this message... it may be displayed to more people than
just the person receiving damage. The third argument is a 0 if you only
want the trap to damage a single person, or a 1 if the trap should damage
everyone in the room.
You can also set_long(), set_short() and set_id() on chests. If you don't, generic values will be provided for you.
For an example, look at /wizards/greycopy/crypt/c2.c