Frictional Games Forum (read-only)

Full Version: Playing Sounds Randomly through a whole map.
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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.
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
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");
}