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?
Athom Offline
Junior Member

Posts: 32
Threads: 6
Joined: Jul 2012
Reputation: 1
#1
Combination Lock Using Levers Code?

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!

Current Projects: The Cure 15%
4Shared Download: http://ow.ly/cqjk4
Youtube Video: http://ow.ly/cq2LR
07-16-2012, 10:36 AM
Find
Traggey Offline
is mildly amused

Posts: 3,257
Threads: 74
Joined: Feb 2012
Reputation: 185
#2
RE: Combination Lock Using Levers Code?

Wrong forum section, this goes to development support, not tech support, moved.
07-16-2012, 12:06 PM
Find
Ongka Offline
Member

Posts: 225
Threads: 3
Joined: Nov 2010
Reputation: 20
#3
RE: Combination Lock Using Levers Code?

Which combination should unlock the cabinet?
231 is the same as 123. The only difference is the name of levers.

[Image: 18694.png]
07-16-2012, 01:52 PM
Find
Athom Offline
Junior Member

Posts: 32
Threads: 6
Joined: Jul 2012
Reputation: 1
#4
RE: Combination Lock Using Levers Code?

(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?

Current Projects: The Cure 15%
4Shared Download: http://ow.ly/cqjk4
Youtube Video: http://ow.ly/cq2LR
(This post was last modified: 07-16-2012, 06:28 PM by Athom.)
07-16-2012, 06:27 PM
Find
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
Ongka Offline
Member

Posts: 225
Threads: 3
Joined: Nov 2010
Reputation: 20
#6
RE: Combination Lock Using Levers Code?

It might look pretty confusing for a beginner, because of the const string and all that.
But anyway, nice work there buddy!

[Image: 18694.png]
07-17-2012, 12:07 AM
Find
Athom Offline
Junior Member

Posts: 32
Threads: 6
Joined: Jul 2012
Reputation: 1
#7
RE: Combination Lock Using Levers Code?

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!

Current Projects: The Cure 15%
4Shared Download: http://ow.ly/cqjk4
Youtube Video: http://ow.ly/cq2LR
(This post was last modified: 07-18-2012, 09:57 AM by Athom.)
07-18-2012, 09:20 AM
Find




Users browsing this thread: 2 Guest(s)