Frictional Games Forum (read-only)
(Script)Lever Opens a Door - 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: (Script)Lever Opens a Door (/thread-16072.html)

Pages: 1 2


(Script)Lever Opens a Door - No Author - 06-12-2012

Hi, guys. I'm making a custom story and there's a lever that opens and closes a door. The name of the door is "wooden_slide_door_1". And I have no idea how to script it. Can someone tell me how to do it ?


RE: (Script)Lever Opens a Door - Putkimato - 06-12-2012

void OnStart()

{

SetEntityConnectionStateChangeCallback("lever", "leverfunc");
SetEntityConnectionStateChangeCallback("lever", "leverfunc2");
}

void leverfunc(string &in asEntity, int alState)
{
if (alState == 1)

SetSwingDoorLocked("door", false, true);
PlaySoundAtEntity("", "unlock_door", "door", 0, false);
}

void leverfunc2(string &in asEntity, int alState)
{
if (alState == -1)

SetSwingDoorClosed("door", false, true);
PlaySoundAtEntity("", "unlock_door", "door", 0, false);
}

When you drag lever down, door unlocks, and when you stop dragging it down, it locks.. Its kinda buggy script, i can make it better if you need Smile


RE: (Script)Lever Opens a Door - No Author - 06-12-2012

Make it better please

And BTW does that work for valves ?


RE: (Script)Lever Opens a Door - Putkimato - 06-12-2012

(06-12-2012, 12:54 PM)TheNoAuthor12 Wrote: Make it better please

And BTW does that work for valves ?
Maybe, what if you make two levers? another opens, another closes


RE: (Script)Lever Opens a Door - No Author - 06-13-2012

Okay. But, I want to make lever that opens and closes the door. Is that possible ?


RE: (Script)Lever Opens a Door - Putkimato - 06-13-2012

(06-13-2012, 06:40 AM)TheNoAuthor12 Wrote: Okay. But, I want to make lever that opens and closes the door. Is that possible ?
I think it is.. But its hard, i always just make 2 levers Tongue Im not good scripter, started like month ago.


RE: (Script)Lever Opens a Door - No Author - 06-13-2012

(06-13-2012, 09:48 AM)Putkimato Wrote:
(06-13-2012, 06:40 AM)TheNoAuthor12 Wrote: Okay. But, I want to make lever that opens and closes the door. Is that possible ?
I think it is.. But its hard, i always just make 2 levers Tongue Im not good scripter, started like month ago.
I started like a few days ago.


RE: (Script)Lever Opens a Door - SilentHideButFine - 06-13-2012

(06-12-2012, 08:46 AM)TheNoAuthor12 Wrote: Hi, guys. I'm making a custom story and there's a lever that opens and closes a door. The name of the door is "wooden_slide_door_1". And I have no idea how to script it. Can someone tell me how to do it ?
Take the script he gave you its good and easy to understand if not follow this (this tut is with buttons)

http://wiki.frictionalgames.com/hpl2/tutorials/script/buttons_that_open_a_door

Smile


oid OnStart()
{
SetLocalVarInt("Var1", 0);
SetEntityPlayerInteractCallback("button1", "func1", true);
SetEntityPlayerInteractCallback("button2", "func2", true);
SetEntityPlayerInteractCallback("button3", "func3", true);
SetEntityPlayerInteractCallback("button4", "func4", true);
}

void func1(string &in asEntity)
{
AddLocalVarInt("Var1", 1);
func5();
}

void func2(string &in asEntity)
{
AddLocalVarInt("Var1", 1);
func5();
}

void func3(string &in asEntity)
{
AddLocalVarInt("Var1", 1);
func5();
}

void func4(string &in asEntity)
{
AddLocalVarInt("Var1", 1);
func5();
}

void func5()
{
if(GetLocalVarInt("Var1") == 4)
{
/////add what ever you want to happen after you press all 4 buttons here.
SetSwingDoorLocked("door1", false, false);
PlaySoundAtEntity("", "unlock_door.snt", "door1", 0.5f, false);
}
}
I think you can change the Entity to lever not sure but anywaySmile


RE: (Script)Lever Opens a Door - No Author - 06-13-2012

I'll try it first then change it to a lever

It doesn't work. I can't get it open.


RE: (Script)Lever Opens a Door - Theforgot3n1 - 06-13-2012

Ehm, so you want a button that closes and locks the door at the same time when pushed?

Code:
void OnStart()



{



SetEntityConnectionStateChangeCallback("lever", "leverfunc");

SetEntityConnectionStateChangeCallback("lever", "leverfunc2");

}



void leverfunc(string &in asEntity, int alState)

{

if (alState == 1)
SetMoveObjectStateExt("wooden_slide_door_1", 1.0f, 1.0f, 5.0f, 5.0f, true);
//All the numbers on the script above depends on what speed you want it to open. Check out "Engine Scripts" //in the wiki for more information.

}



void leverfunc2(string &in asEntity, int alState)

{

if (alState == -1)

SetMoveObjectStateExt("wooden_slide_door_1", 0.0f, 1.0f, 5.0f, 5.0f, true);

}

That should be all. I'm slightly unsure if the SetMoveObjectStateExt works exactly like they should. But yeah, you can always check the Engine Scripts in the wiki.
Good luck!