Frictional Games Forum (read-only)
Lever-Pulling Combination Help - 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 (https://www.frictionalgames.com/forum/forum-35.html)
+--- Thread: Lever-Pulling Combination Help (/thread-7746.html)



Lever-Pulling Combination Help - Kyle - 05-01-2011

I have been working on a script for a while and for some reason, it doesn't work the way I want it to work. The player is supposed to pull down 5 levers in a certain order and there are 2 combinations that they can use.

These are the levers: 1 2 3 4 5
Combinations: 4 5 2 1 3
5 1 3 2 4

I don't want the combinations to combine in a way. So this is my somewhat advanced script that should have taken care of it, but doesn't work, yet still can run:

Code:
void OnStart()
{
    SetLocalVarInt("Lever", 1);
    SetEntityConnectionStateChangeCallback("lever_simple01_22", "L1");
    SetEntityConnectionStateChangeCallback("lever_simple01_23", "L2");
    SetEntityConnectionStateChangeCallback("lever_simple01_24", "L3");
    SetEntityConnectionStateChangeCallback("lever_simple01_25", "L4");
    SetEntityConnectionStateChangeCallback("lever_simple01_26", "L5");
    Check();
}
void Check()
{
    if (GetLocalVarInt("Lever") == 6)
    {
        GiveSanityBoost();
        int x = RandInt(1, 2);
        if (x == 1)
        {
            SetSwingDoorLocked("castle_1", false, true);
            SetSwingDoorClosed("castle_1", false, true);
            return;
        }
        else if (x == 2)
        {
            SetSwingDoorLocked("castle_2", false, true);
            SetSwingDoorClosed("castle_2", false, true);
            return;
        }
    }
}
void L5(string &in asEntity, int alState)
{
    if (alState == 1)
    {
        if (GetLocalVarInt("Lever") == 4)
        {
            AddLocalVarInt("Lever", 1);
            SetEntityInteractionDisabled("lever_simple_26", true);
            return;
        }
        else if (GetLocalVarInt("Lever") == 3)
        {
            AddLocalVarInt("Lever", 1);
            SetEntityInteractionDisabled("lever_simple_26", true);
            return;
        }
        else if ((GetLocalVarInt("Lever") != 3) || (GetLocalVarInt("Lever") != 4))
        {
            SetLocalVarInt("Lever", 1);
            for (int i = 22; i <= 26 && i >= 22; i++)
            {
                SetEntityInteractionDisabled("lever_simple01_"+i, false);
            }
            return;
        }
    }
}
void L4(string &in asEntity, int alState)
{
    if (alState == 1)
    {
        if (GetLocalVarInt("Lever") == 1)
        {
            AddLocalVarInt("lever", 1);
            SetEntityInteractionDisabled("lever_simple_25", true);
            return;
        }
        else if (GetLocalVarInt("Lever") == 2)
        {
            AddLocalVarInt("Lever", 1);
            SetEntityInteractionDisabled("lever_simple_25", true);
            return;
        }
        else if ((GetLocalVarInt("Lever") != 1) || (GetLocalVarInt("Lever") != 2))
        {
            SetLocalVarInt("Lever", 1);
            for (int i = 22; i <= 26 && i >= 22; i++)
            {
                SetEntityInteractionDisabled("lever_simple01_"+i, false);
            }
            return;
        }
    }
}
void L3(string &in asEntity, int alState)
{
    if (alState == 1)
    {
        if (GetLocalVarInt("Lever") == 3)
        {
            AddLocalVarInt("lever", 1);
            SetEntityInteractionDisabled("lever_simple_24", true);
            return;
        }
        else if (GetLocalVarInt("Lever") == 2)
        {
            AddLocalVarInt("Lever", 1);
            SetEntityInteractionDisabled("lever_simple_24", true);
            return;
        }
        else if ((GetLocalVarInt("Lever") != 3) || (GetLocalVarInt("Lever") != 2))
        {
            SetLocalVarInt("Lever", 1);
            for (int i = 22; i <= 26 && i >= 22; i++)
            {
                SetEntityInteractionDisabled("lever_simple01_"+i, false);
            }
            return;
        }
    }
}
void L2(string &in asEntity, int alState)
{
    if (alState == 1)
    {
        if (GetLocalVarInt("Lever") == 1)
        {
            AddLocalVarInt("lever", 1);
            SetEntityInteractionDisabled("lever_simple_23", true);
            return;
        }
        else if (GetLocalVarInt("Lever") == 5)
        {
            AddLocalVarInt("Lever", 1);
            SetEntityInteractionDisabled("lever_simple_23", true);
            return;
        }
        else if ((GetLocalVarInt("Lever") != 1) || (GetLocalVarInt("Lever") != 5))
        {
            SetLocalVarInt("Lever", 1);
            for (int i = 22; i <= 26 && i >= 22; i++)
            {
                SetEntityInteractionDisabled("lever_simple01_"+i, false);
            }
            return;
        }
    }
}
void L1(string &in asEntity, int alState)
{
    if (alState == 1)
    {
        if (GetLocalVarInt("Lever") == 5)
        {
            AddLocalVarInt("lever", 1);
            SetEntityInteractionDisabled("lever_simple_22", true);
            return;
        }
        else if (GetLocalVarInt("Lever") == 4)
        {
            AddLocalVarInt("Lever", 1);
            SetEntityInteractionDisabled("lever_simple_22", true);
            return;
        }
        else if ((GetLocalVarInt("Lever") != 5) || (GetLocalVarInt("Lever") != 4))
        {
            SetLocalVarInt("Lever", 1);
            for (int i = 22; i <= 26 && i >= 22; i++)
            {
                SetEntityInteractionDisabled("lever_simple01_"+i, false);
            }
            return;
        }
    }
}



RE: Lever-Pulling Combination Help - Tanshaydar - 05-01-2011

I have a puzzle and nicely coded and it works. To give an example:
Code:
removed code

Simply, I have an int variable and when buttons pressed in order it counts, and when filan button pressed it checks whether int value is expected or not.


RE: Lever-Pulling Combination Help - Kyle - 05-01-2011

I don't really understand what the script is trying to show in comparison to mine, but I'm adding debug messages to zero in on the issue.

I think I found the problem, or at least part of it...


RE: Lever-Pulling Combination Help - Tanshaydar - 05-02-2011

Step by step:

Assume you have password 4 5 2 1 3

Pulled 1: If variable int is 3 then set the int variable to 4; if not set the int variable to 0.
Pulled 2: If variable int is 2 then set the int variable to 3; if not set the int variable to 0.
Pulled 3: If variable int is 4 then do whatever needed; if not set the int variable to 0.
Pulled 4: Set the int variable to 1.
Pulled 5: If variable int is 1 then set the int variable to 2; if not set the int variable to 0.


RE: Lever-Pulling Combination Help - Kyle - 05-02-2011

It's alright, I got most if it fixed with my handy-dandy debug messages. Big Grin

I got it to where you pull all the levers in the correct order and you can't interact with them anymore, I can do the rest. Thanks for your help! Smile