Frictional Games Forum (read-only)
Playing Sounds Randomly through a whole map. - Printable Version

+- Frictional Games Forum (read-only) (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: Playing Sounds Randomly through a whole map. (/thread-20574.html)



Playing Sounds Randomly through a whole map. - tonitoni1998 - 03-01-2013

hello,

i want to play sounds randomly through a whole map. i wanted to work with a loop, that adds a timer al over again and it always has a different time. and i tried to work with RandFloat to set a random time. i tried it like this at first.
Code:
float p = RandFloat(1.0f, 50.0f);
void OnStart()
{
for(int i=1;i<100;i++);
{
    AddTimer("", p, "");
}
}

so i guess there are a lot of mistakes in it and it will never work as i want it. so im asking for somehelp from you guys, how i could do it.

what exactly do i want to do: when the player enters the map, some sounds i´ve chosen before are randomly played. the time between the sounds should also vary.


RE: Playing Sounds Randomly through a whole map. - Adny - 03-01-2013

To set up a basic repeating timer (with random times), it will look something like this:

Spoiler below!


void OnStart()
{
AddTimer("", RandFloat(25.0f, 60.0f), "ambience");
}

void ambience(string &in asTimer)
{
AddTimer("", RandFloat(25.0f, 60.0f), "ambience");
}


Getting the different sounds to play is a bit trickier though. Can't think of a solution off the top of my head atm, I'll post back later if I think of something. Good luck with the rest Big Grin


RE: Playing Sounds Randomly through a whole map. - Rapture - 03-01-2013

Here is a simple example if you wanted a infinite loop and plays different random sounds at the players location.
Spoiler below!
Code:
int ASound;
      
void OnStart()
{
ASound = 0;

AddTimer("TimerName_RandomSounds_0", 10, "Timer_RandomSounds_0");
}
void Intro()
{

}
void OnEnter()
{

}
//******************************************************************************************************
void Timer_RandomSounds_0(string &in asTimer)
{
ASound = RandFloat(1, 3);

if(ASound == 1)
{  
  PlaySoundAtEntity("Sound 1", "ExampleSound1.snt", "Player", 2, true);
}

if(ASound == 2)
{  
  PlaySoundAtEntity("Sound 2", "ExampleSound2.snt", "Player", 2, true);
}

if(ASound == 3)
{  
  PlaySoundAtEntity("Sound 2", "ExampleSound3.snt", "Player", 2, true);
}

AddTimer("TimerName_RandomSounds_0", RandFloat(5, 10);,  "Timer_RandomSounds_0");
}