Frictional Games Forum
Sound script help - Printable Version

+- Frictional Games Forum (https://www.frictionalgames.com/forum)
+-- Forum: Amnesia: The Dark Descent (https://www.frictionalgames.com/forum/forum-6.html)
+--- Forum: Custom Stories, TCs & Mods - Development (https://www.frictionalgames.com/forum/forum-38.html)
+---- Forum: Development Support (https://www.frictionalgames.com/forum/forum-39.html)
+---- Thread: Sound script help (/thread-17963.html)

Pages: 1 2


Sound script help - cammie827 - 08-26-2012

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");
}


RE: Sound script help - Adny - 08-26-2012

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).


RE: Sound script help - cammie827 - 08-26-2012

(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?


RE: Sound script help - Adny - 08-26-2012

Try removing the . + extension altogether:

PlaySoundAtEntity("", "step_walk_wood_squeaky", "Player", 0.0f, false);


RE: Sound script help - cammie827 - 08-26-2012

Still doesn't work... Maybe I just can't hear it? Is there a way to increase the volume?


RE: Sound script help - Ongka - 08-26-2012

To loop it you have to use timers. You only heard one step because the soundfile is supposed to play one step-sound only.


RE: Sound script help - cammie827 - 08-26-2012

(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?


RE: Sound script help - Adny - 08-26-2012

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);
}
}



RE: Sound script help - cammie827 - 08-26-2012

(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");
}



RE: Sound script help - Adny - 08-26-2012

You're missing a quotation mark in:
RemoveTimer("time_loop);


It should be RemoveTimer("time_loop");