Making Keys Usable from the Inventory

From FleshWorks

Jump to: navigation, search

by Rantako

Contents

Intro

This tutorial will show you how to make keys that work like those from Thief 1 and 2. For anyone who hasn’t played those games, they work by selecting a key from inventory and using it on a door. If it is the correct key, the door unlocks (or locks). I’m probably not the only person who thinks that is better than T3’s automatic unlocking!

Making the Key

Open the Actor Class Browser and create a new class under WorldObj -> InventoryObject -> PowerUp -> Potion and call it InvKey. (I know it’s not a potion, but it works there! Alternatively, if you don't want it under Potion you could create a new class higher up, but you would need to give it all the same properties as Potion.) Give your InvKey archetype the following properties:

Frob -> FrobBias: 16.00
Frob -> IsFrobbable: True
Highlight -> HighlightDist: 128
Inventory -> bCanUseWhileClimbing: False
Inventory -> bDeleteOnUse: False
Inventory -> DontUseOnFullHealth: False
Inventory -> bIsInventory: True
Inventory -> bIsStackable: False
Inventory -> InvName:
<string=t_Key>
Inventory -> InvType: eIT_ITEM
Inventory -> MaxInventoryStack: 0
Scripts -> bEnableScriptInherit: False

Add the property Scripts -> TriggerScripts, and give it the script KeySound. (It is in GameObjects -> ObjectSounds. This should be the only script your InvKey archetype has. If it has any others, delete them.) You will notice we have not yet given the key a mesh, nor have we set it up to actually do anything. This is because the actual keys will be archetypes under this one.

Create a new class under InvKey and call it InvKey1. Right click it, and click ‘Placeable/Unplaceable’. Because we specified most of the properties needed on the InvKey archetype, we don’t need them on this one. We do need a few other ones, though:

Render -> ObjectMesh: INVKeyA(Default)

Now close the Actor Class Browser and open the Trigger Script Manager.

Create the following scripts:


InvKey1OnKey

Image:Condition_icon.png CONDITIONS

Image:Condition_icon.png When I am used in a way from inventory

Image:action_icon.png ACTIONS

Image:action_icon.png Send trigger message [Key1]
Image:action_icon.png Reset script conditions and actions


InvKey1OnDoor

Image:Condition_icon.png CONDITIONS

Image:Condition_icon.png Received trigger message [Key1]
Image:Condition_icon.png Query if linked object(s) [PLAYER] are within [128.00] unreal units from linked object(s) [MYSELF]

Image:action_icon.png ACTIONS

Image:action_icon.png Toggle [bIsLocked] on linked objects of type [MYSELF]
Image:action_icon.png Play sound schema [lock_unlocked] in 2D sound
Image:action_icon.png Reset script conditions and actions


Now save these scripts. You may want to group them (I called the group InventoryKey), as you will need 2 scripts for every different key (more on that later).

Go back to your InvKey1 archetype and give it the property Scripts -> TriggerScripts. Add the script InvKey1OnKey, and then save the gamesys (File -> Export Changed Scripts). Now we’re ready to see it in action!

Create a map with a few rooms, and a few doors (they can be hinged or sliding). Open the properties of one of the doors, and give it the property Lock -> bIsLocked: True. Also give it the property Scripts -> TriggerScripts, and add the script InvKey1OnDoor. Close its properties, and place an InvKey1 somewhere in the level. Build All, save, etc, and you are now ready to test it!

This is how it should work: When you pick up the key, a clinking sound should play (instead of the default inventory sound). The key is now in your inventory, and you can select it like you would a flashbomb or a health potion. The text below it should say ‘Key’. If you use the key when you are far away from the locked door, Garrett will do his ‘throwing a flashbomb’ animation (which I don’t know how to get rid of), and nothing else should happen. If you use the key while the locked door is highlighted, Garrett will do his animation again, and you will hear a lock clicking sound. Frob the door, and it should now be unlocked! You can lock it again in the same way.

Making More Keys

Because of the way the inventory system works (when you pick up an object, it is not that concrete actor that goes in your inventory, it is a new concrete of the same archetype. So if you set up the properties on a concrete, this means the one that goes into inventory will not have those properties, and will not work.), every different key must be a different archetype, and will need its own two scripts.

Create another new archetype under InvKey, and call it InvKey2. Make it placeable, and give it the property: Render -> ObjectMesh: INVKeyB(Default)

Open up the Trigger Script Manager again, and copy the script InvKey1OnKey. Rename it to InvKey2OnKey, and change the Image:action_icon.png Send trigger message [Key1] action to Image:action_icon.png Send trigger message [Key2]. Now copy the script InvKey1OnDoor, rename it to InvKey2OnDoor, and change the Image:Condition_icon.png Received trigger message [Key1] condition to Image:Condition_icon.png Received trigger message [Key2]. Save these scripts.

Back in the Actor Class Browser, give your InvKey2 the property Scripts -> TriggerScripts, and add the script InvKey2OnKey. Save the gamesys, and place an Invkey2 somewhere in your map. Now select one of the other doors you placed earlier, and give it the property Lock -> bIsLocked: True. Give it the property Scripts -> TriggerScripts and add the script InvKey2OnDoor. Build All, save, and playtest the map. If everything is set up correctly, each key should open a different door.

Adding more keys is just the same. Create a new archetype under InvKey and give it the mesh you want. Just copy the InvKey1OnKey and InvKey1OnDoor scripts, and change the trigger message in them to something different. You can make the trigger message whatever you want, as long as the corresponding two scripts use the same message. You then need to give your OnKey script to your new key archetype, and give your OnDoor script to the door it opens.

Refinements

Making a key open more than one door

This is very simple. Give the corresponding OnDoor script to any door that key can open. The doors can then be locked/unlocked independently.

Making a door that can be opened by more than one key

This is simple as well. If you want the door to be opened by Key 1 and Key 2, give it the OnDoor scripts corresponding to both of these keys

Keys and AIs

You will still have to use the normal method for giving an AI a key (using the KeyOpenStr and LockOpenStr properties).

And that’s it. Everything should work properly.


TTLG Forum Discussion



Back to Doors, Locks and Keys Tutorials Page

Back to Mission Design: World Objects Tutorials Page

Back to Mission Design Tutorials Page

Back to Main Tutorials Page

Personal tools