Frictional Games Forum (read-only)

Full Version: Creating A Lever Puzzle
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3
I'm trying to create a lever puzzle, using either the guiding rod machine or the lever one, it doesn't matter to me. Whichever is easier, I guess.
I want to either put levers in a certain up/down state or put the three guiding rods into the machine to cause a screen shake, which in turn causes the huge castle gate to open. I can handle the last part, I'm just clueless on levers. I can do one, but I can't do multiple to save my life. A script or tutorial/thread link would be helpful. Thankyou :]

  1. Set connection state callbacks to all levers.
  2. Create a function that checks the state of all levers.
  3. Create a function to call when all levers have been set by the player.
  4. Save the state of each lever when the callback is called.
    1. Call the function from #2 after storing the state of the lever, within the connection state callback.
  5. If all levers are in the state you want them to be, call the function from #3.
(11-22-2011, 12:02 AM)Your Computer Wrote: [ -> ]
  1. Set connection state callbacks to all levers.
  2. Create a function that checks the state of all levers.
  3. Create a function to call when all levers have been set by the player.
  4. Save the state of each lever when the callback is called.
    1. Call the function from #2 after storing the state of the lever, within the connection state callback.
  5. If all levers are in the state you want them to be, call the function from #3.

thanks bro

(11-22-2011, 12:02 AM)Your Computer Wrote: [ -> ]
  1. Set connection state callbacks to all levers.
  2. Create a function that checks the state of all levers.
  3. Create a function to call when all levers have been set by the player.
  4. Save the state of each lever when the callback is called.
  5. Call the function from #2 after storing the state of the lever, within the connection state callback.
[*]If all levers are in the state you want them to be, call the function from #3.
I'm sorry is it just me that finds that confusing? Sad maybe a script example?

(11-22-2011, 01:12 AM)JenniferOrange Wrote: [ -> ]maybe a script example?

PHP Code:
/*

   ***** Warning: untested code *****

   Assuming only two levers are present in map.
   First lever name: "lever_1"
   Second lever name: "lever_2"
   Assuming global script variables "lever_1_state" and "lever_2_state" have been defined.

*/

void OnStart()
{
    
SetEntityConnectionStateChangeCallback("lever_1""StoreCheckLeverState");
    
SetEntityConnectionStateChangeCallback("lever_2""StoreCheckLeverState");
}

void CheckLeverStates()
{
    if (
GetLocalVarInt("lever_1") == lever_1_state
     
&& GetLocalVarInt("lever_2") == lever_2_state)
    {
        
PerformLeverTaskCompleted();
    }
}

void PerformLeverTaskCompleted()
{
    
// Do something...
}

void StoreCheckLeverState(string &in entityint state)
{
    
SetLocalVarInt(entitystate);
    
CheckLeverStates();

(11-22-2011, 01:49 AM)Your Computer Wrote: [ -> ]
(11-22-2011, 01:12 AM)JenniferOrange Wrote: [ -> ]maybe a script example?

PHP Code:
/*

   ***** Warning: untested code *****

   Assuming only two levers are present in map.
   First lever name: "lever_1"
   Second lever name: "lever_2"
   Assuming global script variables "lever_1_state" and "lever_2_state" have been defined.

*/

void OnStart()
{
    
SetEntityConnectionStateChangeCallback("lever_1""StoreCheckLeverState");
    
SetEntityConnectionStateChangeCallback("lever_2""StoreCheckLeverState");
}

void CheckLeverStates()
{
    if (
GetLocalVarInt("lever_1") == lever_1_state
     
&& GetLocalVarInt("lever_2") == lever_2_state)
    {
        
PerformLeverTaskCompleted();
    }
}

void PerformLeverTaskCompleted()
{
    
// Do something...
}

void StoreCheckLeverState(string &in entityint state)
{
    
SetLocalVarInt(entitystate);
    
CheckLeverStates();


Thank you, I'll try this! Which function do I use to define the global variables and where should I put them/it?
(11-22-2011, 02:04 AM)JenniferOrange Wrote: [ -> ]Thank you, I'll try this! Which function do I use to define the global variables and where should I put them/it?

Technically, you don't need to; though, it's just an example, the variable names being placeholders. Replace whatever to suit your needs.
My script does for some reason don't work. I have setted all of the levers on stuck in max and InteractionDisablesStuck, so when I have pulled the right levers they are in the wanted positions, but still the "PerformLeverTaskCompleted" doesn't start...

void OnStart()
{
SetEntityConnectionStateChangeCallback("lever_1", "StoreCheckLeverState");
SetEntityConnectionStateChangeCallback("lever_2", "StoreCheckLeverState");
SetEntityConnectionStateChangeCallback("lever_3", "StoreCheckLeverState");
SetEntityConnectionStateChangeCallback("lever_4", "StoreCheckLeverState");
SetEntityConnectionStateChangeCallback("lever_5", "StoreCheckLeverState");
SetEntityConnectionStateChangeCallback("lever_6", "StoreCheckLeverState");
SetEntityConnectionStateChangeCallback("lever_7", "StoreCheckLeverState");
SetEntityConnectionStateChangeCallback("lever_8", "StoreCheckLeverState");
}

void CheckLeverStates()
{
if (GetLocalVarInt("lever_1") == 0
&& GetLocalVarInt("lever_2") == 1
&& GetLocalVarInt("lever_3") == 0
&& GetLocalVarInt("lever_4") == 1
&& GetLocalVarInt("lever_5") == 0
&& GetLocalVarInt("lever_6") == 1
&& GetLocalVarInt("lever_7") == 1
&& GetLocalVarInt("lever_8") == 0)
{
PerformLeverTaskCompleted();
}
}
void PerformLeverTaskCompleted()
{
SetSwingDoorLocked("door1", false, false);
SetSwingDoorClosed("door1", false, false);
PlaySoundAtEntity("", "unlock_door", "door1", 0, false);
PlaySoundAtEntity("", "quest_completed.snt", "Player", 0.5f, false);
StartEffectFlash(1, 0.4, 1);
}

void StoreCheckLeverState(string &in entity, int state)
{
SetLocalVarInt("lever_1", 0);
SetLocalVarInt("lever_2", 1);
SetLocalVarInt("lever_3", 0);
SetLocalVarInt("lever_4", 1);
SetLocalVarInt("lever_5", 0);
SetLocalVarInt("lever_6", 1);
SetLocalVarInt("lever_7", 1);
SetLocalVarInt("lever_8", 0);
CheckLeverStates();
}
You're not supposed to do this:
PHP Code:
void StoreCheckLeverState(string &in entityint state)
 {
     
SetLocalVarInt("lever_1"0);
     
SetLocalVarInt("lever_2"1);
     
SetLocalVarInt("lever_3"0);
     
SetLocalVarInt("lever_4"1);
     
SetLocalVarInt("lever_5"0);
     
SetLocalVarInt("lever_6"1);
     
SetLocalVarInt("lever_7"1);
     
SetLocalVarInt("lever_8"0);
     
CheckLeverStates();
 } 

You should replace that with this:

PHP Code:
void StoreCheckLeverState(string &in entityint state)
 {
     
SetLocalVarInt(entitystate);
     
CheckLeverStates();
 } 

What you are doing by changing that is creating a random variable with the entities name(lever_1, lever_2 etc.), and saving that levers state. In the function CheckLeverStates() you will check the state of each and if the state of each one corresponds to the expected it will trigger the final function.

(12-12-2011, 09:12 PM)nemesis567 Wrote: [ -> ]You're not supposed to do this:
PHP Code:
void StoreCheckLeverState(string &in entityint state

SetLocalVarInt("lever_1"0); 
SetLocalVarInt("lever_2"1); 
SetLocalVarInt("lever_3"0); 
SetLocalVarInt("lever_4"1); 
SetLocalVarInt("lever_5"0); 
SetLocalVarInt("lever_6"1); 
SetLocalVarInt("lever_7"1); 
SetLocalVarInt("lever_8"0); 
CheckLeverStates(); 



You should replace that with this:

PHP Code:
void StoreCheckLeverState(string &in entityint state

SetLocalVarInt(entitystate); 
CheckLeverStates(); 



What you are doing by changing that is creating a random variable with the entities name(lever_1, lever_2 etc.), and saving that levers state. In the function CheckLeverStates() you will check the state of each and if the state of each one corresponds to the expected it will trigger the final function.


Ok, I understand...

But I still have a problem with the "complete" part. I can't seem to get the door to lock itself (yes I have checked the locked box). And the sound and light effects doesn't start either...

Pages: 1 2 3