Frictional Games Forum (read-only)

Full Version: Combination Lock Using Levers Code?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hey everybody! I want to make a combination lock with three levers. The levers are named lever_1, lever_2, and lever_3. I want it to be arranged as 231. so, lever_2, lever_3, lever_1 I need somebody else to write a sample code for this as i am a huge noob. When the correct combination is put in, i want a cabinet to slide/spin to reveal a secret wall with a key inside. If anybody can get back to me with a sample code, i will be eternally grateful!

Thank you!
Wrong forum section, this goes to development support, not tech support, moved.
Which combination should unlock the cabinet?
231 is the same as 123. The only difference is the name of levers.
(07-16-2012, 01:52 PM)Ongka Wrote: [ -> ]Which combination should unlock the cabinet?
231 is the same as 123. The only difference is the name of levers.
I want them

im sorry. I didnt know i should post in that section. I want 3 levers in a room and when pulled in this order (middle, right, left) a secret bookcase will open. Can anybody help me with this?
At first i was going to explain it all, but decided just to post some code:

PHP Code:
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.
It might look pretty confusing for a beginner, because of the const string and all that.
But anyway, nice work there buddy!
I got a friend to help me with the script for it. Here it is for anyone who wants to use it!



void LeverPulled(string &in asEntity, int alState)
{
if(GetLocalVarInt("Sequence") == 0 && asEntity == "lever_2")
{
AddLocalVarInt("Sequence", 1);
SetLeverStuckState(asEntity, alState, true);
PlaySoundAtEntity("", "27_tunnel.snt", "Player", 0, false);
}
if(GetLocalVarInt("Sequence") == 1 && asEntity == "lever_1")
{
AddLocalVarInt("Sequence", 1);
SetLeverStuckState(asEntity, alState, true);
PlaySoundAtEntity("", "27_tunnel.snt", "Player", 0, false);
}
if(GetLocalVarInt("Sequence") == 2 && asEntity == "lever_3")
{
AddLocalVarInt("Sequence", 1);
SetLeverStuckState(asEntity, alState, true);
SetMoveObjectState("shelf_secret_door_1", 1);
PlaySoundAtEntity("", "scrape_wood_heavy.snt", "Player", 0, false);
PlaySoundAtEntity("", "27_tunnel.snt", "Player", 0, false);
StopSound("tunnel", 1.0f);
GiveSanityBoostsmall();
}

There you go. I think it is a bit simpler than the above script! ENJOY!
Small edit, fixing "tunnel" sound lasting for a LONG time!

(07-18-2012, 09:20 AM)Athom Wrote: [ -> ]I got a friend to help me with the script for it. Here it is for anyone who wants to use it!



void LeverPulled(string &in asEntity, int alState)
{
if(GetLocalVarInt("Sequence") == 0 && asEntity == "lever_2")
{
AddLocalVarInt("Sequence", 1);
SetLeverStuckState(asEntity, alState, true);
PlaySoundAtEntity("", "27_tunnel.snt", "Player", 0, false);
}
if(GetLocalVarInt("Sequence") == 1 && asEntity == "lever_1")
{
AddLocalVarInt("Sequence", 1);
SetLeverStuckState(asEntity, alState, true);
PlaySoundAtEntity("", "27_tunnel.snt", "Player", 0, false);
}
if(GetLocalVarInt("Sequence") == 2 && asEntity == "lever_3")
{
AddLocalVarInt("Sequence", 1);
SetLeverStuckState(asEntity, alState, true);
SetMoveObjectState("shelf_secret_door_1", 1);
PlaySoundAtEntity("", "scrape_wood_heavy.snt", "Player", 0, false);
PlaySoundAtEntity("", "27_tunnel.snt", "Player", 0, false);
StopSound("tunnel", 1.0f);
GiveSanityBoostsmall();
}

There you go. I think it is a bit simpler than the above script! ENJOY!
Small edit, fixing "tunnel" sound lasting for a LONG time!
I give thanks for writing this script to andyrockin123 and Obliviator27! I love you guys! You RULE!