Frictional Games Forum

Full Version: Sound script help
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Hi all!

I've just beaten the game for the first time, and I have decided to try my hand at a custom story. All was going well until I had to add a sound effect, and it wouldn't play.The game returns no errors, but the sound is not audible. The basic effect I'm going for is you wake up in a room with no sanity, hear creaky footsteps, and pass out. It should then transport you to a torture room where the story begins. The last line of the script is commented out because the map doesn't exist yet Tongue.


void OnStart()
{
PreloadSound("step_walk_wood_squeaky.snt");
PlaySoundAtEntity("steps", "step_walk_wood_squeaky.ogg", "Player", 0.0f, false);
SetPlayerSanity(1);
FadeRadialBlurTo(1.0f, 0.5f);
StartPlayerLookAt("look1", 1.0f, 1.0f, "");
AddTimer("", 15, "fade");
}
void fade(string &in asTimer)
{
FadeOut(1.0);
//ChangeMap("labyrinth_start.map");
}
PlaySoundAtEntity doesn't work with .ogg files (at least not directly); you will need a .snt file (it's basically a configuration file for sounds).
(08-26-2012, 02:21 AM)andyrockin123 Wrote: [ -> ]PlaySoundAtEntity doesn't work with .ogg files (at least not directly); you will need a .snt file (it's basically a configuration file for sounds).
I tired it with a .snt first, but it didn't work. I think I heard it play one step, but how do I loop it?
Try removing the . + extension altogether:

PlaySoundAtEntity("", "step_walk_wood_squeaky", "Player", 0.0f, false);
Still doesn't work... Maybe I just can't hear it? Is there a way to increase the volume?
To loop it you have to use timers. You only heard one step because the soundfile is supposed to play one step-sound only.
(08-26-2012, 04:24 AM)Ongka Wrote: [ -> ]To loop it you have to use timers. You only heard one step because the soundfile is supposed to play one step-sound only.
OK, but instead of using timers could I set a variable and have the script play the sound, add 1 to the variable, and then loop until the variable is a certain number?
You kinda need a timer to loop a function. Use this, but make sure to change the float to the amount of time (in seconds) you want between sounds, and change int (in the if function) to the amount of times you'd like it to repeat. You can add more stuff under the if statement:


void OnStart()
{
AddTimer("time_loop", float, "Sound_Loop");
SetLocalVarInt("loop_var", 0);
}

void Sound_Loop(string &in asTimer)
{
CheckVar();
PlaySoundAtEntity("step", "step_walk_wood_squeaky", "Player", 0.0f, false);
AddTimer("time_loop", float, "Sound_Loop");
AddLocalVarInt("loop_var", 1);
}

void CheckVar()
{
if(GetLocalVarInt("loop_var") == int)
{
RemoveTimer("time_loop");
StopSound("step", 2.0f);
}
}
(08-26-2012, 09:58 PM)andyrockin123 Wrote: [ -> ]You kinda need a timer to loop a function. Use this, but make sure to change the float to the amount of time (in seconds) you want between sounds, and change int (in the if function) to the amount of times you'd like it to repeat. You can add more stuff under the if statement:


void OnStart()
{
AddTimer("time_loop", float, "Sound_Loop");
SetLocalVarInt("loop_var", 0);
}

void Sound_Loop(string &in asTimer)
{
CheckVar();
PlaySoundAtEntity("step", "step_walk_wood_squeaky", "Player", 0.0f, false);
AddTimer("time_loop", float, "Sound_Loop");
AddLocalVarInt("loop_var", 1);
}

void CheckVar()
{
if(GetLocalVarInt("loop_var") == int)
{
RemoveTimer("time_loop");
StopSound("step", 2.0f);
}
}

I added your code in the appropriate locations, but it now throws an (unexpected end) error on line 32, char 2 (the end of the script). Here is what I have:



void OnStart()
{
PreloadSound("step_walk_wood_squeaky.snt");SetPlayerSanity(1);
FadeRadialBlurTo(1.0f, 0.5f);
StartPlayerLookAt("look1", 1.0f, 1.0f, "");
AddTimer("", 15, "fade");
AddTimer("loop_var", 0);
SetLocalVarInt("loop_var", 0);
}

void Sound_Loop(string &in asTimer)
{
CheckVar();
PlaySoundAtEntity("step", "step_walk_wood_squeaky.snt", "Player", 0.0f, false);
AddTimer("time_loop", 1, "Sound_Loop");
AddLocalVarInt("loop_var", 1);
}

void CheckVar()
{
if(GetLocalVarInt("loop_var") == 5)
{
RemoveTimer("time_loop);
StopSound("step", 2.0f);
}
}

void fade(string &in asTimer)
{
FadeOut(1.0);
//ChangeMap("labyrinth_start.map");
}
You're missing a quotation mark in:
RemoveTimer("time_loop);


It should be RemoveTimer("time_loop");
Pages: 1 2