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 Need help to make a lever puzzle
Shadowfied Offline
Senior Member

Posts: 261
Threads: 34
Joined: Jul 2010
Reputation: 5
#1
Need help to make a lever puzzle

Hi everybody.

Again working hard on my custom story, I need some help.

I'm making a lever puzzle, in which 4 levers need to be in the right positions. I'm not good at these types of scripts so I'd appreciate some help.

Like in the control room in the main story, I have one of those panels with 4 levers on. I wanna make a puzzle in which the levers need to be.

Lever 1 = Up
Lever 2 = Up
Lever 3 = Down
Lever 4 = Up

I have no idea how to script this unless I'm gonna make them get stuck in the right state, but then it wouldn't be a puzzle.

Any ideas?

Thanks in advance.

Current - Castle Darkuan
Other - F*cked Map
01-14-2012, 11:55 AM
Find
Statyk Offline
Schrödinger's Mod

Posts: 4,390
Threads: 72
Joined: Sep 2011
Reputation: 241
#2
RE: Need help to make a lever puzzle

I'm jamming out to music full blast in my house since no one is home. Meanwhile, I will try this, as I could learn from it =P
01-14-2012, 06:21 PM
Find
Shadowfied Offline
Senior Member

Posts: 261
Threads: 34
Joined: Jul 2010
Reputation: 5
#3
RE: Need help to make a lever puzzle

(01-14-2012, 06:21 PM)Statyk Wrote: I'm jamming out to music full blast in my house since no one is home. Meanwhile, I will try this, as I could learn from it =P
Thank you man.

Current - Castle Darkuan
Other - F*cked Map
01-14-2012, 06:22 PM
Find
Statyk Offline
Schrödinger's Mod

Posts: 4,390
Threads: 72
Joined: Sep 2011
Reputation: 241
#4
RE: Need help to make a lever puzzle

I got it working, tested it in my "testng map" and everything works fine. Just switched caps to your info like usual =] I actually learned a good amount from this! Thanks!

NOTE: Go into the Level Editor, to each lever and make sure "InteractionDisablesStuck" is CHECKED. this way the player can move the still levers after they are stuck.

//_______________________________

void OnStart();
{
SetEntityConnectionStateChangeCallback("LEVER1", "lever1func"); //levercallback
SetEntityConnectionStateChangeCallback("LEVER2", "lever2func"); //levercallback
SetEntityConnectionStateChangeCallback("LEVER3", "lever3func"); //levercallback
SetEntityConnectionStateChangeCallback("LEVER4", "lever4func"); //levercallback

SetLocalVarInt("lever1bank", 0); //'dem banks!
SetLocalVarInt("lever2bank", 0); //'dem banks!
SetLocalVarInt("lever3bank", 0); //'dem banks!
SetLocalVarInt("lever4bank", 0); //'dem banks!
}


/////////////////////////////////////////////////////////


void lever1func(string &in asEntity, int alState)
{
if(alState == 1)
{
SetLeverStuckState("LEVER1", 1, true); //sets it stuck
SetLocalVarInt("lever1bank", 1); //add dat cash munay
CheckFunction(); //follows function at the bottom, which activates the completed puzzle
}
if(alState == -1)
{
SetLeverStuckState("LEVER1", -1, true);
SetLocalVarInt("lever1bank", 0);
}
}

//////////////////////////////////////////////////////////////////////

void lever2func(string &in asEntity, int alState)
{
if(alState == 1)
{
SetLeverStuckState("LEVER2", 1, true);
SetLocalVarInt("lever2bank", 1);
CheckFunction();
}
if(alState == -1)
{
SetLeverStuckState("LEVER2", -1, true);
SetLocalVarInt("lever2bank", 0);
}
}

//////////////////////////////////////////////////////////////////////

void lever3func(string &in asEntity, int alState) //follows a different "if" statement, making it opposite from the rest or... Down rather than Up.
{
if(alState == 1)
{
SetLeverStuckState("LEVER3", 1, true);
SetLocalVarInt("lever3bank", 0);
}
if(alState == -1)
{
SetLeverStuckState("LEVER3", -1, true);
SetLocalVarInt("lever3bank", 1);
CheckFunction();
}
}

//////////////////////////////////////////////////////////////////////

void lever4func(string &in asEntity, int alState)
{
if(alState == 1)
{
SetLeverStuckState("LEVER4", 1, true);
SetLocalVarInt("lever4bank", 1);
CheckFunction();
}
if(alState == -1)
{
SetLeverStuckState("LEVER4", -1, true);
SetLocalVarInt("lever4bank", 0);
}
}

//////////////////////////

void CheckFunction() //custom function called each time a lever is correctly in place. when all are in place, the function continues.
{
if(GetLocalVarInt("lever1bank") == 1 && GetLocalVarInt("lever2bank") == 1 && GetLocalVarInt("lever3bank") == 1 && GetLocalVarInt("lever4bank") == 1)
{
GiveSanityBoost();
SetSwingDoorLocked("LEVERDOOR", false, true);
}
}





Also, If the levers are facing wrong directions, instead of changing the script, just rotate the levers =P
(This post was last modified: 01-14-2012, 07:59 PM by Statyk.)
01-14-2012, 07:39 PM
Find
Shadowfied Offline
Senior Member

Posts: 261
Threads: 34
Joined: Jul 2010
Reputation: 5
#5
RE: Need help to make a lever puzzle

Gonna try it now. Will tell you what happens.

Edit: Doesn't work. =(

The game crashes giving me this error:
[Image: lcMU1l.jpg]

I copied your script exactly, making sure to name the levers accordingly, and put out a door just to follow your script.
Spoiler below!

void OnStart();
{
SetEntityConnectionStateChangeCallback("LEVER1", "lever1func"); //levercallback
SetEntityConnectionStateChangeCallback("LEVER2", "lever2func"); //levercallback
SetEntityConnectionStateChangeCallback("LEVER3", "lever3func"); //levercallback
SetEntityConnectionStateChangeCallback("LEVER4", "lever4func"); //levercallback

SetLocalVarInt("lever1bank", 0); //'dem banks!
SetLocalVarInt("lever2bank", 0); //'dem banks!
SetLocalVarInt("lever3bank", 0); //'dem banks!
SetLocalVarInt("lever4bank", 0); //'dem banks!
}


/////////////////////////////////////////////////////////


void lever1func(string &in asEntity, int alState)
{
if(alState == 1)
{
SetLeverStuckState("LEVER1", 1, true); //sets it stuck
SetLocalVarInt("lever1bank", 1); //add dat cash munay
CheckFunction(); //follows function at the bottom, which activates the completed puzzle
}
if(alState == -1)
{
SetLeverStuckState("LEVER1", -1, true);
SetLocalVarInt("lever1bank", 0);
}
}

//////////////////////////////////////////////////////////////////////

void lever2func(string &in asEntity, int alState)
{
if(alState == 1)
{
SetLeverStuckState("LEVER2", 1, true);
SetLocalVarInt("lever2bank", 1);
CheckFunction();
}
if(alState == -1)
{
SetLeverStuckState("LEVER2", -1, true);
SetLocalVarInt("lever2bank", 0);
}
}

//////////////////////////////////////////////////////////////////////

void lever3func(string &in asEntity, int alState) //follows a different "if" statement, making it opposite from the rest or... Down rather than Up.
{
if(alState == 1)
{
SetLeverStuckState("LEVER3", 1, true);
SetLocalVarInt("lever3bank", 0);
}
if(alState == -1)
{
SetLeverStuckState("LEVER3", -1, true);
SetLocalVarInt("lever3bank", 1);
CheckFunction();
}
}

//////////////////////////////////////////////////////////////////////

void lever4func(string &in asEntity, int alState)
{
if(alState == 1)
{
SetLeverStuckState("LEVER4", 1, true);
SetLocalVarInt("lever4bank", 1);
CheckFunction();
}
if(alState == -1)
{
SetLeverStuckState("LEVER4", -1, true);
SetLocalVarInt("lever4bank", 0);
}
}

//////////////////////////

void CheckFunction() //custom function called each time a lever is correctly in place. when all are in place, the function continues.
{
if(GetLocalVarInt("lever1bank") == 1 && GetLocalVarInt("lever2bank") == 1 && GetLocalVarInt("lever3bank") == 1 && GetLocalVarInt("lever4bank") == 1)
{
GiveSanityBoost();
SetSwingDoorLocked("LEVERDOOR", false, true);
}
}


I have no idea how to fix this as I'm unfamiliar with this type of scripting.

Any ideas?


Current - Castle Darkuan
Other - F*cked Map
(This post was last modified: 01-15-2012, 10:43 AM by Shadowfied.)
01-15-2012, 10:31 AM
Find
flamez3 Offline
Posting Freak

Posts: 1,281
Threads: 48
Joined: Apr 2011
Reputation: 57
#6
RE: Need help to make a lever puzzle

You have a ; at the end of void OnStart(), delete it.

01-15-2012, 10:54 AM
Find
Shadowfied Offline
Senior Member

Posts: 261
Threads: 34
Joined: Jul 2010
Reputation: 5
#7
RE: Need help to make a lever puzzle

(01-15-2012, 10:54 AM)flamez3 Wrote: You have a ; at the end of void OnStart(), delete it.
Haha thanks. That's what happens, when you're working with something more advanced then you're used to and you run into an error, you assume it's caused by something you don't understand. If I would have noticed that I would have known that it doesn't belong there.

Thank you. =)

EDIT: Alright Statyk, it works. But there are a few problems..

1. You can keep pushing the last lever to the right state over and over and get a shitload of sanity boosts.
2. When it's done, I want the levers to lock in place, if possible.

Even if you cant help me with these two things, you have been of huge help once again. What would I do without you? <3

Current - Castle Darkuan
Other - F*cked Map
(This post was last modified: 01-15-2012, 11:02 AM by Shadowfied.)
01-15-2012, 10:57 AM
Find
Tripication Offline
Member

Posts: 172
Threads: 19
Joined: Dec 2011
Reputation: 6
#8
RE: Need help to make a lever puzzle

Ok a wild stab in the dark with very little testing(that means BACKUP YOUR SCRIPT) but try this.




void OnStart()
{
SetEntityConnectionStateChangeCallback("LEVER1", "lever1func"); //levercallback
SetEntityConnectionStateChangeCallback("LEVER2", "lever2func"); //levercallback
SetEntityConnectionStateChangeCallback("LEVER3", "lever3func"); //levercallback
SetEntityConnectionStateChangeCallback("LEVER4", "lever4func"); //levercallback

SetLocalVarInt("lever1bank", 0); //'dem banks!
SetLocalVarInt("lever2bank", 0); //'dem banks!
SetLocalVarInt("lever3bank", 0); //'dem banks!
SetLocalVarInt("lever4bank", 0); //'dem banks!
}


/////////////////////////////////////////////////////////


void lever1func(string &in asEntity, int alState)
{
if(alState == 1)
{
SetLeverStuckState("LEVER1", 1, true); //sets it stuck
SetLocalVarInt("lever1bank", 1); //add dat cash munay
CheckFunction(); //follows function at the bottom, which activates the completed puzzle
}
if(alState == -1)
{
SetLeverStuckState("LEVER1", -1, true);
SetLocalVarInt("lever1bank", 0);
}
}

//////////////////////////////////////////////////////////////////////

void lever2func(string &in asEntity, int alState)
{
if(alState == 1)
{
SetLeverStuckState("LEVER2", 1, true);
SetLocalVarInt("lever2bank", 1);
CheckFunction();
}
if(alState == -1)
{
SetLeverStuckState("LEVER2", -1, true);
SetLocalVarInt("lever2bank", 0);
}
}

//////////////////////////////////////////////////////////////////////

void lever3func(string &in asEntity, int alState) //follows a different "if" statement, making it opposite from the rest or... Down rather than Up.
{
if(alState == 1)
{
SetLeverStuckState("LEVER3", 1, true);
SetLocalVarInt("lever3bank", 0);
}
if(alState == -1)
{
SetLeverStuckState("LEVER3", -1, true);
SetLocalVarInt("lever3bank", 1);
CheckFunction();
}
}

//////////////////////////////////////////////////////////////////////

void lever4func(string &in asEntity, int alState)
{
if(alState == 1)
{
SetLeverStuckState("LEVER4", 1, true);
SetLocalVarInt("lever4bank", 1);
CheckFunction();
}
if(alState == -1)
{
SetLeverStuckState("LEVER4", -1, true);
SetLocalVarInt("lever4bank", 0);
}
}

//////////////////////////

void CheckFunction() //custom function called each time a lever is correctly in place. when all are in place, the function continues.
{
if(GetLocalVarInt("lever1bank") == 1 && GetLocalVarInt("lever2bank") == 1 && GetLocalVarInt("lever3bank") == 1 && GetLocalVarInt("lever4bank") == 1)
{
SetLeverStuckState("LEVER1", 1, false);
SetLeverStuckState("LEVER2", 1, false);
SetLeverStuckState("LEVER3", -1, false);
SetLeverStuckState("LEVER4", 1, false);
GiveSanityBoost();
SetSwingDoorLocked("LEVERDOOR", false, true);
}
}

[Image: speedart__2___yoshimitsu_by_kamofudge-d4yo6kk.png]
01-15-2012, 11:26 AM
Find
Shadowfied Offline
Senior Member

Posts: 261
Threads: 34
Joined: Jul 2010
Reputation: 5
#9
RE: Need help to make a lever puzzle

You only added the 4 stuckstate lines at the end? (Just so I learn Tongue)

Current - Castle Darkuan
Other - F*cked Map
01-15-2012, 11:28 AM
Find
Tripication Offline
Member

Posts: 172
Threads: 19
Joined: Dec 2011
Reputation: 6
#10
RE: Need help to make a lever puzzle

(01-15-2012, 11:28 AM)Shadowfied Wrote: You only added the 4 stuckstate lines at the end? (Just so I learn Tongue)
I did, but did it work?

PS. Statyk is truly an amazing scripter, he really has lived up to his rep(Posting freak)
PPS. I just player your hunter minimap in the 24 hour amnesia, loved it Big Grin

[Image: speedart__2___yoshimitsu_by_kamofudge-d4yo6kk.png]
(This post was last modified: 01-15-2012, 11:31 AM by Tripication.)
01-15-2012, 11:30 AM
Find




Users browsing this thread: 1 Guest(s)