Hpl2:Tutorials:script:events

From Frictional Wiki
Jump to navigation Jump to search

Scary events

Today I (xtron) will show you! (the reader) how to make scary events that will yea…scare the player!.


The door slam

The Door.

we will startoff this tutorial with the basic door slam!.


Start with adding a door.


Go to entities > Door > Choose a door that you want to slam. Change the name of it.


Now when you got the door added you need to change the open ammount.


Click on the door > Entity > Look for "OpenAmount" and change it to 1. 1 is just a recommendation you can choose anything really.


Now you're done with the door. Let's get going to the Script Area.


The Script Area.

Press on Area (8) > Script and make an area infront of the door like so:


img705.imageshack.us/img705/4039/doorslam.png


When you're done with that you need to change it's name, pick anything just remember it.


Now we're done with the Script Area, let's get going to the actuall scripting.


The Script

First off we will be needing to add an EntityCollideCallBack to the void OnStart()


AddEntityCollideCallback("Player", "script_slam", "func_slam", true, 1);


When you're done adding that we will need to start working on the function.


First function we're gonna add is the actuall slam!.


void func_slam(string &in asParent, string &in asChild, int alState)
{
SetSwingDoorClosed("door1", true, true);
}


That was the first function of a couple.


After the slam we want some sanity increase and maybe one or two sounds! (three actually).


void func_move_box1(string &in asParent, string &in asChild, int alState)


{
SetSwingDoorClosed("door1", true, true);
 
PlaySoundAtEntity("", "react_breath_slow.snt", "Player", 0, false);
 
PlaySoundAtEntity("", "react_scare", "Player", 0, false);
 
PlaySoundAtEntity("", "close_door.snt", "Player", 0, false);
 
GiveSanityDamage(5.0f, true);
}


Now we got the door slam setup. The result of this one should look like this


void OnStart()
 
{
AddEntityCollideCallback("Player", "script_slam", "func_slam", true, 1);
} 
 
void func_slam(string &in asParent, string &in asChild, int alState)
{
SetSwingDoorClosed("door2", true, true);
 
PlaySoundAtEntity("", "react_breath_slow.snt", "Player", 0, false); 
 
PlaySoundAtEntity("", "react_scare", "Player", 0, false);  PlaySoundAtEntity("", "close_door.snt", "Player", 0, false); 
 
GiveSanityDamage(5.0f, true);
}


The exploding door

The exploding door! My favorite!.


It's almost like the slaming door but with a few modifications.


The Door

You will need to go to the level editor:


Click on the door > Entity > Change OpenAmount to 0. So it's closed.


The Script

We will be using the same function as the door slam so copy&paste it.


void func_slam(string &in asParent, string &in asChild, int alState)
{
SetSwingDoorClosed("door2", true, true);
 
PlaySoundAtEntity("", "react_breath_slow.snt", "Player", 0, false);
 
PlaySoundAtEntity("", "react_scare", "Player", 0, false);
 
PlaySoundAtEntity("", "close_door.snt", "Player", 0, false);
 
GiveSanityDamage(5.0f, true);
}


What you now want to do is replace the SetSwingDoorClose with


SetPropHealth("door1", 0.0f);


So it looks like this


void func_slam(string &in asParent, string &in asChild, int alState)
{
SetPropHealth("door1", 0.0f);
 
PlaySoundAtEntity("", "react_breath_slow.snt", "Player", 0, false);
 
PlaySoundAtEntity("", "react_scare", "Player", 0, false);
 
 
 
PlaySoundAtEntity("", "close_door.snt", "Player", 0, false);
 
 
GiveSanityDamage(5.0f, true);
}


Then we need to change the void OnStart abit.


Replace


SetEntityPlayerInteractCallback("door1", "func_slam", true);


And replace


void func_slam(string &in asParent, string &in asChild, int alState)


with


void func_slam(string &in asEntity)


Now we're done with the Exploding door!. The result should look something like this:


void OnStart()
 
 
{
SetEntityPlayerInteractCallback("door1", "func_slam", true);
}
 
 
void func_slam(string &in asParent, string &in asChild, int alState)
{
SetPropHealth("door1", 0.0f);
 
 
PlaySoundAtEntity("", "react_breath_slow.snt", "Player", 0, false);
 
 
PlaySoundAtEntity("", "react_scare", "Player", 0, false);
 
 
PlaySoundAtEntity("", "close_door.snt", "Player", 0, false);
 
 
GiveSanityDamage(5.0f, true);
}


This is how you create some door events.


I hope you find this usefull. If you got any questions or requests on tutorials please send me a PM on the forum.


Thanks for reading.




tutorial by xtron