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


Post Reply 
 
Thread Rating:
  • 2 Vote(s) - 2.5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
3buttons then a bookshelf opens
Author Message
xtron Offline
Senior Member

Posts: 402
Joined: May 2011
Reputation: 2
Post: #1
3buttons then a bookshelf opens

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 :/

[Image: 44917299.jpg]Dubstep <3
06-13-2011 03:28 PM
Find all posts by this user Quote this message in a reply
Kyle Offline
Posting Freak

Posts: 911
Joined: Sep 2010
Reputation: 7
Post: #2
RE: 3buttons then a bookshelf opens

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.

(This post was last modified: 06-13-2011 08:04 PM by Kyle.)
06-13-2011 08:03 PM
Find all posts by this user Quote this message in a reply
Nye Offline
Senior Member

Posts: 250
Joined: Jan 2011
Reputation: 2
Post: #3
RE: 3buttons then a bookshelf opens

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

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.

(This post was last modified: 06-13-2011 08:06 PM by Nye.)
06-13-2011 08:05 PM
Find all posts by this user Quote this message in a reply
xtron Offline
Senior Member

Posts: 402
Joined: May 2011
Reputation: 2
Post: #4
RE: 3buttons then a bookshelf opens

@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.

    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

[Image: 44917299.jpg]Dubstep <3
06-13-2011 08:13 PM
Find all posts by this user Quote this message in a reply
Kyle Offline
Posting Freak

Posts: 911
Joined: Sep 2010
Reputation: 7
Post: #5
RE: 3buttons then a bookshelf opens

@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.

06-13-2011 08:28 PM
Find all posts by this user Quote this message in a reply
xtron Offline
Senior Member

Posts: 402
Joined: May 2011
Reputation: 2
Post: #6
RE: 3buttons then a bookshelf opens

Oh sorry Kyle Confused. 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 :/.

[Image: 44917299.jpg]Dubstep <3
06-13-2011 08:38 PM
Find all posts by this user Quote this message in a reply
Kyle Offline
Posting Freak

Posts: 911
Joined: Sep 2010
Reputation: 7
Post: #7
RE: 3buttons then a bookshelf opens

(06-13-2011 08:38 PM)xtron Wrote:  Oh sorry Kyle Confused. 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:

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;
     }
}

06-13-2011 08:58 PM
Find all posts by this user Quote this message in a reply
xtron Offline
Senior Member

Posts: 402
Joined: May 2011
Reputation: 2
Post: #8
RE: 3buttons then a bookshelf opens

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

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;
     }
}

[Image: 44917299.jpg]Dubstep <3
06-14-2011 02:58 PM
Find all posts by this user Quote this message in a reply
Apjjm Offline
Is easy to say

Posts: 494
Joined: Apr 2011
Reputation: 51
Post: #9
RE: 3buttons then a bookshelf opens

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.
//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/thr...l#pid74705

(This post was last modified: 06-15-2011 03:36 PM by Apjjm.)
06-15-2011 03:31 PM
Find all posts by this user Quote this message in a reply
xtron Offline
Senior Member

Posts: 402
Joined: May 2011
Reputation: 2
Post: #10
RE: 3buttons then a bookshelf opens

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


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

[Image: 44917299.jpg]Dubstep <3
06-15-2011 06:39 PM
Find all posts by this user Quote this message in a reply
Post Reply 




User(s) browsing this thread: 1 Guest(s)