User Tools

Site Tools


Sidebar

hpl2:tutorials:script:buttons_that_open_a_door

Buttons that opens a door

Today I (xtron) will teach you (the reader) how to make lets say press 4 buttons 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)<

    
                    
                                    
hpl2/tutorials/script/buttons_that_open_a_door.txt · Last modified: 2013/05/24 11:10 by grunt44432