Frictional Games Forum (read-only)

Full Version: Using a Timer to Unlock a Door
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
All right, I've been searching around for a code to unlock a door after a certain amount of time, but not really found what I was looking for.

Any ideas?
First, you would need something to trigger the timer. Collide, useitem, etc etc. When the timer expires, its callback would call the SetSwingDoorLocked function.

Also, I would visit the wiki. It has documentation for each function.
Sounds good, but still very confused with the script for the timer.

This is what the wiki says, but no idea what it means. Still pretty new to scripting.

Code:
void AddTimer(string& asName, float afTime, string& asFunction);


Creates a timer which calls a function when it expires.


Callback syntax: void MyFunc(string &in asTimer)



asName - the name of the timer


afTime - time in seconds


asFunction - the function to call
asName, afTime, and asFunction are known as arguments.

asName is the name of your timer. Basically a string. It isn't required (unless you wish to use stop timer), but I recommend it as it can help you keep track of multiple timers.

afTime is, well, the time. "Float" is basically a decimal number. As an example, 1.5f will create a timer that runs for 1.5 seconds.

asFunction is the callback. This is the function that will be called when your timer expires.

asTimer is the parameter for the callback function.

Here's an example.

PHP Code:
void Function()//Parameters would go here, depending on what called this function
{
    
//This function starts the timer
    
AddTimer("ExampleTimer",1.5f,"TimerCall");
    
//Name of timer, the time, and the callback
}

void TimerCall(string &in asTimer//This function is called when the timer expires
{
   
//Do things here

Okay, so the player hits a script area named "timer_area" and then after 42 seconds, the door named "hall_door" would unlock. The door is already set to locked in the editor.

This script probably looks like the world's biggest mess....
Code:
In OnStart()
    {
    AddEntityCollideCallback("Player", "timer_area", "OpenDoor", true, -1);
    }

void OpenDoor()
{
    AddTimer("ExampleTimer",42f,"TimerCall");
}

void TimerCall(string &in asTimer)
{
   SetSwingDoorClosed("hall_door", false, true);
}
Looks good, but you're missing the parameters for OpenDoor.

Same kind of deal with the timer. Except the entitycollide has a different callback syntax:

PHP Code:
void Function(string &in asParentstring &in asChildint alState
Now getting a error saying " f is not declared".
Try changing it to 42.0f?

Oh, and is "In" in your .hps file?

PHP Code:
In OnStart()
    {
    
AddEntityCollideCallback("Player""timer_area""OpenDoor"true, -1);
    } 
Error is gone. Yippee, but the door is not opening. =/

Code:
void OpenDoor(string &in asParent, string &in asChild, int alState)
{
    AddTimer("ExampleTimer", 42.0f, "TimerCall");
}

void TimerCall(string &in asTimer)
{
   SetSwingDoorClosed("hall_door", false, true);
}
Try SetSwingDoorLocked.
Pages: 1 2