The following warnings occurred:
Warning [2] count(): Parameter must be an array or an object that implements Countable - Line: 906 - File: showthread.php PHP 7.2.24-0ubuntu0.18.04.17 (Linux)
File Line Function
/showthread.php 906 errorHandler->error



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


Messages In This Thread
Universal Unlock door with item script - by ModManDann - 01-13-2011, 04:44 PM



Users browsing this thread: 1 Guest(s)