Frictional Games Forum (read-only)
Sequence of buttons - 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: Sequence of buttons (/thread-19501.html)



Sequence of buttons - ElectricRed - 12-09-2012

Hi, in my custom story I have a safe and in order to open it I wanted to have the player enter a combination of buttons. I have a panel with 6 buttons on it, and there are 4 digits in the combination. If the player enters the wrong combination, I want a message to display saying "Nothing happened..." and have it reset. (So the player can't continuously press buttons until it works.)

What would be the easiest way to do this? Would someone be able to help me with an outline of the script required? Thanks!

- ElectricRed


RE: Sequence of buttons - xxxxxxxxxxxxxxxx - 12-10-2012

Hm... I can't script at all, but I'd sure love to learn it, so please forgive me for staining this thread with my curious noobliness. (Also I never know when to shut up) Big Grin
So this would be my theory:

I'm assuming the correct sequence is simply 1234. Pressing button 1 will set the "sequence" variable to 1, pressing 2 will set it to 2 - but only if it was already "1" when you pressed 2 of course. Same principle applies to the buttons 3 and 4 respectively. Pressing 4 while "sequence" is 3 will also open the safe and deactivate the whole button business.

In any case, pressing a button will always increase "buttoncount" by 1. If it reaches 4, "sequence" and "buttoncount" will be set back to 0 and a "try again" message will appear. (This ensures that you have only four "tries" before sequence is resetted, so you have to enter the whole correct sequence in one go and can't just keep pressing buttons.)

I think I may have found the most complicated way to do it...but it might work.
Anyway, here's my sad and crippled attempt at a script that does this. For the love of everything holy, don't copy any of this, it will most likely do something horrible. Wink
Code:
void OnStart()
{
SetEntityPlayerInteractCallback("Button_1" , "Button_1_Call" , false);
SetEntityPlayerInteractCallback("Button_2" , "Button_2_Call" , false);
SetEntityPlayerInteractCallback("Button_3" , "Button_3_Call" , false);
SetEntityPlayerInteractCallback("Button_4" , "Button_4_Call" , false);
SetEntityPlayerInteractCallback("Button_5" , "Button_5_Call" , false);
SetEntityPlayerInteractCallback("Button_6" , "Button_6_Call" , false);

void SetLocalVarInt("buttoncount", 0);
void SetLocalVarInt("sequence", 0);
}


void Button_1_Call(string &in asParent, string &in asChild, int alState)
{
    if (GetLocalVarInt("sequence") == 0)
    {
    SetLocalVarInt("sequence", 1);
    }

    AddLocalVarInt("buttoncount", 1);

    if (GetLocalVarInt("buttoncount") == 4)
    {
    SetLocalVarInt("buttoncount", 0);
    SetLocalVarInt("sequence", 0);
    SetMessage("Messages", "tryagain", 0);
    }

}


void Button_2_Call(string &in asParent, string &in asChild, int alState)
{
    if (GetLocalVarInt("sequence") == 1)
    {
    SetLocalVarInt("sequence", 2);
    }

    AddLocalVarInt("buttoncount", 1);

    if (GetLocalVarInt("buttoncount") == 4)
    {
    SetLocalVarInt("buttoncount", 0);
    SetLocalVarInt("sequence", 0);
    SetMessage("Messages", "tryagain", 0);
    }
}


void Button_3_Call(string &in asParent, string &in asChild, int alState)
{
    if (GetLocalVarInt("sequence") == 2)
    {
    SetLocalVarInt("sequence", 3);
    }

    AddLocalVarInt("buttoncount", 1);
    
    if (GetLocalVarInt("buttoncount") == 4)
    {
    SetLocalVarInt("buttoncount", 0);
    SetLocalVarInt("sequence", 0);
    SetMessage("Messages", "tryagain", 0);
    }
}


void Button_4_Call(string &in asParent, string &in asChild, int alState)
{
    if (GetLocalVarInt("sequence") == 3)
    {
    OPEN SAFE;
    DEACTIVATE BUTTONS;
    }

    else
    {
    AddLocalVarInt("buttoncount", 1);
    }

    if (GetLocalVarInt("buttoncount") == 4)
    {
    SetLocalVarInt("buttoncount", 0);
    SetLocalVarInt("sequence", 0);
    SetMessage("Messages", "tryagain", 0);
    }
}


void Button_5_Call(string &in asParent, string &in asChild, int alState)
{
    AddLocalVarInt("buttoncount", 1);

    if (GetLocalVarInt("buttoncount") == 4)
    {
    SetLocalVarInt("buttoncount", 0);
    SetLocalVarInt("sequence", 0);
    SetMessage("Messages", "tryagain", 0);
    }
}


void Button_6_Call(string &in asParent, string &in asChild, int alState)
{
    AddLocalVarInt("buttoncount", 1);
    
    if (GetLocalVarInt("buttoncount") == 4)
    {
    SetLocalVarInt("buttoncount", 0);
    SetLocalVarInt("sequence", 0);
    SetMessage("Messages", "tryagain", 0);
    }
}



RE: Sequence of buttons - Acies - 12-10-2012

(12-10-2012, 12:53 AM)Hirnwirbel Wrote: I think I may have found the most complicated way to do it...but it might work.

Anyway, here's my sad and crippled attempt at a script that does this. For the love of everything holy, don't copy any of this, it will most likely do something horrible. Wink
Oh my god. This script whiped my harddrive clean and blew up my monitor. Use it with care.

In other words, something like what Hirnwibel wrote is the extent at which I might help you. For a more effective one someone script oriented must help you. Good luck :]


RE: Sequence of buttons - ElectricRed - 12-10-2012

(12-10-2012, 12:53 AM)Hirnwirbel Wrote: Hm... I can't script at all, but I'd sure love to learn it, so please forgive me for staining this thread with my curious noobliness. (Also I never know when to shut up) Big Grin
So this would be my theory:

I'm assuming the correct sequence is simply 1234. Pressing button 1 will set the "sequence" variable to 1, pressing 2 will set it to 2 - but only if it was already "1" when you pressed 2 of course. Same principle applies to the buttons 3 and 4 respectively. Pressing 4 while "sequence" is 3 will also open the safe and deactivate the whole button business.

In any case, pressing a button will always increase "buttoncount" by 1. If it reaches 4, "sequence" and "buttoncount" will be set back to 0 and a "try again" message will appear. (This ensures that you have only four "tries" before sequence is resetted, so you have to enter the whole correct sequence in one go and can't just keep pressing buttons.)

I think I may have found the most complicated way to do it...but it might work.
Anyway, here's my sad and crippled attempt at a script that does this. For the love of everything holy, don't copy any of this, it will most likely do something horrible. Wink
Code:
void OnStart()
{
SetEntityPlayerInteractCallback("Button_1" , "Button_1_Call" , false);
SetEntityPlayerInteractCallback("Button_2" , "Button_2_Call" , false);
SetEntityPlayerInteractCallback("Button_3" , "Button_3_Call" , false);
SetEntityPlayerInteractCallback("Button_4" , "Button_4_Call" , false);
SetEntityPlayerInteractCallback("Button_5" , "Button_5_Call" , false);
SetEntityPlayerInteractCallback("Button_6" , "Button_6_Call" , false);

void SetLocalVarInt("buttoncount", 0);
void SetLocalVarInt("sequence", 0);
}


void Button_1_Call(string &in asParent, string &in asChild, int alState)
{
    if (GetLocalVarInt("sequence") == 0)
    {
    SetLocalVarInt("sequence", 1);
    }

    AddLocalVarInt("buttoncount", 1);

    if (GetLocalVarInt("buttoncount") == 4)
    {
    SetLocalVarInt("buttoncount", 0);
    SetLocalVarInt("sequence", 0);
    SetMessage("Messages", "tryagain", 0);
    }

}


void Button_2_Call(string &in asParent, string &in asChild, int alState)
{
    if (GetLocalVarInt("sequence") == 1)
    {
    SetLocalVarInt("sequence", 2);
    }

    AddLocalVarInt("buttoncount", 1);

    if (GetLocalVarInt("buttoncount") == 4)
    {
    SetLocalVarInt("buttoncount", 0);
    SetLocalVarInt("sequence", 0);
    SetMessage("Messages", "tryagain", 0);
    }
}


void Button_3_Call(string &in asParent, string &in asChild, int alState)
{
    if (GetLocalVarInt("sequence") == 2)
    {
    SetLocalVarInt("sequence", 3);
    }

    AddLocalVarInt("buttoncount", 1);
    
    if (GetLocalVarInt("buttoncount") == 4)
    {
    SetLocalVarInt("buttoncount", 0);
    SetLocalVarInt("sequence", 0);
    SetMessage("Messages", "tryagain", 0);
    }
}


void Button_4_Call(string &in asParent, string &in asChild, int alState)
{
    if (GetLocalVarInt("sequence") == 3)
    {
    OPEN SAFE;
    DEACTIVATE BUTTONS;
    }

    else
    {
    AddLocalVarInt("buttoncount", 1);
    }

    if (GetLocalVarInt("buttoncount") == 4)
    {
    SetLocalVarInt("buttoncount", 0);
    SetLocalVarInt("sequence", 0);
    SetMessage("Messages", "tryagain", 0);
    }
}


void Button_5_Call(string &in asParent, string &in asChild, int alState)
{
    AddLocalVarInt("buttoncount", 1);

    if (GetLocalVarInt("buttoncount") == 4)
    {
    SetLocalVarInt("buttoncount", 0);
    SetLocalVarInt("sequence", 0);
    SetMessage("Messages", "tryagain", 0);
    }
}


void Button_6_Call(string &in asParent, string &in asChild, int alState)
{
    AddLocalVarInt("buttoncount", 1);
    
    if (GetLocalVarInt("buttoncount") == 4)
    {
    SetLocalVarInt("buttoncount", 0);
    SetLocalVarInt("sequence", 0);
    SetMessage("Messages", "tryagain", 0);
    }
}
With a little bit of tweaking, I was able to get it to work! Thanks! Smile


RE: Sequence of buttons - xxxxxxxxxxxxxxxx - 12-10-2012

Quote: With a little bit of tweaking, I was able to get it to work! Thanks! [Image: smile.gif]
Yaaaaay, I could help! *dance* Big Grin