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.
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


Messages In This Thread
RE: Using a key to unlock a door on 2 separate levels. - by Cruzore - 06-27-2012, 04:03 PM



Users browsing this thread: 1 Guest(s)