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
Combination Lock Using Levers Code?
Your Computer Offline
SCAN ME!

Posts: 3,456
Threads: 32
Joined: Jul 2011
Reputation: 235
#5
RE: Combination Lock Using Levers Code?

At first i was going to explain it all, but decided just to post some code:

PHP Code: (Select All)
const string[] secret_door_lever_positions =
    {
"secret_door_first_lever",
     
"secret_door_second_lever",
     
"secret_door_third_lever"};

void OnStart ()
{
    
SetEntityConnectionStateChangeCallback("lever_left""SecretDoorLevers");
    
SetEntityConnectionStateChangeCallback("lever_middle""SecretDoorLevers");
    
SetEntityConnectionStateChangeCallback("lever_right""SecretDoorLevers");

    
ClearSecretDoorLevers();
    
ResetSecretDoorLevers();
}

void ClearSecretDoorLevers()
{
    
SetLocalVarString(secret_door_lever_positions[0], "");
    
SetLocalVarString(secret_door_lever_positions[1], "");
    
SetLocalVarString(secret_door_lever_positions[2], "");
}

void ResetSecretDoorLevers()
{
    
SetLeverStuckState("lever_left"0true);
    
SetLeverStuckState("lever_middle"0true);
    
SetLeverStuckState("lever_right"0true);
}

void SecretDoorLevers(string &in entityint state)
{
    
SetLeverStuckState(entitystatefalse);

    for (
int i 0secret_door_lever_positions.length(); ++i)
    {
        if (
GetLocalVarString(secret_door_lever_positions[i]) == "")
        {
            
SetLocalVarString(secret_door_lever_positions[i], entity);
            break;
        }
    }

    
CheckSecretDoorLeversOrder();
}

void CheckSecretDoorLeversOrder()
{
    if (
GetLocalVarString(secret_door_lever_positions[0]) == "lever_middle"
     
&& GetLocalVarString(secret_door_lever_positions[1]) == "lever_right"
     
&& GetLocalVarString(secret_door_lever_positions[2]) == "lever_left")
    {
        
CompleteSecretDoorLeversPuzzle();
    }

    else if (
GetLocalVarString(secret_door_lever_positions[0]) != ""
     
&& GetLocalVarString(secret_door_lever_positions[1]) != ""
     
&& GetLocalVarString(secret_door_lever_positions[2]) != "")
    {
        
ClearSecretDoorLevers();
        
ResetSecretDoorLevers();
    }
}

void CompleteSecretDoorLeversPuzzle()
{
    
AddDebugMessage("Secret door puzzle complete!"false);
    Print(
"Secret door puzzle complete!");
    
// Open secret door


Note, you'll have to change the names of the levers to "lever_middle", "lever_left" and "lever_right". Since you didn't specify which state you want the levers to be pulled at, pulling them in either direction should work.

Tutorials: From Noob to Pro
(This post was last modified: 07-16-2012, 11:26 PM by Your Computer.)
07-16-2012, 11:19 PM
Website Find


Messages In This Thread
Combination Lock Using Levers Code? - by Athom - 07-16-2012, 10:36 AM
RE: Combination Lock Using Levers Code? - by Your Computer - 07-16-2012, 11:19 PM



Users browsing this thread: 1 Guest(s)