User Tools

Site Tools


Sidebar

hpl2:tutorials:script:buttons_that_open_a_door

This is an old revision of the document!


Buttons that opens a door

Today I (xtron) will teach you (the reader) how to make lets say press 3buttons and a door opens.

First off you will be needing THE DOOR!

THE DOOR:

Press on entities (7) > Doors > Choose the door of your liking and place it out on your map. Change the name of your door to door1.

Now if you want it be unlock itself when you pressed those magic buttons you will need to lock it!.

Click on the door you just created > Entity > Check the Lock box.

Now you're done with adding the door, lets add some buttons then!.

THE BUTTONS:

Press on entities (7) > Gameplay > Press on button_simple and place out how buttons you want the player to press and rename the buttons to your liking, for example: button1, button2 , button3 etc…

Now you're done with adding the buttons, we can finally go to the scripting part! yeeey!.

THE SCRIPT:

Lets say that you want the player to press 4buttons and then a door unlocks itself and opens a bit.

Add this to your void OnStart()

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

When you're done adding that you can start adding the functions which looks like this:

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);
    }
}

You can change the function names and the door name to whatever you chosen and/or you want it to be.

When you successfuly managed to add this in to your .hps file it should look something like this:

void 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);
    }
}

Now. When the map loads Var1 will start with a count on 0 ( SetLocalVarInt(“var1”, 0); ). Everytime you press a button the funcs will

turn active and it adds 1 to the Var1 count, so if you press button1 Var1 will go from 0 to 1 and then you press button2 and Var1 will go

from 1 to 2 and so on until it reaches count 4 then func5 will occur and SetSwingdoorLocked will happen and PlaySoundAtEntity.

I hope you understand it and if you got any questions or requests on what I should show or how I should make my tutorials please send a

PM on Frictionalgames forum and I'll be glad to change it.

Thanks for reading!

by xtron

hpl2/tutorials/script/buttons_that_open_a_door.1310600612.txt.gz · Last modified: 2011/07/13 23:43 by xtron