Frictional Games Forum (read-only)

Full Version: Door Open/Close Depending on Situation
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
When the player steps into a trigger area, I want the door that they just walked through to slam shut (if they left it open) or creak open slowly (if they closed it). I can get the door to slam shut if it's open but am not really sure how to do it this way instead.

Any help would be appreciated.
You just need to use GetSwingDoorClosed() to check if the door is open or closed, and as for creaking it open slowly, check 00_rainy_hall.hps (beginning at line 817).
I looked at it but am still confused. For that section, the door was always closed so there was no need to check if it was closed or not.

If I tell it to check for if it is closed or not, how do I distinguish which action to take?

I know I need an "if" somewhere but am unsure what to do exactly.
Assuming you have created the area and the callback for entering into the area.

GetSwingDoorClosed() will return a true or false when you use it, so if you do:

Code:
//Player enters the area, we check if door is closed or open
void ColliderPlayerInArea(CAN'T RECALL ALL THE STUFF THAT GOES HERE)
{
    //Door is closed so we will creak it open
    if(GetSwingDoorClosed("NameOfDoor") == true)
        CreakOpen();

    //Door is open so we will slam it shut, this is easy.
    else
        SetSwindDoorClosed("NameOfDoor", true, true);
}

//Door was closed, so we add a bunch of timers to give a small amount of force,
//creaking the door open after we disabled some stuff that would interfer
void CreakOpen()
{
    SetSwingDoorDisableAutoClose("NameOfDoor", true);
    SetSwingDoorClosed("NameOfDoor", false, false);

    AddTimer("NameOfDoor", 0.05f, "TimerCreakDoor");
    AddTimer("NameOfDoor", 0.1f, "TimerCreakDoor");
    AddTimer("NameOfDoor", 0.2f, "TimerCreakDoor");
    AddTimer("NameOfDoor", 0.3f, "TimerCreakDoor");
}

//The timer that gives the door a little push, notice that I do not know what a good
//force value is 1 might be too much or too little, and I am not sure of the direction
//so could be -1 or on the Z axis and not on the X axis as in this script.
void TimerCreakDoor(string &in asTimer)
{
    AddPropForce(asTimer, 1, 0, 0, "World");
}
Thank you so much Jens!
I followed what Jens posted, but I get an error which states, "main (81, 9): ERR : No matching signatures to 'CreakOpen()'

What gives?

EDIT: Lol, it seems I didn't notice that there was more down the code box so I had only copied the top...
Actually I'm having troubles too. It's only slamming the door, whether it's already closed or open.

Firstly, I have this in my void OnStart section:
Code:
//Callback to slam door
    AddEntityCollideCallback("Player", "area_lock_door", "CollideLock", true, 1);


Code:
//Function called when player steps into area_lock_door
void CollideLock(string &in asParent, string &in asChild, int alState)
{
    //Door is closed so activate CreakOpen function
    if(GetSwingDoorClosed("castle_1") == true)
        CreakOpen();
    
    //Door is open so slam it shut
    else
        StartPlayerLookAt("castle_1", 3, 4, "");
        AddTimer("", 0.5f, "TimerSlamDoor");
}

void TimerSlamDoor(string &in asTimer)
{
    SetSwingDoorClosed("castle_1", true, true);
    SetSwingDoorLocked("castle_1", true, true);    
    PlaySoundAtEntity("", "react_scare.snt", "Player", 0, false);        
    GiveSanityDamage(5.0f, true);
    AddTimer("", 3.0f, "TimerStopLook");
}

void CreakOpen()
{
    SetSwingDoorDisableAutoClose("castle_1", true);
    SetSwingDoorClosed("castle_1", false, false);    
    StartPlayerLookAt("castle_1", 2, 2, "");
    GiveSanityDamage(5.0f, true);
    PlaySoundAtEntity("", "react_breath_slow.snt", "Player", 0, false);    
    AddTimer("castle_1", 0.05f, "TimerCreakDoor");
    AddTimer("castle_1", 0.1f, "TimerCreakDoor");
    AddTimer("castle_1", 0.2f, "TimerCreakDoor");
    AddTimer("castle_1", 0.3f, "TimerCreakDoor");
    AddTimer("", 3.0f, "TimerStopLook");
}

void TimerCreakDoor(string &in asTimer)
{
    AddPropForce("castle_1", 1, 0, 0, "World");
}

void TimerStopLook(string &in asTimer)
{
    StopPlayerLookAt();
}
Yeah the creaking open of the door doesn't work for me either, only it slamming does.
You have to experiment a bit with the values here.

void TimerCreakDoor(string &in asTimer)
{
AddPropForce("castle_1", 1, 0, 0, "World");
}

You might have to use -1, -2 or 2, just try it out.

[edit]
You also got a mistake in the code.

Code:
else
        StartPlayerLookAt("castle_1", 3, 4, "");
        AddTimer("", 0.5f, "TimerSlamDoor");

Use:

Code:
else {
        StartPlayerLookAt("castle_1", 3, 4, "");
        AddTimer("", 0.5f, "TimerSlamDoor");
}

You have to use { } when you use more than 1 line in if-, else-, for-clauses and so on.
No, Pandemoneus, the problem isn't that. It's still slamming the door. It's not just that the opening won't work, but that it doesn't even attempt to open it.
Pages: 1 2