Frictional Games Forum (read-only)
3buttons then a bookshelf opens - 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: 3buttons then a bookshelf opens (/thread-8578.html)

Pages: 1 2


3buttons then a bookshelf opens - xtron - 06-13-2011

I already know how to make so when you pull 1lever a bookshelf opens but I don't have any ideas on how to do so when you push 3 buttons a secret bookshelf opens :O

I appreciate if you guys could help me fix this :/


RE: 3buttons then a bookshelf opens - Kyle - 06-13-2011

Code:
void OnStart()
{
     SetLocalVarInt("Var01", 0);
     for (int x = 1; x < 4 && x > 0; x++)
     {
          SetEntityPlayerInteractCallback("Button_"+x, "Func_"+x, true);
     }
     FuncOpen();
}
void Func_1(string &in asEntity) { AddLocalVarInt("Var01", 1); }
void Func_2(string &in asEntity) { AddLocalVarInt("Var01", 1); }
void Func_3(string &in asEntity) { AddLocalVarInt("Var01", 1); }
void FuncOpen()
{
     if (GetLocalVarInt("Var01") == 3)
     {
          // However the bookshelf opens...
          return;
     }
}

Edit: Oops, here you go, this one is right now.


RE: 3buttons then a bookshelf opens - Nye - 06-13-2011

(06-13-2011, 07:50 PM)xtron Wrote: bump...

"the message is too short"...nope.

Set the interact callbacks for each of the levers. Set the 'DestroyOnInteraction' to true for each; and link them all to the same procedure.

Here, you will need to either use a case-switch structure or just a bunch of if statements, and local variables. For example:

Code:
if (getlocalvarint("BookShelf") == 1)
{
   setlocalvarint("BookShelf, 2);
  break;
}

if (getlocalvarint("BookShelf") == 2)
{
    setlocalvarint("BookShelf, 2);
    break;
}

if (getlocalvarint("BookShelf") == 3)
{
    // INSERT STUFF FOR OPENING BOOKSHELF
   break;
}

Note, for the above to work, the local variable, "BookShelf", will previously need setting to 1, so in your void onStart() { // you need to include the line, "setlocalvarint("BookShelf", 1);".

Hope this helps somewhat.



RE: 3buttons then a bookshelf opens - xtron - 06-13-2011

@Nye

Could you please explain your code a little more?. Where should I add the 3 buttons and the code which dose so the bookshelf opens?

Here's my code for opening a bookshelf if you drag 1lever.

Code:
    ConnectEntities("door_connection",        //Name of connection
            "Button1",     //Parent entity (Affects)
            "shelf_move1",    //Child entity     (Affected)
            false,        //Invert the state sent
            1,         //States used (0=both), checked before invertion.
            "CreateDust");    //callback



RE: 3buttons then a bookshelf opens - Kyle - 06-13-2011

@Xtron;

Thanks for ignoring my reply... :/

It should work like this:

1. Player pushes a button and a local variable is incremented by 1.

2. Same thing happens for the other 2 buttons.

3. Since they were all pushed, the bookshelf slides over to reveal a secret door.


RE: 3buttons then a bookshelf opens - xtron - 06-13-2011

Oh sorry Kyle :S. Forgot about yours. Sad.

But Kyle...since your so kind you can maybe give me a start on how to set the script up?.

I tried to understand both your and Nye's script but didn't made it :/.


RE: 3buttons then a bookshelf opens - Kyle - 06-13-2011

(06-13-2011, 08:38 PM)xtron Wrote: Oh sorry Kyle :S. Forgot about yours. Sad.

But Kyle...since your so kind you can maybe give me a start on how to set the script up?.

I tried to understand both your and Nye's script but didn't made it :/.

To set it up, first you need to keep track of whether the player pushes the buttons. So you need a local variable which can be used within the whole script.

SetLocalVarInt("Var01", 0);

The name of it is "Var01" and it's value is 0.

Now we need to change it's value when the player interacts with each button.

So we add interactions for each button.

For button 1 which will be called "Button_1":

SetEntityPlayerInteractCallback("Button_1", "Func_1", true);

For button 2 which will be called "Button_2":

SetEntityPlayerInteractCallback("Button_2", "Func_2", true);

For button 3 which will be called "Button_3":

SetEntityPlayerInteractCallback("Button_3", "Func_3", true);


So now we have a function for each individual button.
Functions: "Func_1", "Func_2", and "Func_3". Buttons: "Button_1", "Button_2", and "Button_3".

We can simplify it to where you only need 1 function. Lets just call it "Func_1". This is what it'll look like:

void Func_1(string &in asEntity)
{
AddLocalVarInt("Var01", 1);
}

Now in the void OnStart() function, we need to call another function. Lets call it "FuncOpen".

Now inside of that function, we need to check and see if the variable is equal to 3. Let me represent it by this:

Buttons Pressed By Player = Var01 = 3 ---> 3 = BookShelf Slides Open

So most of the script should look like this:

Code:
void OnStart()
{
     SetLocalVarInt("Var01", 0);
     SetEntityPlayerInteractCallback("Button_1", "Func_1", true);
     SetEntityPlayerInteractCallback("Button_2", "Func_1", true);
     SetEntityPlayerInteractCallback("Button_3", "Func_1", true);
     FuncOpen();
}
void Func_1(string &in asEntity)
{
     AddLocalVarInt("Var01", 1);
     SetEntityInteractionDisabled(asEntity, true);
}
void FuncOpen()
{
     if (GetLocalVarInt("Var01") == 3)
     {
          // However the bookshelf opens...
          return;
     }
}



RE: 3buttons then a bookshelf opens - xtron - 06-14-2011

Thanks kyle! Tongue.
But it doesn't work for me :S

Code:
void OnStart()
{
     SetLocalVarInt("Var01", 0);
     SetEntityPlayerInteractCallback("button1", "Func_1", true);
     SetEntityPlayerInteractCallback("button2", "Func_1", true);
     SetEntityPlayerInteractCallback("button3", "Func_1", true);
     FuncOpen();
}

void Func_1(string &in asEntity)
{
     AddLocalVarInt("Var01", 1);
     SetEntityInteractionDisabled(asEntity, true);
}
void FuncOpen()
{
     if (GetLocalVarInt("Var01") == 3)
     {
          RotatePropToSpeed("shelf_move1", 1.0f, 0.6f, 0, 0, 65, false, "shelf_moveto_thisplace");
          return;
     }
}



RE: 3buttons then a bookshelf opens - Apjjm - 06-15-2011

Tweaked and re-arranged the code a little, by moving the buttons into an array so you can add/remove/change the buttons easily (you can just add any extra buttons to the array and without needing to alter the code at all). The code wasn't working because FuncOpen() was only being called from the start routine, and not the callback.
Code:
//List of all our buttons. You can add or remove buttons really easily from this
//Add: Just add another comma, and another item!
//You can also break the array over lines, so it looks nicer
string[] buttonsToCount =
         {"button_simple_2","button_simple_3","button_simple_4"};

/////////////////////////////////////////////////////////////
//Onstart Event Routine                                    //
/////////////////////////////////////////////////////////////
void OnStart()
{
  
   SetLocalVarInt("buttonCount", 0); //Set how many buttons are intially pressed here.
  
   //Loop through all the buttons we wish to count, adding a callback for them.
   for(int i=0; i<buttonsToCount.length(); i++)
     SetEntityPlayerInteractCallback(buttonsToCount[i], "cbButtonCounter", true);
}



/////////////////////////////////////////////////////////////
//Callback (button interaction) Event Routine              //
/////////////////////////////////////////////////////////////
void cbButtonCounter(string &in asEntity)
{
     //Do stuff for this button
     AddLocalVarInt("buttonCount",1);         //Increment the button counter
         
     //Check the state of all the buttons. If they are pressed, call event.
     if(GetLocalVarInt("buttonCount") == buttonsToCount.length())
       evButtonsDepressed();
}

/////////////////////////////////////////////////////////////
//Event: all buttons pressed                               //
/////////////////////////////////////////////////////////////
void evButtonsDepressed()
{
   //Put your code when all buttons are pressed here.
   AddDebugMessage("All Buttons Pressed!",false);
}


This may also interest you:
http://www.frictionalgames.com/forum/thread-8484-post-74705.html#pid74705




RE: 3buttons then a bookshelf opens - xtron - 06-15-2011

Thanks Apjjm! your the best! Big Grin <3.


Great love to you Kyle aswell for trying to help me Smile <3.