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
Using a key to unlock a door on 2 separate levels.
Cyfiawn Offline
Junior Member

Posts: 27
Threads: 8
Joined: Jun 2012
Reputation: 0
#1
Using a key to unlock a door on 2 separate levels.

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
(This post was last modified: 06-27-2012, 04:31 PM by Cyfiawn.)
06-27-2012, 03:00 PM
Find
Cruzore Offline
Senior Member

Posts: 301
Threads: 2
Joined: Jun 2012
Reputation: 37
#2
RE: Using a key to unlock a door on 2 separate levels.

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.
06-27-2012, 03:28 PM
Find
Cyfiawn Offline
Junior Member

Posts: 27
Threads: 8
Joined: Jun 2012
Reputation: 0
#3
RE: Using a key to unlock a door on 2 separate levels.

(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:
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
(This post was last modified: 06-27-2012, 03:40 PM by Cyfiawn.)
06-27-2012, 03:39 PM
Find
Cruzore Offline
Senior Member

Posts: 301
Threads: 2
Joined: Jun 2012
Reputation: 37
#4
RE: Using a key to unlock a door on 2 separate levels.

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: (Select All)
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: (Select All)
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/amn..._functions
(This post was last modified: 06-27-2012, 04:05 PM by Cruzore.)
06-27-2012, 04:03 PM
Find
Cyfiawn Offline
Junior Member

Posts: 27
Threads: 8
Joined: Jun 2012
Reputation: 0
#5
RE: Using a key to unlock a door on 2 separate levels.

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
(This post was last modified: 06-27-2012, 04:30 PM by Cyfiawn.)
06-27-2012, 04:29 PM
Find
ApeCake Offline
Member

Posts: 116
Threads: 20
Joined: Jun 2012
Reputation: 4
#6
RE: Using a key to unlock a door on 2 separate levels.

FastHunteR, why are you so amazing?
06-27-2012, 07:28 PM
Find
Cruzore Offline
Senior Member

Posts: 301
Threads: 2
Joined: Jun 2012
Reputation: 37
#7
RE: Using a key to unlock a door on 2 separate levels.

Just simple logic. Logic, and tutorials.
Nah, I'm glad to help.
06-27-2012, 07:47 PM
Find
Cyfiawn Offline
Junior Member

Posts: 27
Threads: 8
Joined: Jun 2012
Reputation: 0
#8
RE: Using a key to unlock a door on 2 separate levels.

I was on the right tracks, but I was expecting to need an extra file to store the Global Variables. Thanks again! Smile
06-27-2012, 07:49 PM
Find




Users browsing this thread: 3 Guest(s)