Facebook Twitter YouTube Frictional Games | Forum | Privacy Policy | Dev Blog | Dev Wiki | Support | Gametee


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Sequence of buttons
ElectricRed Offline
Member

Posts: 106
Threads: 13
Joined: Jun 2012
Reputation: 5
#1
Sequence of buttons

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

[Image: 9lkjf4.jpg]

12-09-2012, 10:19 PM
Find
xxxxxxxxxxxxxxxx Away
Posting Freak

Posts: 935
Threads: 0
Joined: Jun 2012
Reputation: 54
#2
RE: Sequence of buttons

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
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);
    }
}
12-10-2012, 12:53 AM
Find
Acies Offline
Posting Freak

Posts: 1,643
Threads: 60
Joined: Feb 2011
Reputation: 73
#3
RE: Sequence of buttons

(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 :]

[Image: mZiYnxe.png]


12-10-2012, 01:08 AM
Find
ElectricRed Offline
Member

Posts: 106
Threads: 13
Joined: Jun 2012
Reputation: 5
#4
RE: Sequence of buttons

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

[Image: 9lkjf4.jpg]

12-10-2012, 03:47 AM
Find
xxxxxxxxxxxxxxxx Away
Posting Freak

Posts: 935
Threads: 0
Joined: Jun 2012
Reputation: 54
#5
RE: Sequence of buttons

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
(This post was last modified: 12-10-2012, 11:32 AM by xxxxxxxxxxxxxxxx.)
12-10-2012, 11:32 AM
Find




Users browsing this thread: 1 Guest(s)