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


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

(01-15-2012, 11:30 AM)Tripication Wrote:
(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?
No, it didn't. =/ Didn't make any noticeable difference.

Edit: I think I know why though, Statyk told me to check the box "InteractionDisablesStuck"
That's probably it...right?


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

(01-15-2012, 11:31 AM)Shadowfied Wrote:
(01-15-2012, 11:30 AM)Tripication Wrote:
(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?
No, it didn't. =/ Didn't make any noticeable difference.

Edit: I think I know why though, Statyk told me to check the box "InteractionDisablesStuck"
That's probably it...right?
That could possible be it, although its probably better to wait for him to help you out. ive it a shot if you want, but once again, i dont have too much experience with this kinda thing, so i wouldn't be sure.
(The levers should only get stuck once the puzzle is complete, i put the SetLeverStuckState lines in the last function, and statyk does say...

custom function called each time a lever is correctly in place. when all are in place, the function continues.

So assuming that the boxes are unticked, it should work. But i dont EXACTLY know what the boxes do so be sure that you can fix it if it does stuff up)


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

(01-15-2012, 11:39 AM)Tripication Wrote:
(01-15-2012, 11:31 AM)Shadowfied Wrote:
(01-15-2012, 11:30 AM)Tripication Wrote:
(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?
No, it didn't. =/ Didn't make any noticeable difference.

Edit: I think I know why though, Statyk told me to check the box "InteractionDisablesStuck"
That's probably it...right?
That could possible be it, although its probably better to wait for him to help you out. ive it a shot if you want, but once again, i dont have too much experience with this kinda thing, so i wouldn't be sure.
(The levers should only get stuck once the puzzle is complete, i put the SetLeverStuckState lines in the last function, and statyk does say...

custom function called each time a lever is correctly in place. when all are in place, the function continues.

So assuming that the boxes are unticked, it should work. But i dont EXACTLY know what the boxes do so be sure that you can fix it if it does stuff up)
I don't really understand why I shall have that box ticked. The levers don't get stuck anyway..do they?

Edit: Nevermind. They do get stuck..

Edit 2: Ok I saw that Statyk had them getting stuck in up and down states in every func. I removed them and now it works the way I want, they only get stuck once they are all correct.


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

(01-15-2012, 11:43 AM)Shadowfied Wrote:
(01-15-2012, 11:39 AM)Tripication Wrote:
(01-15-2012, 11:31 AM)Shadowfied Wrote:
(01-15-2012, 11:30 AM)Tripication Wrote:
(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?
No, it didn't. =/ Didn't make any noticeable difference.

Edit: I think I know why though, Statyk told me to check the box "InteractionDisablesStuck"
That's probably it...right?
That could possible be it, although its probably better to wait for him to help you out. ive it a shot if you want, but once again, i dont have too much experience with this kinda thing, so i wouldn't be sure.
(The levers should only get stuck once the puzzle is complete, i put the SetLeverStuckState lines in the last function, and statyk does say...

custom function called each time a lever is correctly in place. when all are in place, the function continues.

So assuming that the boxes are unticked, it should work. But i dont EXACTLY know what the boxes do so be sure that you can fix it if it does stuff up)
I don't really understand why I shall have that box ticked. The levers don't get stuck anyway..do they?

Edit: Nevermind. They do get stuck..
They shouldn't. Just try it anyway, im sure its nothing you cant undo.


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

(01-15-2012, 11:46 AM)Tripication Wrote:
(01-15-2012, 11:43 AM)Shadowfied Wrote:
(01-15-2012, 11:39 AM)Tripication Wrote:
(01-15-2012, 11:31 AM)Shadowfied Wrote:
(01-15-2012, 11:30 AM)Tripication Wrote: I did, but did it work?
No, it didn't. =/ Didn't make any noticeable difference.

Edit: I think I know why though, Statyk told me to check the box "InteractionDisablesStuck"
That's probably it...right?
That could possible be it, although its probably better to wait for him to help you out. ive it a shot if you want, but once again, i dont have too much experience with this kinda thing, so i wouldn't be sure.
(The levers should only get stuck once the puzzle is complete, i put the SetLeverStuckState lines in the last function, and statyk does say...

custom function called each time a lever is correctly in place. when all are in place, the function continues.

So assuming that the boxes are unticked, it should work. But i dont EXACTLY know what the boxes do so be sure that you can fix it if it does stuff up)
I don't really understand why I shall have that box ticked. The levers don't get stuck anyway..do they?

Edit: Nevermind. They do get stuck..
They shouldn't. Just try it anyway, im sure its nothing you cant undo.
Read my edit 2. ^^




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

(01-15-2012, 11:47 AM)Shadowfied Wrote:
(01-15-2012, 11:46 AM)Tripication Wrote:
(01-15-2012, 11:43 AM)Shadowfied Wrote:
(01-15-2012, 11:39 AM)Tripication Wrote:
(01-15-2012, 11:31 AM)Shadowfied Wrote: No, it didn't. =/ Didn't make any noticeable difference.

Edit: I think I know why though, Statyk told me to check the box "InteractionDisablesStuck"
That's probably it...right?
That could possible be it, although its probably better to wait for him to help you out. ive it a shot if you want, but once again, i dont have too much experience with this kinda thing, so i wouldn't be sure.
(The levers should only get stuck once the puzzle is complete, i put the SetLeverStuckState lines in the last function, and statyk does say...

custom function called each time a lever is correctly in place. when all are in place, the function continues.

So assuming that the boxes are unticked, it should work. But i dont EXACTLY know what the boxes do so be sure that you can fix it if it does stuff up)
I don't really understand why I shall have that box ticked. The levers don't get stuck anyway..do they?

Edit: Nevermind. They do get stuck..
They shouldn't. Just try it anyway, im sure its nothing you cant undo.
Read my edit 2. ^^
Oh, that sucks, hang on, i've just had a brillian stroke of genius...
Next post...





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

(01-15-2012, 11:49 AM)Tripication Wrote:
(01-15-2012, 11:47 AM)Shadowfied Wrote:
(01-15-2012, 11:46 AM)Tripication Wrote:
(01-15-2012, 11:43 AM)Shadowfied Wrote:
(01-15-2012, 11:39 AM)Tripication Wrote: That could possible be it, although its probably better to wait for him to help you out. ive it a shot if you want, but once again, i dont have too much experience with this kinda thing, so i wouldn't be sure.
(The levers should only get stuck once the puzzle is complete, i put the SetLeverStuckState lines in the last function, and statyk does say...

custom function called each time a lever is correctly in place. when all are in place, the function continues.

So assuming that the boxes are unticked, it should work. But i dont EXACTLY know what the boxes do so be sure that you can fix it if it does stuff up)
I don't really understand why I shall have that box ticked. The levers don't get stuck anyway..do they?

Edit: Nevermind. They do get stuck..
They shouldn't. Just try it anyway, im sure its nothing you cant undo.
Read my edit 2. ^^
Oh, that sucks, hang on, i've just had a brillian stroke of genius...
Next post...
Well, thanks for your help. =)




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

Try Duplicating the levers and deactivating the duplicates, turn the InteractionDisablesStuck off on the Inactive duplicates and do 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)
{
SetEntityActive("LEVER1", false);
SetEntityActive("LEVER2", false);
SetEntityActive("LEVER3", false);
SetEntityActive("LEVER4", false);
SetEntityActive("LEVER1_1", true);
SetEntityActive("LEVER2_1", true);
SetEntityActive("LEVER3_1", true);
SetEntityActive("LEVER4_1", true);
SetLeverStuckState("LEVER1_1", 1, false);
SetLeverStuckState("LEVER2_1", 1, false);
SetLeverStuckState("LEVER3_1", -1, false);
SetLeverStuckState("LEVER4_1", 1, false);

GiveSanityBoost();
SetSwingDoorLocked("LEVERDOOR", false, true);
}
}






I'm assuming the Duplicates will have a _1 at the end of the original name.


Ya dig?
(NOTE:May not be Genius...BACKUPS BEFORE COMPLAINING)


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

Uhm..I thought I already told you I solved it?

Statyk had put "SetLeverStuckState("LEVER4", 1, true);" in every function, removing all of those and adding your "SetLeverStuckState" scripts at the end solved it. There was no reason (not that I understand anyway) to make them stuck all the time and using the InteractDisablesStuck checkbox for this situation.


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

Here's a more efficient way of doing it (though entirely untested).

PHP Code:
const string[] lever_names = {"LEVER1""LEVER2""LEVER3""LEVER4"}
const 
int[] desired_lever_states = {11, -11}

/******************************************************************************/

void OnStart()
{
    
SetEntityConnectionStateChangeCallback("LEVER1""lever_func");
    
SetEntityConnectionStateChangeCallback("LEVER2""lever_func");
    
SetEntityConnectionStateChangeCallback("LEVER3""lever_func");
    
SetEntityConnectionStateChangeCallback("LEVER4""lever_func");

    
SetLocalVarInt("LEVER1"0);
    
SetLocalVarInt("LEVER2"0);
    
SetLocalVarInt("LEVER3"0);
    
SetLocalVarInt("LEVER4"0);
}

/******************************************************************************/

void lever_func(string &in asEntityint alState)
{
    if (
GetLocalVarInt("LEVER_PUZZLE_COMPLETE") == 1)
        return;

    
SetLocalVarInt(asEntityalState);    
    
CheckFunction();
}

/******************************************************************************/

void CheckFunction()
{
    for (
int i 0lever_names.length(); ++i)
    {
        if (
GetLocalVarInt(lever_names[i]) != desired_lever_states[i])
            return;
        else
        {
            
SetLeverStuckState(lever_names[i], desired_lever_states[i], true);
            
SetEntityConnectionStateChangeCallback(lever_names[i], "");
        }
    }
    
    
GiveSanityBoost();
    
SetSwingDoorLocked("LEVERDOOR"falsetrue);
    
SetLocalVarInt("LEVER_PUZZLE_COMPLETE"1);