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
Script Help Lever Puzzle Help
RurouniMori Offline
Junior Member

Posts: 11
Threads: 3
Joined: Apr 2013
Reputation: 0
#1
Lever Puzzle Help

I'm trying to make a lever puzzle where after three levers are pulled in a certain order, a painting slides, and a key falls. I've made a fair amount of progress on my script so far as a whole, but I'd definitely still say I'm a noob. XP I'm having issues getting the levers to work and therefore, for the puzzle to work at all.

Basically, what I want to happen is:
1. Read a note that has a riddle on it, levers are made active.
2. Pull lever1, lever2, then lever3 in order.
3. The painting slides over, key is made active, it falls, puzzle solved.

I don't know how to make it so the levers lock after use, that way you know you pulled it in the right direction and it worked. And if I can figure out or get help how to do this, how can I reset it if they do it wrong?

Here's my script (just the puzzle related info):
////////////////////////////
// Run first time starting map
void OnEnter()
{
        SetEntityCallbackFunc("puzzlenote", "OnRead");
        SetEntityConnectionStateChangeCallback("lever1", "LeverStateChange");
        SetEntityConnectionStateChangeCallback("lever2", "LeverStateChange");
        SetEntityConnectionStateChangeCallback("lever3", "LeverStateChange");
}

void OnRead(string &in asEntity, string &in type)
{
        AddQuest("puzzle", "puzzle");
        SetEntityActive("lever1", true);
        SetEntityActive("lever2", true);
        SetEntityActive("lever3", true);
}
void LeverStateChange(string &in asEntity, int alState)
{
        if((GetLeverState("lever1") == 1) && (GetLeverState("lever2") == 1) && (GetLeverState("lever3") == 1))
        {
            PlaySoundAtEntity("","level_wood_min_max01.snt", "lever3", 0, false);
            AddPropForce("themaiden", 200, 0, 0, "mylordscurse_1");
            AddTimer("", 2, "PaintingMove");
            SetEntityInteractionDisabled("lever1", true);
            SetEntityInteractionDisabled("lever2", true);
            SetEntityInteractionDisabled("lever3", true);
        }
}
void PaintingMove(string &in asTimer)
{
        SetEntityActive("chapter2key", true);
        SetPlayerSanity(90);
        PlayMusic("10_puzzle01.ogg", false, 0.7, 0.1, 10, false);
}

Any help would be greatly appreciated! Thank you!
05-09-2013, 10:05 PM
Find
Tomato Cat Offline
Senior Member

Posts: 287
Threads: 2
Joined: Sep 2012
Reputation: 20
#2
RE: Lever Puzzle Help

As far as sticking the lever goes, use this:

PHP Code: (Select All)
SetLeverStuckState(stringasNameint alStatebool abEffects); 

I'll look into your other script.
05-09-2013, 11:08 PM
Find
RurouniMori Offline
Junior Member

Posts: 11
Threads: 3
Joined: Apr 2013
Reputation: 0
#3
RE: Lever Puzzle Help

(05-09-2013, 11:08 PM)Tomato Cat Wrote: As far as sticking the lever goes, use this:

PHP Code: (Select All)
SetLeverStuckState(stringasNameint alStatebool abEffects); 

I'll look into your other script.

Thank you! Tis' appreciated! Smile
05-09-2013, 11:22 PM
Find
PutraenusAlivius Offline
Posting Freak

Posts: 4,713
Threads: 75
Joined: Dec 2012
Reputation: 119
#4
RE: Lever Puzzle Help

To reset, add an else if like this.
PHP Code: (Select All)
void LeverStateChange(string &in asEntityint alState)
{
if((
GetLeverState("lever1") == 1) && (GetLeverState("lever2") == 1) && (GetLeverState("lever3") == 1)) 
{
PlaySoundAtEntity("","level_wood_min_max01.snt""lever3"0false);
AddPropForce("themaiden"20000"mylordscurse_1");
AddTimer(""2"PaintingMove");
SetEntityInteractionDisabled("lever1"true);
SetEntityInteractionDisabled("lever2"true);
SetEntityInteractionDisabled("lever3"true);
}

else if
{
//EFFECTS
}


"Veni, vidi, vici."
"I came, I saw, I conquered."
(This post was last modified: 05-10-2013, 12:10 AM by PutraenusAlivius.)
05-10-2013, 12:10 AM
Find
Tomato Cat Offline
Senior Member

Posts: 287
Threads: 2
Joined: Sep 2012
Reputation: 20
#5
RE: Lever Puzzle Help

Ok, try this out.

Basically what's happening is that a variable is incremented each time you pull a lever, which is locked in place. (But if it's the correct lever, a separate variable is incremented.) This repeats until all 3 levers are pulled and function checks to see if the levers were pulled in the correct order.

Add these to OnStart, first:
PHP Code: (Select All)
SetLocalVarInt("Lever",0);
SetLocalVarInt("Correct",0);
SetEntityConnectionStateChangeCallback("lever_nice01_*""LeverCallback"); 

Here's the main function:
Spoiler below!

PHP Code: (Select All)
void LeverCallback(string &in asEntityint alState)
        {    
            
AddDebugMessage("Lever "+asEntity " "+alState,false);
            
            if(
alState == 1)
            {
            
                if(
GetLocalVarInt("Lever") == 0)
                {
                    if(
asEntity == "lever_nice01_1")
                    {
                        
SetLeverStuckState(asEntity1true);
                        
AddLocalVarInt("Lever",1);
                        
AddDebugMessage(asEntity,false);
                    }
                    
                    else if(
asEntity == "lever_nice01_2")
                    {
                        
AddLocalVarInt("Correct",1);
                        
AddDebugMessage(asEntity,false);
                        
SetLeverStuckState(asEntity1true);
                        
AddLocalVarInt("Lever",1);
                    }
                    
                    else if(
asEntity == "lever_nice01_3")
                    {
                        
SetLeverStuckState(asEntity1true);
                        
AddLocalVarInt("Lever",1);
                        
AddDebugMessage(asEntity,false);
                    }    
                }
                
                else if(
GetLocalVarInt("Lever") == 1)
                {
                    if(
asEntity == "lever_nice01_1")
                    {
                        
SetLeverStuckState(asEntity1true);
                        
AddLocalVarInt("Lever",1);
                        
AddDebugMessage(asEntity,false);
                    }
                    
                    else if(
asEntity == "lever_nice01_2")
                    {
                        
AddDebugMessage(asEntity,false);
                        
SetLeverStuckState(asEntity1true);
                        
AddLocalVarInt("Lever",1);
                    }
                    
                    else if(
asEntity == "lever_nice01_3")
                    {
                        
SetLeverStuckState(asEntity1true);
                        
AddLocalVarInt("Lever",1);
                        
AddDebugMessage(asEntity,false);
                        
AddLocalVarInt("Correct",1);
                    }    
                } 

And a continuation...
PHP Code: (Select All)
                else if(GetLocalVarInt("Lever") == 2)
                {
                    if(
asEntity == "lever_nice01_1")
                    {
                        
SetLeverStuckState(asEntity1true);
                        
                        
AddDebugMessage(asEntity,false);
                        
AddLocalVarInt("Correct",1);
                        
CheckLever();
                    }
                    
                    else if(
asEntity == "lever_nice01_2")
                    {
                        
AddDebugMessage(asEntity,false);
                        
SetLeverStuckState(asEntity1true);
                
                        
CheckLever();
                    }
                    
                    else if(
asEntity == "lever_nice01_3")
                    {
                        
SetLeverStuckState(asEntity1true);
                        
                        
AddDebugMessage(asEntity,false);
                        
CheckLever();
                    }    
                }
            }
        } 


This is the function that checks the order:

Spoiler below!
PHP Code: (Select All)
void CheckLever()
{
    if(
GetLocalVarInt("Correct") == 3)
    {
        
AddDebugMessage("Correct order. Good job!",false);
    }
    
    else
    {
        
AddDebugMessage("Incorrect order!",false);
        
SetLeverStuckState("lever_nice01_1",0,true);
        
SetLeverStuckState("lever_nice01_2",0,true);
        
SetLeverStuckState("lever_nice01_3",0,true);
        
SetLocalVarInt("Correct",0);
        
SetLocalVarInt("Lever",0);
    }


(This post was last modified: 05-10-2013, 12:29 AM by Tomato Cat.)
05-10-2013, 12:27 AM
Find
RurouniMori Offline
Junior Member

Posts: 11
Threads: 3
Joined: Apr 2013
Reputation: 0
#6
RE: Lever Puzzle Help

(05-10-2013, 12:27 AM)Tomato Cat Wrote: Ok, try this out.

Basically what's happening is that a variable is incremented each time you pull a lever, which is locked in place. (But if it's the correct lever, a separate variable is incremented.) This repeats until all 3 levers are pulled and function checks to see if the levers were pulled in the correct order.

Add these to OnStart, first:
PHP Code: (Select All)
SetLocalVarInt("Lever",0);
SetLocalVarInt("Correct",0);
SetEntityConnectionStateChangeCallback("lever_nice01_*""LeverCallback"); 

Here's the main function:
Spoiler below!

PHP Code: (Select All)
void LeverCallback(string &in asEntityint alState)
        {    
            
AddDebugMessage("Lever "+asEntity " "+alState,false);
            
            if(
alState == 1)
            {
            
                if(
GetLocalVarInt("Lever") == 0)
                {
                    if(
asEntity == "lever_nice01_1")
                    {
                        
SetLeverStuckState(asEntity1true);
                        
AddLocalVarInt("Lever",1);
                        
AddDebugMessage(asEntity,false);
                    }
                    
                    else if(
asEntity == "lever_nice01_2")
                    {
                        
AddLocalVarInt("Correct",1);
                        
AddDebugMessage(asEntity,false);
                        
SetLeverStuckState(asEntity1true);
                        
AddLocalVarInt("Lever",1);
                    }
                    
                    else if(
asEntity == "lever_nice01_3")
                    {
                        
SetLeverStuckState(asEntity1true);
                        
AddLocalVarInt("Lever",1);
                        
AddDebugMessage(asEntity,false);
                    }    
                }
                
                else if(
GetLocalVarInt("Lever") == 1)
                {
                    if(
asEntity == "lever_nice01_1")
                    {
                        
SetLeverStuckState(asEntity1true);
                        
AddLocalVarInt("Lever",1);
                        
AddDebugMessage(asEntity,false);
                    }
                    
                    else if(
asEntity == "lever_nice01_2")
                    {
                        
AddDebugMessage(asEntity,false);
                        
SetLeverStuckState(asEntity1true);
                        
AddLocalVarInt("Lever",1);
                    }
                    
                    else if(
asEntity == "lever_nice01_3")
                    {
                        
SetLeverStuckState(asEntity1true);
                        
AddLocalVarInt("Lever",1);
                        
AddDebugMessage(asEntity,false);
                        
AddLocalVarInt("Correct",1);
                    }    
                } 

And a continuation...
PHP Code: (Select All)
                else if(GetLocalVarInt("Lever") == 2)
                {
                    if(
asEntity == "lever_nice01_1")
                    {
                        
SetLeverStuckState(asEntity1true);
                        
                        
AddDebugMessage(asEntity,false);
                        
AddLocalVarInt("Correct",1);
                        
CheckLever();
                    }
                    
                    else if(
asEntity == "lever_nice01_2")
                    {
                        
AddDebugMessage(asEntity,false);
                        
SetLeverStuckState(asEntity1true);
                
                        
CheckLever();
                    }
                    
                    else if(
asEntity == "lever_nice01_3")
                    {
                        
SetLeverStuckState(asEntity1true);
                        
                        
AddDebugMessage(asEntity,false);
                        
CheckLever();
                    }    
                }
            }
        } 


This is the function that checks the order:

Spoiler below!
PHP Code: (Select All)
void CheckLever()
{
    if(
GetLocalVarInt("Correct") == 3)
    {
        
AddDebugMessage("Correct order. Good job!",false);
    }
    
    else
    {
        
AddDebugMessage("Incorrect order!",false);
        
SetLeverStuckState("lever_nice01_1",0,true);
        
SetLeverStuckState("lever_nice01_2",0,true);
        
SetLeverStuckState("lever_nice01_3",0,true);
        
SetLocalVarInt("Correct",0);
        
SetLocalVarInt("Lever",0);
    }



Wow thanks! I'll try this out and get back to you! XD
05-10-2013, 01:37 AM
Find
RurouniMori Offline
Junior Member

Posts: 11
Threads: 3
Joined: Apr 2013
Reputation: 0
#7
RE: Lever Puzzle Help

Okay, so I got it all in there, I edited to fit my script and map.

The levers go into a position and lock, that's exactly what I want. If you move them in the wrong order, it resets and makes the sounds I want. BUT it does not do as I want when it IS in the right order. It just resets. Did I miss something?

Again, what I want to happen, is the painting I have to move, the key to be made active, and fall out.

OnEnter Script:
Quote:SetLocalVarInt("Lever",0);
SetLocalVarInt("Correct",0);
SetEntityConnectionStateChangeCallback("lever1", "LeverCallback");
SetEntityConnectionStateChangeCallback("lever2", "LeverCallback");
SetEntityConnectionStateChangeCallback("lever3", "LeverCallback");

Main Script:
Quote:void LeverCallback(string &in asEntity, int alState)
{
if(alState == 1)
{

if(GetLocalVarInt("Lever") == 0)
{
if(asEntity == "lever1")
{
SetLeverStuckState("lever1", 1, true);
AddLocalVarInt("Lever",1);
}

else if(asEntity == "lever2")
{
AddLocalVarInt("Correct",1);
SetLeverStuckState("lever2", 1, true);
AddLocalVarInt("Lever",1);
}

else if(asEntity == "lever3")
{
SetLeverStuckState("lever3", 1, true);
AddLocalVarInt("Lever", 1);
}
}

else if(GetLocalVarInt("Lever") == 1)
{
if(asEntity == "lever1")
{
SetLeverStuckState("lever1", 1, true);
AddLocalVarInt("Lever",1);
}

else if(asEntity == "lever2")
{
SetLeverStuckState("lever2", 1, true);
AddLocalVarInt("Lever",1);
}

else if(asEntity == "lever3")
{
SetLeverStuckState("lever3", 1, true);
AddLocalVarInt("Lever", 1);
AddLocalVarInt("Correct",1);
}
}
else if(GetLocalVarInt("Lever") == 2)
{
if(asEntity == "lever1")
{
SetLeverStuckState("lever1", 1, true);
AddLocalVarInt("Correct",1);
CheckLever();
}

else if(asEntity == "lever2")
{
SetLeverStuckState("lever2", 1, true);
CheckLever();
}

else if(asEntity == "lever3")
{
SetLeverStuckState("lever3", 1, true);
CheckLever();
}
}
}
}
void CheckLever()
{
if(GetLocalVarInt("Correct") == 3)
{
SetPlayerSanity(90);
PlayMusic("10_puzzle01.ogg", false, 0.7, 0.1, 10, false);
AddPropForce("themaiden", 200, 0, 0, "mylordscurse_1");
AddTimer("", 2, "PaintingMove");
}

else
{
PlaySoundAtEntity("","level_wood_min_max01.snt", "lever1", 0, false);
PlaySoundAtEntity("","level_wood_min_max01.snt", "lever2", 0, false);
PlaySoundAtEntity("","level_wood_min_max01.snt", "lever3", 0, false);
SetLeverStuckState("lever1",0,true);
SetLeverStuckState("lever2",0,true);
SetLeverStuckState("lever3",0,true);
SetLocalVarInt("Correct",0);
SetLocalVarInt("Lever",0);
}
}
void PaintingMove(string &in asTimer)
{
SetEntityActive("chapter2key", true);
AddPropForce("chapter2key", 0, -200, 0, "mylordscurse_1");
PlaySoundAtEntity("", "25_drop_key.snt", "chapter2key", 0, false);
}
05-10-2013, 02:46 AM
Find
Tomato Cat Offline
Senior Member

Posts: 287
Threads: 2
Joined: Sep 2012
Reputation: 20
#8
RE: Lever Puzzle Help

When I was testing it, I set the correct order to 231. That might not be what you like. =p

You can modify it by changing where the "Correct" variable appears.
05-10-2013, 02:59 AM
Find
RurouniMori Offline
Junior Member

Posts: 11
Threads: 3
Joined: Apr 2013
Reputation: 0
#9
RE: Lever Puzzle Help

(05-10-2013, 02:59 AM)Tomato Cat Wrote: When I was testing it, I set the correct order to 231. That might not be what you like. =p

You can modify it by changing where the "Correct" variable appears.
Ooooh! Well jeez, now I just feel silly. XP lol. Still learning, I'mma working on that. Thank you!
05-10-2013, 03:07 AM
Find
Tomato Cat Offline
Senior Member

Posts: 287
Threads: 2
Joined: Sep 2012
Reputation: 20
#10
RE: Lever Puzzle Help

No problem. Happy to help!
05-10-2013, 03:20 AM
Find




Users browsing this thread: 2 Guest(s)