RurouniMori
Junior Member
Posts: 11
Threads: 3
Joined: Apr 2013
Reputation:
0
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
Tomato Cat
Senior Member
Posts: 287
Threads: 2
Joined: Sep 2012
Reputation:
20
RE: Lever Puzzle Help
As far as sticking the lever goes, use this:
SetLeverStuckState ( string & asName , int alState , bool abEffects );
I'll look into your other script.
05-09-2013, 11:08 PM
RurouniMori
Junior Member
Posts: 11
Threads: 3
Joined: Apr 2013
Reputation:
0
RE: Lever Puzzle Help
(05-09-2013, 11:08 PM) Tomato Cat Wrote: As far as sticking the lever goes, use this:
SetLeverStuckState ( string & asName , int alState , bool abEffects );
I'll look into your other script.
Thank you! Tis' appreciated!
05-09-2013, 11:22 PM
PutraenusAlivius
Posting Freak
Posts: 4,713
Threads: 75
Joined: Dec 2012
Reputation:
119
RE: Lever Puzzle Help
To reset, add an else if like this.
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 ); } else if { //EFFECTS } }
"Veni, vidi, vici."
"I came, I saw, I conquered."
05-10-2013, 12:10 AM
Tomato Cat
Senior Member
Posts: 287
Threads: 2
Joined: Sep 2012
Reputation:
20
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:
SetLocalVarInt ( "Lever" , 0 ); SetLocalVarInt ( "Correct" , 0 ); SetEntityConnectionStateChangeCallback ( "lever_nice01_*" , "LeverCallback" );
Here's the main function:
Spoiler below!
void LeverCallback ( string & in asEntity , int alState ) { AddDebugMessage ( "Lever " + asEntity + " " + alState , false ); if( alState == 1 ) { if( GetLocalVarInt ( "Lever" ) == 0 ) { if( asEntity == "lever_nice01_1" ) { SetLeverStuckState ( asEntity , 1 , true ); AddLocalVarInt ( "Lever" , 1 ); AddDebugMessage ( asEntity , false ); } else if( asEntity == "lever_nice01_2" ) { AddLocalVarInt ( "Correct" , 1 ); AddDebugMessage ( asEntity , false ); SetLeverStuckState ( asEntity , 1 , true ); AddLocalVarInt ( "Lever" , 1 ); } else if( asEntity == "lever_nice01_3" ) { SetLeverStuckState ( asEntity , 1 , true ); AddLocalVarInt ( "Lever" , 1 ); AddDebugMessage ( asEntity , false ); } } else if( GetLocalVarInt ( "Lever" ) == 1 ) { if( asEntity == "lever_nice01_1" ) { SetLeverStuckState ( asEntity , 1 , true ); AddLocalVarInt ( "Lever" , 1 ); AddDebugMessage ( asEntity , false ); } else if( asEntity == "lever_nice01_2" ) { AddDebugMessage ( asEntity , false ); SetLeverStuckState ( asEntity , 1 , true ); AddLocalVarInt ( "Lever" , 1 ); } else if( asEntity == "lever_nice01_3" ) { SetLeverStuckState ( asEntity , 1 , true ); AddLocalVarInt ( "Lever" , 1 ); AddDebugMessage ( asEntity , false ); AddLocalVarInt ( "Correct" , 1 ); } }
And a continuation...
else if( GetLocalVarInt ( "Lever" ) == 2 ) { if( asEntity == "lever_nice01_1" ) { SetLeverStuckState ( asEntity , 1 , true ); AddDebugMessage ( asEntity , false ); AddLocalVarInt ( "Correct" , 1 ); CheckLever (); } else if( asEntity == "lever_nice01_2" ) { AddDebugMessage ( asEntity , false ); SetLeverStuckState ( asEntity , 1 , true ); CheckLever (); } else if( asEntity == "lever_nice01_3" ) { SetLeverStuckState ( asEntity , 1 , true ); AddDebugMessage ( asEntity , false ); CheckLever (); } } } }
This is the function that checks the order:
Spoiler below!
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
RurouniMori
Junior Member
Posts: 11
Threads: 3
Joined: Apr 2013
Reputation:
0
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:
SetLocalVarInt ( "Lever" , 0 ); SetLocalVarInt ( "Correct" , 0 ); SetEntityConnectionStateChangeCallback ( "lever_nice01_*" , "LeverCallback" );
Here's the main function:
Spoiler below!
void LeverCallback ( string & in asEntity , int alState ) { AddDebugMessage ( "Lever " + asEntity + " " + alState , false ); if( alState == 1 ) { if( GetLocalVarInt ( "Lever" ) == 0 ) { if( asEntity == "lever_nice01_1" ) { SetLeverStuckState ( asEntity , 1 , true ); AddLocalVarInt ( "Lever" , 1 ); AddDebugMessage ( asEntity , false ); } else if( asEntity == "lever_nice01_2" ) { AddLocalVarInt ( "Correct" , 1 ); AddDebugMessage ( asEntity , false ); SetLeverStuckState ( asEntity , 1 , true ); AddLocalVarInt ( "Lever" , 1 ); } else if( asEntity == "lever_nice01_3" ) { SetLeverStuckState ( asEntity , 1 , true ); AddLocalVarInt ( "Lever" , 1 ); AddDebugMessage ( asEntity , false ); } } else if( GetLocalVarInt ( "Lever" ) == 1 ) { if( asEntity == "lever_nice01_1" ) { SetLeverStuckState ( asEntity , 1 , true ); AddLocalVarInt ( "Lever" , 1 ); AddDebugMessage ( asEntity , false ); } else if( asEntity == "lever_nice01_2" ) { AddDebugMessage ( asEntity , false ); SetLeverStuckState ( asEntity , 1 , true ); AddLocalVarInt ( "Lever" , 1 ); } else if( asEntity == "lever_nice01_3" ) { SetLeverStuckState ( asEntity , 1 , true ); AddLocalVarInt ( "Lever" , 1 ); AddDebugMessage ( asEntity , false ); AddLocalVarInt ( "Correct" , 1 ); } }
And a continuation...
else if( GetLocalVarInt ( "Lever" ) == 2 ) { if( asEntity == "lever_nice01_1" ) { SetLeverStuckState ( asEntity , 1 , true ); AddDebugMessage ( asEntity , false ); AddLocalVarInt ( "Correct" , 1 ); CheckLever (); } else if( asEntity == "lever_nice01_2" ) { AddDebugMessage ( asEntity , false ); SetLeverStuckState ( asEntity , 1 , true ); CheckLever (); } else if( asEntity == "lever_nice01_3" ) { SetLeverStuckState ( asEntity , 1 , true ); AddDebugMessage ( asEntity , false ); CheckLever (); } } } }
This is the function that checks the order:
Spoiler below!
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
RurouniMori
Junior Member
Posts: 11
Threads: 3
Joined: Apr 2013
Reputation:
0
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
Tomato Cat
Senior Member
Posts: 287
Threads: 2
Joined: Sep 2012
Reputation:
20
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
RurouniMori
Junior Member
Posts: 11
Threads: 3
Joined: Apr 2013
Reputation:
0
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
Tomato Cat
Senior Member
Posts: 287
Threads: 2
Joined: Sep 2012
Reputation:
20
RE: Lever Puzzle Help
No problem. Happy to help!
05-10-2013, 03:20 AM