Frictional Games Forum (read-only)
Door Open/Close Depending on Situation - 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: Door Open/Close Depending on Situation (/thread-4509.html)

Pages: 1 2


Door Open/Close Depending on Situation - Armored Cow - 09-18-2010

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.


RE: Door Open/Close Depending on Situation - Liag - 09-18-2010

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


RE: Door Open/Close Depending on Situation - Armored Cow - 09-18-2010

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.


RE: Door Open/Close Depending on Situation - jens - 09-18-2010

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



RE: Door Open/Close Depending on Situation - Armored Cow - 09-18-2010

Thank you so much Jens!


RE: Door Open/Close Depending on Situation - theDARKW0LF - 09-18-2010

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


RE: Door Open/Close Depending on Situation - Armored Cow - 09-18-2010

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



RE: Door Open/Close Depending on Situation - theDARKW0LF - 09-18-2010

Yeah the creaking open of the door doesn't work for me either, only it slamming does.


RE: Door Open/Close Depending on Situation - Pandemoneus - 09-18-2010

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.


RE: Door Open/Close Depending on Situation - Armored Cow - 09-18-2010

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.