Rantako on 29/8/2005 at 18:54
At last! No more automatic unlocking!
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!
Part 1: 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!) 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
Conditions:
When I am used in a way from inventory
Actions:
Send trigger message [Key1]
Reset script conditions and actions
InvKey1OnDoor
Conditions:
Received trigger message [Key1]
Query if linked object(s) [PLAYER] are within [128.00] unreal units from linked object(s) [MYSELF]
Actions:
Toggle [bIsLocked] on linked objects of type [MYSELF]
Play sound schema [lock_unlocked] in 2D sound
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.
Part 2: Making More Keys
Because of the way the inventory system works, every different key must be a different archetype (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.), 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 ‘Key1’ in the script’s action to ‘Key2’. Now copy the script InvKey1OnDoor, rename it to InvKey2OnDoor, and change the ‘Key1’ in the script’s condition to ‘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.
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. If anything doesn’t work, or if anyone knows how to stop the flashbomb throwing animation, please post here.
New Horizon on 29/8/2005 at 19:03
Brilliant. That's all I have to say. :) Do you think this could work for making lock picking manual as well?
rujuro on 29/8/2005 at 19:16
Awesome. This is great. Should work for any item that needs to act on something else in the environment too. Just make the distance query match the highlight distance and it's good to go. Thanks!
Although lockpicks might be harder, since it's an actual mode you enter.
ascottk on 29/8/2005 at 19:33
Getting this to work on for the OMs is going to take a lot of work. One script per key not to mention the doors. The doors are going to be hard because the door archetypes are nonspecific while the keys are. If there was a condition to include the LockOpenStr property then I'd be more happy about this solution. It's great for a FM though.
New Horizon on 29/8/2005 at 19:45
I'm making a few alterations to this for my T3Ed installer.
I like to keep things clean and separated, so I'm creating a new archetype called KeyPowerUp that brances into Keys/ InvKey. It basically imitates the power up archetype setup and I know it adds to the bulk in the gamesys but for anyone just starting out, it will be important to have things go where they are meant to go.
I'll also have around 12 keys ready for placement with scripts.
New Horizon on 30/8/2005 at 00:20
I should also mention that a key ring is a piece of cake now. All I have to do is make InvKey stackable and give it a hudrender link to the keyring. Any key you pickup will be added to the inventory as a keyring, this will allow the player to frob any door with the key ring and as long as they have the right key...presto.
We'll still have to find a sollution for lock picks though because if they kick in....bam...keys are pointless. I have a few ideas though.
GlasWolf on 30/8/2005 at 02:38
Quote Posted by New Horizon
I should also mention that a key ring is a piece of cake now.
Can't you change the mesh? :confused:
Crispy on 30/8/2005 at 03:30
lol@GlasWolf :joke:
Lockpicking sounds slightly trickier, but (hopefully) not impossible. Add a lock to a door in the usual way, but set the lock object's frob distance to zero (so the player can't frob it). Have the lockpick as an inventory item, similar to the key, but make it broadcast a different trigger message. When the lock receives the trigger message, use a script action to frob it. Hopefully the player will then enter lock-picking mode as usual.
It depends whether the lock-picking is only triggered when the player frobs the lock or not. I'm going to try this out now.
Edit: Okay, so lockpicking is triggered by frobbing the door, not the lock. Hmm.
New Horizon on 30/8/2005 at 09:39
Quote Posted by GlasWolf
Can't you change the mesh? :confused:
Yes, with the hud render link. ;) That changes the mesh for the entire archetype because you still need the keys to appear as keys within the level. The keys have to be made stackable so you don't have a dozen key rings floating around the inventory.
New Horizon on 30/8/2005 at 09:43
Quote Posted by Crispy
lol@GlasWolf :joke:
Lockpicking sounds slightly trickier, but (hopefully) not impossible. Add a lock to a door in the usual way, but set the lock object's frob distance to zero (so the player can't frob it). Have the lockpick as an inventory item, similar to the key, but make it broadcast a different trigger message. When the lock receives the trigger message, use a script action to frob it. Hopefully the player will then enter lock-picking mode as usual.
It depends whether the lock-picking is only triggered when the player frobs the lock or not. I'm going to try this out now.
Edit: Okay, so lockpicking is triggered by frobbing the door, not the lock. Hmm.
I had some ideas on this. It's easy enough to give the player lockpicks when selecting an item from inventory but the real bugger is setting "give player lockpicks" to false after the door has been opened. My suggestion would be to check and see if the player is within a certain distance of the door and have a script that listens for a door state. When the door state changes to open, then "give player lockpicks" should be set to false.
Theoretically, the only way a person will get lock picks is when they select the lockpicks.......hmmmm. It's going to be tricky.