From Frictional Wiki
Jump to navigation Jump to search

Push Doors Open( using Force)

Force, aside from moving things around, can be used to open doors and things such as cabinets which can be opened.

This page describes what AddBodyForce/AddPropForce does and how to find out which of the X, Y, or Z variables you want to increase or decrease, in this case it would be whichever way the door opens.

First, of course you would want to set up when it will open in your script, for the example I'll use a LookAtCallback, triggered when looking at the door.

void lookatdoor(string &in entity, int alState)
 if(GetSwingDoorClosed(entity))  //Checks to see if the door is closed.
       SetSwingDoorDisableAutoClose(entity, true);  //This will stop the door from closing as soon as it opens.
       SetSwingDoorClosed(entity, false, true);  //This opens the door so that the force will do something, and not act like throwing a book at a closed door.
       AddPropForce(entity, 0, 0, -900, "world"); //This will actually push the door open. This assumes that the door opens towards -Z, and "world" tells it to use the -Z
                                                  //for the level editor, and not base on I suppose the direction the player is facing? You'd probably almost always want "world" and not something else.

Now, I will also explain something that might not be obvious; In this code "entity" is placed without quotation marks where the name of the entity would be, and if this were put in the entity's PlayerLookAtCallback it will work work because

the "entity" in "string &in entity" at the beginning of the function(just after it's name) is a string variable that is assigned the entity's name if it's placed on the entity's PlayerLookAtCallback text box. Meaning, this would work for a door name "mansion_1", and for another named "room3" at the same time.

Opening entities with "doors"

Opening entities with doors, that aren't door entities is fairly similar to opening doors, however you need to use AddBodyForce instead of AddPropForce, which requires a body name rather than an entity name.

So, for starters you'll need what you want to open, I happen to have the bodies needed to a metal cabinet in some code so I'll use that for an example.

AddBodyForce("cabinet1_rightDoor", 0, 0, -900, "world");
AddBodyForce("cabinet1_leftDoor", 0, 0, -900, "world");

In this example, "cabinet1" is the name of the entity. By adding an underscore at the end of the entity name, you can type in a specific body name, metal cabinets, easily enough, have "rightDoor" and "leftDoor" as the door body names.

It is necessary to use this instead of AddPropForce because if you use AddPropForce, the doors will just shift forward or, with a high enough number, fly away through the walls taking any entities in it's way with it.

Finding out what a body's name is, is rather easy. All you do is open the model editor and open the .ent file for the entity you want to use. This should bring up the finished model with pink boxes at the doors, just click these boxes, making sure that you select the right one, and then just use the name in the code as shown above.