Frictional Games Forum (read-only)
How to make a make a door that need two keys to unlock it? - 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: How to make a make a door that need two keys to unlock it? (/thread-6807.html)

Pages: 1 2


How to make a make a door that need two keys to unlock it? - Raymond - 03-07-2011

As the title said, i need to know how Smile.


RE: How to make a make a door that need two keys to unlock it? - Tanshaydar - 03-07-2011

A little workaround is needed.

Put a local int variable and make it count every time you use a key on the door and put the if( variable is > 2) open the door function inside every callback function.


RE: How to make a make a door that need two keys to unlock it? - Nye - 03-07-2011

oh no, one key is normally boring enough! :p


RE: How to make a make a door that need two keys to unlock it? - Anxt - 03-07-2011

An example of the code Tanshaydar mentioned would look something like this:

void OnStart()
{
AddUseItemCallback("UseKey1", "Key1", "LockedDoor", "KeyCounter", true);
AddUseItemCallback("UseKey2", "Key2", "LockedDoor", "KeyCounter", true);
SetLocalVarInt("KeysUsed", 0);
}

void KeyCounter(string &in asItem, string &in asEntity)
{
SetLocalVarInt("KeysUsed", GetLocalVarInt("KeysUsed")+1);

if(GetLocalVarInt("KeysUsed")==2)
{
SetSwingDoorLocked("LockedDoor", false, true);
}
}

You could also use two separate variables and set them equal to 1 when using the key, then add a similar if statement to check if both are 1, but I think the way above is a bit easier.

Sorry if there are any typos in the code.


RE: How to make a make a door that need two keys to unlock it? - Pandemoneus - 03-07-2011

Code:
SetLocalVarInt("KeysUsed", GetLocalVarInt("KeysUsed")+1);

AddLocalVarInt("KeysUsed", 1); would do the same. Wink


RE: How to make a make a door that need two keys to unlock it? - Anxt - 03-07-2011

(03-07-2011, 07:57 PM)Pandemoneus Wrote:
Code:
SetLocalVarInt("KeysUsed", GetLocalVarInt("KeysUsed")+1);

AddLocalVarInt("KeysUsed", 1); would do the same. Wink

Really? As in, that adds 1 to the counter? For some reason I assumed "AddLocalVarInt" meant create a new one, which now that you point it out, I realize that would be redundant.

This is why I am terrible at coding! Big Grin


RE: How to make a make a door that need two keys to unlock it? - Raymond - 03-08-2011

Oh my god! Confusing Confused.


RE: How to make a make a door that need two keys to unlock it? - Anxt - 03-08-2011

Sorry about that, Raymond. I'll see if I can simplify it.

Basically what I did in my code is set up the keys to add value to a variable rather than unlock the door directly. This is because otherwise just using one key would unlock it.

The variable "KeysUsed", upon reaching 2, will call for the door to be unlocked. Each key used increases the value of "KeysUsed" by 1.

The if statement makes sure that the door is unlocked directly after using the second key, since it will check both times a key is used. The first time, it gets a value of 1, so it does nothing. The second time, it gets a value of 2, and calls for the door to be unlocked.

Hopefully that explanation didn't make things worse.


RE: How to make a make a door that need two keys to unlock it? - gandalf91 - 03-08-2011

That code doesn't seem too bad. I've had more complicated ones for complex servant spawning sequences, but then again I'm still pretty new to scripting. Tongue


RE: How to make a make a door that need two keys to unlock it? - Raymond - 03-09-2011

void OnStart()
{
AddUseItemCallback("UseKey1", "prisonkeylight_1", "mansion_3", "KeyCounter", true);
AddUseItemCallback("UseKey2", "prisonkeydark_1", "mansion_3", "KeyCounter", true);
SetLocalVarInt("KeysUsed", 0);
}

void KeyCounter(string &in asItem, string &in asEntity)
{
SetLocalVarInt("KeysUsed", GetLocalVarInt("KeysUsed")+1);

if(GetLocalVarInt("KeysUsed")==2)
{
SetSwingDoorLocked("LockedDoor", false, true);
}
}

Like this?