Frictional Games Forum (read-only)
Using a key to unlock a door on 2 separate levels. - 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 - Development (https://www.frictionalgames.com/forum/forum-38.html)
+---- Forum: Development Support (https://www.frictionalgames.com/forum/forum-39.html)
+---- Thread: Using a key to unlock a door on 2 separate levels. (/thread-16534.html)



Using a key to unlock a door on 2 separate levels. - Cyfiawn - 06-27-2012

Hello,

I have 2 maps, with 2 doorways to each other (Upper and Lower).
Both doors start locked.
The player unlocks the Upper door first and goes through the door.
Then in the second map, they get another key to unlock the Lower door.
The problem is that when the player unlocks the Lower door from Map 2 side and returns to Map 1, the door is still locked from the Map 1 side. How can I unlock a door from both sides on the 2 separate maps?


Obviously, I can have the Upper door on Map 2 unlocked from the start, as the only way of getting to that door from that side is by unlocking it from the other side.

Here is an image to show the layout: http://i.imgur.com/SE2wE.jpg

Thanks,
Cyfiawn

PS. Sorry, I find it hard to explain this well, hopefully you get the idea. Smile


RE: Using a key to unlock a door on 2 separate levels. - Cruzore - 06-27-2012

use a global variable, set it 0 at start, 1 once you unlocked it from the other side, and let the first side unlock when that global variable is 1. If you need more directions, like a sample script, just let me know.


RE: Using a key to unlock a door on 2 separate levels. - Cyfiawn - 06-27-2012

(06-27-2012, 03:28 PM)FastHunteR Wrote: use a global variable, set it 0 at start, 1 once you unlocked it from the other side, and let the first side unlock when that global variable is 1. If you need more directions, like a sample script, just let me know.
Thanks for the reply,

I was thinking of that, but where can I put global variables, and how can I change it from the maps .hps file?
Map 1 hps = Mansion_WestWing.hps
Map 2 hps = Mansion_Courtyard.hps

I guess it would be something like:
Code:
void UnlockLCYDoor(string &in item, string &in door) {    

PlaySoundAtEntity("unlock_door", "unlock_door.snt", "level_hub_2", 0.0f, false);

SetLevelDoorLocked("level_hub_1", false);  
      
RemoveItem("Key_LowerCourtyard");
    
GlobalFile.GlobalVariable = true;

}


Some example code would be great. Smile

Thanks,
Cyfiawn


RE: Using a key to unlock a door on 2 separate levels. - Cruzore - 06-27-2012

at first, i'll make a sample script, then explain it to you.
The key will be named key, the door at map 1(where your problem is at) is named level_door1, and the door in map 2 is named level_door2.
in map 2 .hps:
PHP Code:
void OnStart()
{

AddUseItemCallback("""key""level_door2""UnlockDoor"true);
}
void UnlockDoor(string &in asItemstring &in asEntity
{
SetLevelDoorLocked("level_door2"false); 


RemoveItem("key");
SetGlobalVarInt("DoorLocked"1);


in map 1 .hps:
PHP Code:
void OnStart()
{
SetGlobalVarInt("DoorLocked"0);
}
void OnEnter()
{
if(
GetGlobalVarInt("DoorLocked")==1)
{
SetLevelDoorLocked("level_door1"false); 
}

Now for the explanation:
When you first enter map 1, the global variable "DoorLocked" is set 0.
When you pick up the key and use it on the map 2 level door, it will be unlocked and the global variable "DoorLocked" is set 1.
Now, when you go through that door to map 1, OnEnter() will run again, but OnStart() not, since you've been there already.
So, OnEnter() will run, and will check with an if-statement if the global variable "DoorLocked" is 1. if it is, then the levle door in map 1 will get unlocked. If not, nothing happens.
It is required for the if-statement to be in OnEnter(), since this way, you check every time you enter the map if that variable is 1, thus unlocking the door once you did on the other side. Now, if you want to prevent it opening at some time later, just set the global variable 0. Once you've set it 0 later, it will never get to be 1 again, unless you scripted to do it at some later point, since it only gets to be 1 when you used the key on the door.
Hope that cleared up a bit. If you need to see the syntax of how to set up a global variable or something, just search for the name at http://wiki.frictionalgames.com/hpl2/amnesia/script_functions


RE: Using a key to unlock a door on 2 separate levels. - Cyfiawn - 06-27-2012

Works great. Thanks. Didn't realise you could set Global Variables without the need for a file to store them in. I'll be sure to add you to the credits once the story is complete! Wink


RE: Using a key to unlock a door on 2 separate levels. - ApeCake - 06-27-2012

FastHunteR, why are you so amazing?


RE: Using a key to unlock a door on 2 separate levels. - Cruzore - 06-27-2012

Just simple logic. Logic, and tutorials.
Nah, I'm glad to help.


RE: Using a key to unlock a door on 2 separate levels. - Cyfiawn - 06-27-2012

I was on the right tracks, but I was expecting to need an extra file to store the Global Variables. Thanks again! Smile