Frictional Games Forum (read-only)

Full Version: (Script)Lever Opens a Door
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
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 ?
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
Make it better please

And BTW does that work for valves ?
(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
Okay. But, I want to make lever that opens and closes the door. Is that possible ?
(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.
(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.
(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/tut...pen_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
I'll try it first then change it to a lever

It doesn't work. I can't get it open.
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!
Pages: 1 2