Frictional Games Forum (read-only)

Full Version: Making a lever unlock a door?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Thanks for answering my last question, but a new one has arisen. In my cs, I have a .map called 'The Undercroft', where you need to go down a few levels and pull a lever. This lever, I pictured, would open a door back up on the main floor that was previously locked for security reasons. How should I go about this? Should I make a GetLeverState function of sorts that will set a global variable to true, unlock the door in a different map? The separation of maps is the tricky part Tongue Thanks
You should use a
SetEntityConnectionStateChangeCallback

Along with SetGlobalVarInt.
Then, when entering the map with the door, use an if statement to determine if the global variable has been changed to 1(or whatever you changed it to when you pulled the lever) and then set the door to unlocked if it evaluates to true.
void OnStart()
{
SetEntityConnectionStateChangeCallback("LEVER", "LEVER_CALLBACK");
}

void LEVER_CALLBACK(string &in asEntity, int alState)

{
if(alState == 1)
{
SetGlobalVarInt("OPENDOORINT", 1);
}
}

In the other level:

void OnEnter()
{
if(GetGlobalVarInt("OPENDOORINT") == 1)
{
SetSwingDoorLocked("DOOR", false, true);
}
}
(07-13-2012, 08:18 PM)beecake Wrote: [ -> ]void OnStart()
{
SetEntityConnectionStateChangeCallback("LEVER", "LEVER_CALLBACK");
}

void LEVER_CALLBACK(string &in asEntity, int alState)

{
if(alState == 1)
{
SetGlobalVarInt("OPENDOORINT", 1);
}
}

In the other level:

void OnEnter()
{
if(GetGlobalVarInt("OPENDOORINT") == 1)
{
SetSwingDoorLocked("DOOR", false, true);
}
}
Thanks! For that if statement, is the alState on the lever all the way up or down? And the global variable gets declared in an HPS file in the maps folder called 'global'?
1 = up
0 = middle
-1 = down
No you don't have to create a folder... It just is there somewhere i guess.. I don't know maybe i'm wrong, but in the custom story i'm making right now, i have no folder for the globals, and it worked fine ^^
<removed><removed><removed>
SetGlobalVarInt("Ongka", 1); // This creates a number called Ongka, which has the value 1.
if(GetGlobalVarInt("Ongka") == 1) // == means equal to; this functions asks if the number Ongka has the value 1. If you didn't set the value to 1, nothing will happen. Global vars can be used in other levels too.