Facebook Twitter YouTube Frictional Games | Forum | Privacy Policy | Dev Blog | Dev Wiki | Support | Gametee


Thread Rating:
  • 2 Vote(s) - 4.5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Scary creaking Script Tutorial
amusei Offline
Junior Member

Posts: 23
Threads: 8
Joined: Aug 2012
Reputation: 2
#1
Scary creaking Script Tutorial

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()
{

}


Attached Files
.jpg   Attachment.jpg (Size: 348.35 KB / Downloads: 216)
09-04-2012, 12:00 PM
Find
Robby Offline
Posting Freak

Posts: 2,549
Threads: 38
Joined: Jun 2009
Reputation: 47
#2
RE: Scary creaking Script Tutorial

Very useful. Didn't know how those work. The timers, I knew those. But those "RandFloat", I never understood them.

Post this to the wikia! It will help.

Also, +1 for this!

Infrequently active. Don't expect an immediate response. Best to contact me at a different locale. If I create a thread, expect me to be quite active.
09-04-2012, 12:02 PM
Website Find
amusei Offline
Junior Member

Posts: 23
Threads: 8
Joined: Aug 2012
Reputation: 2
#3
RE: Scary creaking Script Tutorial

(09-04-2012, 12:02 PM)Nemet Robert Wrote: Very useful. Didn't know how those work. The timers, I knew those. But those "RandFloat", I never understood them.

Post this to the wikia! It will help.

Also, +1 for this!
Thanks. This is actually my first tutorial Blush . I will post it to the wiki Smile
09-04-2012, 12:04 PM
Find
Hardarm Offline
Posting Freak

Posts: 891
Threads: 39
Joined: Apr 2011
Reputation: 43
#4
RE: Scary creaking Script Tutorial

Will check it out later, great work! Big Grin

listen to boards of canada
09-06-2012, 10:06 PM
Website Find
go.go Offline
Junior Member

Posts: 11
Threads: 2
Joined: Jun 2012
Reputation: 0
#5
RE: Scary creaking Script Tutorial

I cant get the delay thing to work. I want the creaking sounds to come at a random time between 30 and 60 seconds, so i changed:

float fCreaking = RandFloat(1.5f, 8);

To:

float fCreaking = RandFloat(30f, 60);

But the sounds still come really frequently. Any idea why?
09-20-2012, 07:19 PM
Find
Ongka Offline
Member

Posts: 225
Threads: 3
Joined: Nov 2010
Reputation: 20
#6
RE: Scary creaking Script Tutorial

Nice to see new members posting useful stuff!
Good job on your first tutorial, keep it going Wink

[Image: 18694.png]
09-20-2012, 09:13 PM
Find
amusei Offline
Junior Member

Posts: 23
Threads: 8
Joined: Aug 2012
Reputation: 2
#7
RE: Scary creaking Script Tutorial

(09-20-2012, 07:19 PM)go.go Wrote: I cant get the delay thing to work. I want the creaking sounds to come at a random time between 30 and 60 seconds, so i changed:

float fCreaking = RandFloat(1.5f, 8);

To:

float fCreaking = RandFloat(30f, 60);

But the sounds still come really frequently. Any idea why?
Sorry I couldn't answer sooner but I was absent. Try changing the second timer(the one in the void CreakingTimer(string &in asTimer))
from
AddTimer("creak", 1 +fCreaking, "CreakingTimer");
to
AddTimer("creak1", 1 +fCreaking, "CreakingTimer");
The problem is probably because both timers have the same names. I'm not sure though because I don't seem to have that problem and changing the "float fCreaking = (1.5f, 8);" also changes the time between creaks and my timers have same names. Hope this work for you Smile
09-29-2012, 03:41 PM
Find




Users browsing this thread: 1 Guest(s)