Scary Creaking
You probably wondered how to make a scary creaking like in the original game (for example - the wine cellar)?
It is actually pretty simple.
The Area(s)
First, you will need an area or areas. You can create how many you like. Name the first one however you like but the name of the others needs to be the same plus "_ + the number of the area" (for example -
area_1,
area_2,
area_3 and so on). I have created four areas and named them -
Creak_1,
Creak_2, Creak_3,
Creak_4.
What you will also need to do with the areas is to place them near the ceiling. My areas are touching the ceiling but are not colliding with it -
Attachment.
The Script
First, you will need to add a basic timer to your OnStart and set it up like this. Like this.
void OnStart()
{
AddTimer("creak", 1, "CreakingTimer");
}
"creak" - the name of the timer
1 - seconds until the function launches after the level loads
"CreakingTimer" - The name of the function to be called
You can change everyone of these.
Now, lets add the actual creaking. Copy this anywhere except for the OnStart, OnEnter and OnLeave part of the script
void CreakingTimer(string &in asTimer)
{
int iCreaking = RandFloat(1, 5);
float fCreaking = RandFloat(1.5f, 8);
PlaySoundAtEntity("creakSound" +iCreaking, "scare_wood_creak_mix", "Creak_" +iCreaking, 0.0f, false);
CreateParticleSystemAtEntity("creakPS" +iCreaking, "ps_dust_falling_small", "Creak_" +iCreaking, false);
AddTimer("creak", 1 +fCreaking, "CreakingTimer");
}
void CreakingTimer(string &in asTimer) - the name of the function we called in the OnStart(change it so it fits yours)
int iCreaking = RandFloat(1, 5); - (simplified) picks a random number between 1 and 5. That includes 1 but
DOES NOT INCLUDE 5. If you have four areas it must be
RandFloat(1, 5); If you have five areas it must be
RandFloat(1, 6);. Simply add one to the number of areas you have.
float fCreaking = RandFloat(1.5f, 8.5f); - this also picks a random number between 1.5 and 8.5 (including 1 and excluding 8). This random number is the amount of seconds from each creak.
PlaySoundAtEntity("creakSound" +iCreaking, "scare_wood_creak_mix", "Creak_" +iCreaking, 0.0f, false);
[i][u]"creakSound" +iCreaking -[/u][/i] the internal name of the sound.
"scare_wood_creak_mix" - the name of the actual sound to be player
+ extension .snt. Can be found under sounds/scares
"Creak_" +iCreaking - The area at which the sound is played. Creak_ is the name of your areas without the number. Since my areas are named Creak_1, Creak_2 and so on this MUST be Creak_. iCreaking is the random number of one of the areas(thus a random area).
0.0f - not really important. The amount of seconds until the sound reaches full volume (0.0f is recommended)
false - determines whether a sound should “remember” its state. If true, the
sound is never attached to the entity! Also note that saving should on
be used on looping sounds!
(From the wiki). Just leave it false.
CreateParticleSystemAtEntity("creakPS" +iCreaking, "ps_dust_falling_small", "Creak_" +iCreaking, false); - I'm not going to break this into parts. This creates the particle of the dust falling from the ceiling when you hear the scary wood walk creak.
AddTimer("creak", 1 +fCreaking, "CreakingTimer"); - This just repeats the function.
Final Script
How your script must look like when it's finished
void OnStart()
{
AddTimer("creak", 1, "CreakingTimer");
}
void CreakingTimer(string &in asTimer)
{
int iCreaking = RandFloat(1, 5);
float fCreaking = RandFloat(1.5f, 8);
PlaySoundAtEntity("creakSound" +iCreaking, "scare_wood_creak_mix", "Creak_" +iCreaking, 0.0f, false);
CreateParticleSystemAtEntity("creakPS" +iCreaking, "ps_dust_falling_small", "Creak_" +iCreaking, false);
AddTimer("creak", 1 +fCreaking, "CreakingTimer");
}
void OnEnter()
{
}
void OnLeave()
{
}