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 - Tripication - 01-15-2012

(01-15-2012, 11:55 AM)Shadowfied Wrote: 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.
Oh, thats good then. NVM about the last post.
And good luck with the rest of your story


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

(01-15-2012, 11:56 AM)Your Computer Wrote: 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);

Wow that's a lot shorter. I appreciate it, although for now I'm gonna stick with what I understand myself so I have use for it and know what I'm doing.


Thank you very much Tripication.



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

Ahh, that was fun. Time for tea.


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

(01-15-2012, 12:02 PM)Tripication Wrote: Ahh, that was fun. Time for tea.
Enjoy it. ;]



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

(01-15-2012, 11:56 AM)Your Computer Wrote: 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);




Goodness gracious great balls of fire, this is ridiculous... XD I have a lot to learn! I might give this a whirl to try it out. Also need to find time to watch your scripting tutorial. And guys, I'm really NOT the best scripter. I'm glad you appreciate the effort and stuff but I'm still a newbie to this stuff. >>; I'm glad you liked Hunter though =P I think I'm going to continue it in Cry's 2nd 24-Hour installment.


Also, instead of setting new levers and whatnot, in the "CheckFunction", add this (all issues solved when you can't touch the levers after completion):

CheckFunction()
{
SetEntityInteractionDisabled("LEVER1", true);
SetEntityInteractionDisabled("LEVER2", true);
SetEntityInteractionDisabled("LEVER3", true);
SetEntityInteractionDisabled("LEVER4", true);
}


RE: Need help to make a lever puzzle - Inurias - 01-16-2012

(01-15-2012, 03:13 PM)Statyk Wrote:
(01-15-2012, 11:56 AM)Your Computer Wrote: 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);




Goodness gracious great balls of fire, this is ridiculous... XD I have a lot to learn! I might give this a whirl to try it out. Also need to find time to watch your scripting tutorial. And guys, I'm really NOT the best scripter. I'm glad you appreciate the effort and stuff but I'm still a newbie to this stuff. >>; I'm glad you liked Hunter though =P I think I'm going to continue it in Cry's 2nd 24-Hour installment.


Also, instead of setting new levers and whatnot, in the "CheckFunction", add this (all issues solved when you can't touch the levers after completion):

CheckFunction()
{
SetEntityInteractionDisabled("LEVER1", true);
SetEntityInteractionDisabled("LEVER2", true);
SetEntityInteractionDisabled("LEVER3", true);
SetEntityInteractionDisabled("LEVER4", true);
}
If you are really going for shortness, I just made up an even shorter version (which works):

Code:
string[] vars = {"", "", "", "", ""};

void OnStart()
{
    for (int i = 1; i <= 4; i++)
        SetEntityConnectionStateChangeCallback("LEVER" + i, "LeverCallback");
}

void LeverCallback(string &in asEntity, int alState)
{

    if (alState != 0)
    {
        for (int i = 1; i <= 4; i++)
        {
                if (StringContains(asEntity, "" + i))
                {
                    vars[i] = "b" + asEntity;
                    SetLocalVarInt(vars[i], alState);
                    SetLeverStuckState(asEntity, alState, true);
                    break;
                }
        }
    }

    if (GetLocalVarInt(vars[1]) == 1 && GetLocalVarInt(vars[2]) == 1 && GetLocalVarInt(vars[3]) == -1 && GetLocalVarInt(vars[4]) == 1)
        DoMyStuff();
}

void DoMyStuff()
{
     GiveSanityBoost();
                 SetSwingDoorLocked("LEVERDOOR", false, true);

     for (int l = 1; l <= 4; l++)
        SetEntityInteractionDisabled("LEVER" + l, true);
}

- Inurias



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

(01-16-2012, 09:11 PM)Inurias Wrote:
(01-15-2012, 03:13 PM)Statyk Wrote:
(01-15-2012, 11:56 AM)Your Computer Wrote: 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);




Goodness gracious great balls of fire, this is ridiculous... XD I have a lot to learn! I might give this a whirl to try it out. Also need to find time to watch your scripting tutorial. And guys, I'm really NOT the best scripter. I'm glad you appreciate the effort and stuff but I'm still a newbie to this stuff. >>; I'm glad you liked Hunter though =P I think I'm going to continue it in Cry's 2nd 24-Hour installment.


Also, instead of setting new levers and whatnot, in the "CheckFunction", add this (all issues solved when you can't touch the levers after completion):

CheckFunction()
{
SetEntityInteractionDisabled("LEVER1", true);
SetEntityInteractionDisabled("LEVER2", true);
SetEntityInteractionDisabled("LEVER3", true);
SetEntityInteractionDisabled("LEVER4", true);
}
If you are really going for shortness, I just made up an even shorter version (which works):

Code:
string[] vars = {"", "", "", "", ""};

void OnStart()
{
    for (int i = 1; i <= 4; i++)
        SetEntityConnectionStateChangeCallback("LEVER" + i, "LeverCallback");
}

void LeverCallback(string &in asEntity, int alState)
{

    if (alState != 0)
    {
        for (int i = 1; i <= 4; i++)
        {
                if (StringContains(asEntity, "" + i))
                {
                    vars[i] = "b" + asEntity;
                    SetLocalVarInt(vars[i], alState);
                    SetLeverStuckState(asEntity, alState, true);
                    break;
                }
        }
    }

    if (GetLocalVarInt(vars[1]) == 1 && GetLocalVarInt(vars[2]) == 1 && GetLocalVarInt(vars[3]) == -1 && GetLocalVarInt(vars[4]) == 1)
        DoMyStuff();
}

void DoMyStuff()
{
     GiveSanityBoost();
                 SetSwingDoorLocked("LEVERDOOR", false, true);

     for (int l = 1; l <= 4; l++)
        SetEntityInteractionDisabled("LEVER" + l, true);
}

- Inurias
I wish I understood that..