cammie827
Junior Member
Posts: 6
Threads: 1
Joined: Aug 2012
Reputation:
0
|
Sound script help
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 .
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");
}
|
|
08-26-2012, 02:18 AM |
|
Adny
Posting Freak
Posts: 1,766
Threads: 6
Joined: Mar 2012
Reputation:
173
|
RE: Sound script help
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 rate it 3 memes.
|
|
08-26-2012, 02:21 AM |
|
cammie827
Junior Member
Posts: 6
Threads: 1
Joined: Aug 2012
Reputation:
0
|
RE: Sound script help
(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?
(This post was last modified: 08-26-2012, 02:27 AM by cammie827.)
|
|
08-26-2012, 02:25 AM |
|
Adny
Posting Freak
Posts: 1,766
Threads: 6
Joined: Mar 2012
Reputation:
173
|
RE: Sound script help
Try removing the . + extension altogether:
PlaySoundAtEntity("", "step_walk_wood_squeaky", "Player", 0.0f, false);
I rate it 3 memes.
|
|
08-26-2012, 02:28 AM |
|
cammie827
Junior Member
Posts: 6
Threads: 1
Joined: Aug 2012
Reputation:
0
|
RE: Sound script help
Still doesn't work... Maybe I just can't hear it? Is there a way to increase the volume?
(This post was last modified: 08-26-2012, 02:33 AM by cammie827.)
|
|
08-26-2012, 02:32 AM |
|
Ongka
Member
Posts: 225
Threads: 3
Joined: Nov 2010
Reputation:
20
|
RE: Sound script help
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 |
|
cammie827
Junior Member
Posts: 6
Threads: 1
Joined: Aug 2012
Reputation:
0
|
RE: Sound script help
(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?
|
|
08-26-2012, 09:50 PM |
|
Adny
Posting Freak
Posts: 1,766
Threads: 6
Joined: Mar 2012
Reputation:
173
|
RE: Sound script help
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 rate it 3 memes.
|
|
08-26-2012, 09:58 PM |
|
cammie827
Junior Member
Posts: 6
Threads: 1
Joined: Aug 2012
Reputation:
0
|
RE: Sound script help
(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");
}
|
|
08-26-2012, 11:35 PM |
|
Adny
Posting Freak
Posts: 1,766
Threads: 6
Joined: Mar 2012
Reputation:
173
|
RE: Sound script help
You're missing a quotation mark in:
RemoveTimer("time_loop);
It should be RemoveTimer("time_loop");
I rate it 3 memes.
|
|
08-26-2012, 11:39 PM |
|
|