//:://////////////////////////////////////////////
/*
A system that creates one-shot custom keys for lockable doors.
*/
//:://////////////////////////////////////////////
//:: Created By: Brutus (with bugtesting and some
//:: scripting finesse suggestions by Gerben :D )
//:: For WorldofCaenyr.com
//:: Created On: November 2013
//:://////////////////////////////////////////////
I wanted to have doors to Inn rooms that required a player to purchase a key to use. I also wanted it so that they could lock the door for a safe night’s sleep. However, I did not want another player to then be able to purchase the same key and enter said room, so I came up with this idea. This system supports five different keytags, as I originally had 3 varying degrees of rooms within the same Inn and wanted to keep them separate, but realized that I may wish to use this system in larger/fancier establishments which might need additional functionality.
How this small system works is as follows. There are four objects involved; the door, the merchant who sells the keys, the key itself, and the PC. Implementation is all done through variables, so that the Designer does not have to create custom scripts for each establishment that S/He wishes to utilize the system in, merely set variables.
The Door:
Set a Key Tag for the door lock; make sure it matches the tag of the key you are using. Place the script "d_lok_custom_key" in the "OnLock" script handle of the door. Place the script "d_unl_custom_key" in the "OnUnLock" script handle of the door. Set the door to "Plot", "Locked", "Can be relocked", and "Key required to unlock or lock".
The Key Merchant:
Paste your merchant, and place the conversation sys_room_key on him/her. You may then save a copy and edit the conversation to your heart’s content as far as vocabulary goes, but do not change the scripts that are placed in the various nodes. You may however delete unneeded conversation nodes if you do not utilize all door categories. The merchant also needs variables set;
Name Type Value
GOLD_NEEDED1 (etc.) int A number in GP of what the key costs for each room type
KEY_1(etc.) string The resref (NOT TAG) of the respective key sold
The Key:
A key is required, matching the required Key Tag of the door lock.
The PC:
You bring gold and buy keys. :P You also provide the name for the custom key tag. ;)
The Scripts:
The starting conditionals in the conversation keep track of if you have enough gold to purchase a key, or have bought a key before. The action taken scripts take gold and give the actual keys, and set a LocalInt on the PC indicating that they have already purchased a key.
The doors are initially set to Locked, so that players do not just enter the rooms and use them without paying. Once inside the PC will have to manually close the doors, as the automatic door closure script we normally use was conflicting with the scripted door closure of the "d_unl_custom_key" script. The player then needs to manually (using the door's radial menu) lock the door. This then triggers the script "d_lok_custom_key". It is where I destroy the original key, then create a new key on the PC, setting the tag of the key to the PC's name. I then change the lock key tag of the door to the new value of the PC's name. Tracking of the doors "LOCKSTATE" (used to allow entry to the locked room with the original key without destroying it) is set here as well.
Once inside, PC's can then unlock the doorby clicking on it, or using the radial menu. This triggers the script "d_unl_custom_key". It is where I destroy the new key the PC carries, and revert the door lock key tag back to the original value. After a small delay (giving the PC and guests 10 seconds to vacate the premises), I close then lock the door. Tracking of the doors "LOCKSTATE" (used to allow entry to the locked room with the original key without destroying it) is set here as well. I finally set a local integer on the PC back to 0, so they can then go buy another key later.
The RAR file below has a small mod for play testing, and only has the scripts required for the system to make it easy to export them all. In my screenshot provided, you will see I tested using a character with odd symbols like asterisks, tildes, etc., to see if it would have any negative effects. I am pleased to report there were none. :)
I hope that you may find it of use in your work. :D Let me know if you find any bugs.
Brutus
p.s. My first offering to the community! :D
Attachment | Size |
---|---|
![]() | 17.79 KB |