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


Thread Rating:
  • 2 Vote(s) - 3 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to remove a Timer Loop which opens a door using AddPropForce?
Frontcannon Offline
Senior Member

Posts: 538
Threads: 10
Joined: Jul 2010
Reputation: 2
#1
How to remove a Timer Loop which opens a door using AddPropForce?

I wanted to make a door open by itself slowly behind the player and used Frictional's code in their .hps of the first level (Rainy Hall) as reference.
The door opens nicely and behaves as expected, but I can't figure out how to remove the loop so the player can close the door without it wanting to open again Sad

Here's the code:

void OpenDoor(string &in asParent, string &in asChild, int alState)
{
    SetSwingDoorClosed("prison_section_2", false, false);
    SetSwingDoorDisableAutoClose("prison_section_2", true);
    AddTimer("swing_door", 0.01f, "TimerDoor");
    AddTimer("stop_creak", 1.5f, "TimerCreak");
}

void TimerDoor(string &in asTimer)
{
    if(asTimer == "swing_door")
    {
        AddPropForce("prison_section_2", 0.0f, 0.0f, 25.0f, "");
    }
    else
    {
        AddPropForce("prison_section_2", 0.0f, 0.0f, -95.0f, "");
    }
    AddTimer(asTimer, 0.03, "TimerDoor");
}

void TimerCreak(string &in asTimer)
{
    RemoveTimer("swing_door");
    PlaySoundAtEntity("pant", "react_scare.snt", "Player", 0.0f, false);
}

I think it has something to do with the devs using the same string for the timer and door name, but I can't really figure out how.


DEV VERSION
Spoiler below!
/*When in hall4 gallery door swings open slowly
*/
void CollideAreaGalleryDoor(string &in asParent, string &in asChild, int alState)
{
    SetSwingDoorClosed("door_gallery", false, false);
    SetSwingDoorDisableAutoClose("door_gallery", true);
    
    PlaySoundAtEntity("creaking_door", "joint_door_move_special.snt", "door_gallery", 1.0 / 0.7f, false);
    
    AddTimer("door_gallery", 0.01f, "TimerSwingDoor");
    
    AddDebugMessage("Boho, the gallery door creaks open.", false);    
    
    AddTimer("stopcreak", 2.0f, "TimerStopCreak");
}
void TimerSwingDoor(string &in asTimer)
{
    if(GetLocalVarInt("SwingDoor") == 10){
        SetLocalVarInt("SwingDoor", 0);
        return;
    }
    
    if(asTimer == "door_gallery") AddPropForce(asTimer, 70.0f, 0, 0, "World");
    else AddPropForce(asTimer, -95.0f, 0, 0, "World");
    
    AddLocalVarInt("SwingDoor", 1);
    
    AddTimer(asTimer, 0.03f, "TimerSwingDoor");
    
    AddDebugMessage("Swing: "+GetLocalVarInt("SwingDoor"), false);
}
void TimerStopCreak(string &in asTimer)
{
    if(asTimer == "scare2"){
        PlaySoundAtEntity("scare", "react_scare.snt", "Player", 1.0 / 1, false);
        return;
    }
    if(asTimer == "scare"){
        PlaySoundAtEntity("scare", "react_scare.snt", "Player", 0, false);
        //PlaySoundAtEntity("laugh", "00_laugh.snt", "door_gallery", 1.0 / 1, false);
        PlaySoundAtEntity("loop", "00_loop.snt", "Player", 1.0 / 0.1f, false);
        return;
    }
    if(asTimer == "breath1"){
        PlaySoundAtEntity("breath", "react_breath.snt", "Player", 1.0 / 1, false);
        return;
    }
    if(asTimer == "breath2"){
        PlaySoundAtEntity("breath", "react_breath.snt", "Player", 1.0 / 0.9f, false);
        return;
    }
    if(asTimer == "breath3"){
        //SetSwingDoorLocked("door_gallery", false, true);
        PlaySoundAtEntity("breath", "react_breath.snt", "Player", 1.0 / 0.8f, false);
        AddTimer("lookloop", RandFloat(2.0f,3.0f), "TimerRandomLook");    //Re-activate the spinning head
        FadePlayerFOVMulTo(1.0f, 0.1f);
        StopSound("loop", 1);
        StartScreenShake(0.01f,0.25f, 0.01f,0.5f);
        return;
    }
    if(asTimer == "lightsout"){
        SetLampLit("chandelier_nice_1", false, true);
        SetLampLit("candlestick_floor_2", false, true);
        FadeLightTo("PointLight_25", 0, 0, 0, 0, 0, 1);
        FadePlayerFOVMulTo(1.5f, 0.25f);
        return;
    }
    
    if(asTimer == "sanity"){
        //SetSwingDoorLocked("door_gallery", true, false);
        GiveSanityDamage(10, true);
        return;
    }
    
    StopSound("creaking_door", 0.4f);
}



╔═════════════════╗
☺ Smoke weed everyday ☺
╚═════════════════╝
12-11-2010, 05:29 PM
Find
Akumasama Offline
Member

Posts: 122
Threads: 2
Joined: Nov 2010
Reputation: 0
#2
RE: How to remove a Timer Loop which opens a door using AddPropForce?

Do you mean it keeps getting pushed open?
12-11-2010, 06:03 PM
Find
Frontcannon Offline
Senior Member

Posts: 538
Threads: 10
Joined: Jul 2010
Reputation: 2
#3
RE: How to remove a Timer Loop which opens a door using AddPropForce?

Yes. The player can close the door, but when you let go the door creaks open again. My RemoveTimer showns no effect.


╔═════════════════╗
☺ Smoke weed everyday ☺
╚═════════════════╝
12-11-2010, 06:16 PM
Find
Akumasama Offline
Member

Posts: 122
Threads: 2
Joined: Nov 2010
Reputation: 0
#4
RE: How to remove a Timer Loop which opens a door using AddPropForce?

void lanterndoorclose(string &in asParent, string &in asChild, int alState)
{
     AddPropImpulse("lanterndoortrapdoor", 0, 150, 0, "world");
     AddTimer("lanterndoortrapdoortimer", 0.3f, "lanterndoortrapdoorlock");
}
void lanterndoortrapdoorlock(string &in asTimer)
{
    SetSwingDoorLocked("lanterndoortrapdoor", true, true);
    PlayGuiSound("door_level_wood_locked", 1);
}

Well, that's what I use.
But in my case, it closes, not opens...
12-11-2010, 07:13 PM
Find
Frontcannon Offline
Senior Member

Posts: 538
Threads: 10
Joined: Jul 2010
Reputation: 2
#5
RE: How to remove a Timer Loop which opens a door using AddPropForce?

An impulse with 150.0f force would SLAM it open very hard, not so subtle Big Grin

And using the timer loop creates the very problem which is the cause of this thread..


╔═════════════════╗
☺ Smoke weed everyday ☺
╚═════════════════╝
12-11-2010, 07:28 PM
Find
Akumasama Offline
Member

Posts: 122
Threads: 2
Joined: Nov 2010
Reputation: 0
#6
RE: How to remove a Timer Loop which opens a door using AddPropForce?

When is "opendoor" activated?
Could you show us that part of the script?
12-12-2010, 12:29 AM
Find
Frontcannon Offline
Senior Member

Posts: 538
Threads: 10
Joined: Jul 2010
Reputation: 2
#7
RE: How to remove a Timer Loop which opens a door using AddPropForce?

It's a CollideCallback in OnStart: the bottom one here to be precise:

    AddEntityCollideCallback("Player", "CollideEnterTorture", "EnterTorture", true, 1);
    AddEntityCollideCallback("Player", "CollideOpenDoor", "OpenDoor", true, 1); <-- this one


╔═════════════════╗
☺ Smoke weed everyday ☺
╚═════════════════╝
12-12-2010, 02:04 AM
Find
Akumasama Offline
Member

Posts: 122
Threads: 2
Joined: Nov 2010
Reputation: 0
#8
RE: How to remove a Timer Loop which opens a door using AddPropForce?

Mmm... that doesnt seem to be the problem.

Oh, I think I see it now.

void TimerDoor(string &in asTimer)
{
    if(asTimer == "swing_door")
    {
        AddPropForce("prison_section_2", 0.0f, 0.0f, 25.0f, "");
    }
    else
    {
        AddPropForce("prison_section_2", 0.0f, 0.0f, -95.0f, "");
    }
    AddTimer(asTimer, 0.03, "TimerDoor");
}
What it does, is that the timer isn't 0.01, so it keeps doing the second AddPropForce.
And thus, making it close/open all the time.
I think that this is the problem, when thinking logically.

EDIT: And so after reading your post again, I see this isn't what your looking for...
Maybe try making timer last longer, make the it push the door open until the time runs out, and have nothing on the other side of the "else".
That would make it stop looping...
(This post was last modified: 12-12-2010, 02:18 AM by Akumasama.)
12-12-2010, 02:13 AM
Find
Frontcannon Offline
Senior Member

Posts: 538
Threads: 10
Joined: Jul 2010
Reputation: 2
#9
RE: How to remove a Timer Loop which opens a door using AddPropForce?

For some reason, this worked:

void OpenDoor(string &in asParent, string &in asChild, int alState)
{
    SetSwingDoorClosed("prison_section_2", false, false);
    SetSwingDoorDisableAutoClose("prison_section_2", true);
    AddTimer("swing_door", 0.01f, "TimerDoor");
    SetEntityPlayerLookAtCallback("prison_section_2", "RemoveTimerCreak", true);
}

void TimerDoor(string &in asTimer)
{
    if(asTimer == "swing_door")
    {
        AddPropForce("prison_section_2", 0.0f, 0.0f, 25.0f, "");
    }
    else
    {
        AddPropForce("prison_section_2", 0.0f, 0.0f, -95.0f, "");
    }
    AddTimer(asTimer, 0.03, "TimerDoor");
}

void RemoveTimerCreak(string &in asEntity, int alState)
{
    RemoveTimer("swing_door");
    PlaySoundAtEntity("pant", "react_scare.snt", "Player", 0.0f, false);
}

Also, it's way more precise because the 'react_scare'-sound will now always be played at the right time Cool


╔═════════════════╗
☺ Smoke weed everyday ☺
╚═════════════════╝
12-12-2010, 07:34 PM
Find




Users browsing this thread: 1 Guest(s)