Frictional Games Forum (read-only)

Full Version: Problem with Scripts: AddPropForce not working
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello, I am trying to get a swing door to open slowly by itself using AddPropForce. An example of what I want is in the original Amnesia in the Rain Hall level. However for the past 2 hours I have been trying to do this but every single time I enter the script area, the door does nothing. Everything looks fine in the script but it just doesn't want to work.

Here is the entire script for the level:
Code:
//This is only executed when the map is loaded for the first time. Only happens once. Can be used for adding effects that should not repeat.//
void OnStart()
{  
    SetPlayerLampOil(70);
    GiveItemFromFile("lantern", "lantern.ent");
    AddEntityCollideCallback("Player", "Door_Creepy", "DoorOpens", true, 1);
}

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

void TimerDoor(string &in asTimer)
{
    if(asTimer == "swing_door")
    {
        AddPropForce("CreepyDoor", 500.0f, 0.0f, 0.0f, "world");
    }
}

//This is executed every time you enter the level. Can be executed several times. Can be used for playing music and adding checks.//
void OnEnter()
{
    AddEntityCollideCallback("Player", "ReturnPlayerArea_0", "ReturnPlayer", false, 1);
}

void ReturnPlayer(string &in asParent, string &in asChild, int alState)
{
    TeleportPlayer("PlayerStartArea_1");
}

//This is executed every time you leave the level. Can be executed several times. Can be used for stopping music//
void OnLeave()
{

}

I just don't know what to do and need help.
I think you're not adding enough. From the wiki:

These functions push objects. Note that rather high values are needed when applying forces (on the order of ~100 (weak) to ~10000 (strong)),

Pump that number up a bit and you should see some effects.
That's not the problem unfortunately, I think it's the script or the AddEntityCollideCallback...
I don't think that "if astimer" part is needed. I've used tons of timers and never needed to use an if statement to get them to work.
I did some changes to the script and the objects in the level editor, and seems I can now only get it to work until after I interact with the door.

Here is the modified script:

Code:
//This is only executed when the map is loaded for the first time. Only happens once. Can be used for adding effects that should not repeat.//
void OnStart()
{  
    SetPlayerLampOil(70);
    GiveItemFromFile("lantern", "lantern.ent");
    AddEntityCollideCallback("Player", "TestDoorScript", "TestFunction", false, 1);
}

void TestFunction(string &in asParent, string &in asChild, int alState)
{
    SetSwingDoorClosed("mansion_1", false, false);
    SetSwingDoorDisableAutoClose("mansion_1", true);
    AddTimer("swing_door", 0.001f, "TimerDoor");
}

void TimerDoor(string &in asTimer)
{
    AddPropForce("mansion_1", -1000.0f, 0.0f, 0.0f, "world");
}

//This is executed every time you enter the level. Can be executed several times. Can be used for playing music and adding checks.//
void OnEnter()
{
    AddEntityCollideCallback("Player", "ReturnPlayerArea_0", "ReturnPlayer", false, 1);
}

void ReturnPlayer(string &in asParent, string &in asChild, int alState)
{
    TeleportPlayer("PlayerStartArea_1");
}

//This is executed every time you leave the level. Can be executed several times. Can be used for stopping music//
void OnLeave()
{

}
AddPropForce must be above 2000 to get visible effects.