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
How to make a make a door that need two keys to unlock it?
Raymond Offline
Member

Posts: 126
Threads: 24
Joined: Feb 2011
Reputation: 0
#1
How to make a make a door that need two keys to unlock it?

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

One World To Another [DEMO] coming soon.
03-07-2011, 10:40 AM
Find
Tanshaydar Offline
From Beyond

Posts: 3,085
Threads: 17
Joined: Mar 2009
Reputation: 67
#2
RE: How to make a make a door that need two keys to unlock it?

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.

03-07-2011, 11:18 AM
Website Find
Nye Offline
Senior Member

Posts: 250
Threads: 8
Joined: Jan 2011
Reputation: 2
#3
RE: How to make a make a door that need two keys to unlock it?

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

03-07-2011, 01:40 PM
Find
Anxt Offline
Senior Member

Posts: 588
Threads: 12
Joined: Mar 2011
Reputation: 10
#4
RE: How to make a make a door that need two keys to unlock it?

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.

03-07-2011, 07:27 PM
Find
Pandemoneus Offline
Senior Member

Posts: 328
Threads: 2
Joined: Sep 2010
Reputation: 0
#5
RE: How to make a make a door that need two keys to unlock it?

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

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

03-07-2011, 07:57 PM
Find
Anxt Offline
Senior Member

Posts: 588
Threads: 12
Joined: Mar 2011
Reputation: 10
#6
RE: How to make a make a door that need two keys to unlock it?

(03-07-2011, 07:57 PM)Pandemoneus Wrote:
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

03-07-2011, 08:02 PM
Find
Raymond Offline
Member

Posts: 126
Threads: 24
Joined: Feb 2011
Reputation: 0
#7
RE: How to make a make a door that need two keys to unlock it?

Oh my god! Confusing Confused.

One World To Another [DEMO] coming soon.
03-08-2011, 08:28 AM
Find
Anxt Offline
Senior Member

Posts: 588
Threads: 12
Joined: Mar 2011
Reputation: 10
#8
RE: How to make a make a door that need two keys to unlock it?

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.

03-08-2011, 05:41 PM
Find
gandalf91 Offline
Senior Member

Posts: 439
Threads: 13
Joined: Feb 2011
Reputation: 0
#9
RE: How to make a make a door that need two keys to unlock it?

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
03-08-2011, 11:42 PM
Find
Raymond Offline
Member

Posts: 126
Threads: 24
Joined: Feb 2011
Reputation: 0
#10
RE: How to make a make a door that need two keys to unlock it?

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?

One World To Another [DEMO] coming soon.
03-09-2011, 10:31 AM
Find




Users browsing this thread: 1 Guest(s)