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"