Frictional Games Forum (read-only)
Universal Unlock door with item script - Printable Version

+- Frictional Games Forum (read-only) (https://www.frictionalgames.com/forum)
+-- Forum: Amnesia: The Dark Descent (https://www.frictionalgames.com/forum/forum-6.html)
+--- Forum: Custom Stories, TCs & Mods (https://www.frictionalgames.com/forum/forum-35.html)
+--- Thread: Universal Unlock door with item script (/thread-6193.html)



Universal Unlock door with item script - ModManDann - 01-13-2011

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:

Code:
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:

Code:
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:

Code:
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:

Code:
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"


RE: Universal Unlock door with item script - Frontcannon - 01-13-2011

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.