Frictional Games Forum (read-only)
Get a door to open? - 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 - Development (https://www.frictionalgames.com/forum/forum-38.html)
+---- Forum: Development Support (https://www.frictionalgames.com/forum/forum-39.html)
+---- Thread: Get a door to open? (/thread-23059.html)



Get a door to open? - gruzz - 09-12-2013

Hello!

Creating a CS and i just want to know how i make a door open when i enter a area.. Found no guides on YT or on http://wiki.frictionalgames.com/hpl2/amnesia/script_functions#doors !

Please, help me! Smile


RE: Get a door to open? - Neelke - 09-12-2013

I'm using SetSwingDoorDisableAutoClose and AddPropForce. Like this:

void NAMEOFSCRIPT()

SetSwingDoorDisableAutoClose("DOORNAME", true);
SetSwingDoorClosed("DOORNAME", false, false);

if(GetLocalVarInt("Door") == 8){
Some stuff you want to happen after the door has opened
}
else
{
AddTimer("", 0.15f, "DoorOpenRepeat");
AddPropForce("DOORNAME", 0.0f, 0, 100.0f, "World");
AddLocalVarInt("Door", 1);
}
void DoorOpenRepeat(string &in asTimer)
{
NAMEOFSCRIPT();
}

Quite simple. But I would recommend trying some stuff yourself. Also, the AddPropForce might not be correct so test it until it starts opening.


RE: Get a door to open? - gruzz - 09-12-2013

(09-12-2013, 06:44 PM)Neelke Wrote: I'm using SetSwingDoorDisableAutoClose and AddPropForce. Like this:

void NAMEOFSCRIPT()

SetSwingDoorDisableAutoClose("DOORNAME", true);
SetSwingDoorClosed("DOORNAME", false, false);

if(GetLocalVarInt("Door") == 8){
Some stuff you want to happen after the door has opened
}
else
{
AddTimer("", 0.15f, "DoorOpenRepeat");
AddPropForce("DOORNAME", 0.0f, 0, 100.0f, "World");
AddLocalVarInt("Door", 1);
}
void DoorOpenRepeat(string &in asTimer)
{
NAMEOFSCRIPT();
}

Quite simple. But I would recommend trying some stuff yourself. Also, the AddPropForce might not be correct so test it until it starts opening.

Well, as a guy who totally new to scripting, this honestly did not say much..


RE: Get a door to open? - The chaser - 09-12-2013

In the wiki there are some great tutorials, not every one covers your need, however. The thing is learning what things do and learning it. Then, you can do it by yourself with your knowledge.

And I see that you are new to scripting, so I'm going to write the script for what you want and I'm going to explain what does what:

void OnStart()
{
AddEntityCollideCallback("Player", "ScriptArea", "OPEN", true, 1);
}

///These lines (/) are commentary, useful when making very long scripts, so you can keep them tidied. So, here's an explanation of OnStart(), OnEnter() and all of that: http://wiki.frictionalgames.com/hpl2/amnesia/script_functions#main

////AddEntityCollideCallback means "Add a callback when an entity collides". The first 2 brackets are the ///entity that triggers an event when colliding (in this case, Player). "ScriptArea" is the name of the ///Entity/Area that has to receive the collision to trigger the event. This means that, when "Player" ///collides with "ScriptArea", "OPEN" will hapen. More information about the AddEntityCollideCallback:

///void AddEntityCollideCallback(string& asParentName, string& asChildName, string& asFunction, bool abDeleteOnCollide, int alStates);


//Calls a function when two entites collide.


//Callback syntax: void MyFunc(string &in asParent, string &in asChild, int alState)


//alState: 1 = enter, -1 = leave




//asParentName - internal name of main object


//asChildName - internal name of object that collides with main object (asterix (*) NOT supported!)


//asFunction - function to call


//abDeleteOnCollide - determines whether the callback after it was called


//alStates - 1 = only enter, -1 = only leave, 0 = both

So:

void OnStart()
{
AddEntityCollideCallback("Player", "ScriptArea", "OPEN", true, 1);
}

void OPEN (string &in asParent, string &in asChild, int alState) //http://www.frictionalgames.com/forum/thread-18368.html
{
SetSwingDoorDisableAutoClose("YourDoor", true); //This will stop the door from closing as soon as it opens.
SetSwingDoorClosed("YourDoor", 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.


}

And that's the script explained. Have a nice scripting time! Smile