Frictional Games Forum (read-only)
[SCRIPT] Need help to make a lever puzzle - Printable Version

+- Frictional Games Forum (read-only) (https://www.frictionalgames.com/forum)
+-- Forum: Amnesia: The Dark Descent (https://www.frictionalgames.com/forum/forum-6.html)
+--- Forum: Custom Stories, TCs & Mods - Development (https://www.frictionalgames.com/forum/forum-38.html)
+---- Forum: Development Support (https://www.frictionalgames.com/forum/forum-39.html)
+---- Thread: [SCRIPT] Need help to make a lever puzzle (/thread-12581.html)

Pages: 1 2 3


Need help to make a lever puzzle - Shadowfied - 01-14-2012

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.



RE: Need help to make a lever puzzle - Statyk - 01-14-2012

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


RE: Need help to make a lever puzzle - Shadowfied - 01-14-2012

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



RE: Need help to make a lever puzzle - Statyk - 01-14-2012

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


RE: Need help to make a lever puzzle - Shadowfied - 01-15-2012

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?




RE: Need help to make a lever puzzle - flamez3 - 01-15-2012

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



RE: Need help to make a lever puzzle - Shadowfied - 01-15-2012

(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


RE: Need help to make a lever puzzle - Tripication - 01-15-2012

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);
}
}



RE: Need help to make a lever puzzle - Shadowfied - 01-15-2012

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



RE: Need help to make a lever puzzle - Tripication - 01-15-2012

(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