Facebook Twitter YouTube Frictional Games | Forum | Privacy Policy | Dev Blog | Dev Wiki | Support | Gametee


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Universal Unlock door with item script
ModManDann Offline
Member

Posts: 61
Threads: 6
Joined: Dec 2010
Reputation: 0
#1
Universal Unlock door with item script

As I've been seeing a lot of "how to make a key unlock my door" I've decided to write a small script which unlocks any door with any key. All you need to do is add this piece of code to your map script:

void UnlockDoor(string &in asItem, string &in asEntity)
    {
        SetSwingDoorLocked(asEntity,false, true);
        PlaySoundAtEntity("", "unlock_door", asEntity, 0.0f, false);
       // Remove double slashes to remove the key from inventory
       //RemoveItem(asItem);
    }

and add the following code in the OnEnter() function or the OnStart function:

AddUseItemCallback("", "<your key name>","<your door name>", "UnlockDoor", true);

You can use the same function for any amount for doors you need to open with keys, so an example level script file:

void UnlockDoor(string &in asItem, string &in asEntity)
    {
        SetSwingDoorLocked(asEntity,false, true);
        PlaySoundAtEntity("", "unlock_door", asEntity, 0.0f, false);
       // Remove double slashes to remove the key from inventory
       //RemoveItem(asItem);
    }

void onStart()
    {
    }

void onEnter()
    {
        AddUseItemCallback("", "cellar_key_1","cellar_door_2", "UnlockDoor", true);
        AddUseItemCallback("", "cellar_key_2","cellar_door_5", "UnlockDoor", true);
    }

If we run the map of the above example, we would be able to open cellar_door_2 with the key cellar_key_1 and cellar_door_5 with cellar_key_2.

The script also works with non-key items, an extreme example:

void onEnter()
    {
        AddUseItemCallback("", "aggripas_head","cellar_door_5", "UnlockDoor", true);
    }

now if we use aggripas_head on cellar_door_5 it will unlock.

I hope after this thread there will be less thread posts about "how do I open a door with a key or item"

Current project: Mind Trap
01-13-2011, 04:44 PM
Find
Frontcannon Offline
Senior Member

Posts: 538
Threads: 10
Joined: Jul 2010
Reputation: 2
#2
RE: Universal Unlock door with item script

We already have a universal 'key on door'-script somewhere, but let's hope the now stickied script recollection will quell the influx of these posts.


╔═════════════════╗
☺ Smoke weed everyday ☺
╚═════════════════╝
(This post was last modified: 01-13-2011, 05:14 PM by Frontcannon.)
01-13-2011, 05:14 PM
Find




Users browsing this thread: 1 Guest(s)