A lock with TWO keys

From ADRIFT 5 Manual Wiki
Jump to: navigation, search

ADRIFT allows you to easily select which dynamic object is used as the key to unlock a particular door or cabinet, but if you want the player to be able to use either of two keys to unlock the door, then we need to create a new object property for it and add support for it to all of the lock/unlock commands.

Second key property

We know this is going to be similar to the existing "Key for lock" property in the Standard Library, so open the "Open and Close" folder and right click on "Key for lock":


Select "Copy" from the menu.

Right click on the folder you want to copy it to and select "Paste"

Now double-click the new property to open it. The first thing we want to do is change the name to "Second key for lock", then remove the tick from the "Mandatory" box as we still want to be able to have other locks with only one key. Click OK to save it.


If you open any lockable object you will now see the new property directly under the "Key for lock" property, and if you tick it you can then select a dynamic object as its second key.

Lock objects with key

Open the "Lock objects with key" task in the "Open and Close" folder, and switch to the restrictions page.

The last restriction here is

Property 'Key for lock' for Referenced Object 1 must be 'Referenced Object 2'

We need to add a new restriction that checks our new property:


But we want this task to pass if EITHER key is visible to the player, so click on the AND between them to change it to an OR, and click on the vertical grey bars tp put parentheses around those two restrictions, as shown here:


That fixes the locking, but we still need to do the unlocking. Do the above for the "Unlock objects with key" task as well.

Lock Objects (Lazy)

If the player types "Lock door" without mentioning the key, the "Lock Objects (Lazy)" will check if they are holding the correct key by executing the "Lock objects key check" task, which then executes the "Lock objects with key" task using that key.

To do this with two different keys, and still give all of the correct responses when the player doesn't have either key, we will need a silent version of the key check task, and two specific tasks which override the Lock Objects (Lazy) task.

Silent key check

In the same way as you copied the key property, make a copy of "Lock objects key check" and call it "Lock objects silent key check".

Open its only restriction and delete the text "What do you want to lock %object1%.Name with?" in its text box (make sure you delete every last space and carriage return).

Specific Tasks

Delete the actions in both the "Lock Objects (Lazy)" and "Unlock Objects (Lazy)" tasks. We will be doing the key checks in our new specific tasks instead.

Create two SPECIFIC tasks which override "Lock Objects (Lazy)", call them something like "Lock with first key" and "Lock with second key"

To the "Lock with first key" task, add the action: "Execute task [Lock objects key check]" with parameters "%object1%" and "%object1%.LockKey".

We need to know the key of your "Second key for lock" property, so click on the funnel icon in the top right corner of the folder containing this property, and tick "Key" in the popup list.

The keys of the items in the folder will now be shown. Note the key next to the "Second key for lock" property, which will most likely be the word "Property" followed by a number.

To the "Lock with second key" task, add the action: "Execute task [Lock objects silent key check]" with parameters "%object1%" and "%object1%.Property1" (Changing "Property1" to the key of your "Second key for lock" property)

Only to the "Lock with second key" task, add a restriction [Referenced object][must][have property][Second key for lock]

Make sure "Lock with second key" has a higher "Task Priority" (smaller number) than "Lock with first key" on their "Advanced" page. (You must have Simple mode turned off to see this page)

In "Unlock objects key check" is an action to execute task "Unlock objects with key". If its second parameter is "%PropertyValue[%object1%.LockKey]%" then change it to "%Object2%".

Create specific task for the "Unlock Objects (Lazy)" tasks in the same way.

Fixing the task priorities

A problem can occur when the user types "Lock door with noodle" and the noodle is not the key for the door.

When this task fails, instead of printing the "You can't open the door with the noodle message", ADRIFT tries to run the 'Lock Object (Lazy)' task instead.

To fix this the 'Lock/Unlock objects with key' tasks must have a higher priority (lower number) than the 'Lock/Unlock Object (Lazy)' tasks.

Go to the advanced page of the 'Lock/Unlock objects with key' tasks and decrease the "Task Priority" number by two steps (from 50039 to 50037 in my version).

<<< Using an event to delay a poisons effectMain PageClothing Slots >>>