Facebook Twitter YouTube Frictional Games | Forum | Privacy Policy | Dev Blog | Dev Wiki | Support | Gametee


Thread Rating:
  • 1 Vote(s) - 4 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Playing Sounds Randomly through a whole map.
tonitoni1998 Offline
Member

Posts: 163
Threads: 54
Joined: Oct 2012
Reputation: 1
#1
Playing Sounds Randomly through a whole map.

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

When you are looking for someone, to do the scripting for your Custom Story, ask me!
(This post was last modified: 03-01-2013, 08:43 PM by tonitoni1998.)
03-01-2013, 08:42 PM
Find
Adny Offline
Posting Freak

Posts: 1,766
Threads: 6
Joined: Mar 2012
Reputation: 173
#2
RE: Playing Sounds Randomly through a whole map.

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

I rate it 3 memes.
03-01-2013, 08:53 PM
Find
Rapture Offline
Posting Freak

Posts: 1,078
Threads: 79
Joined: May 2011
Reputation: 30
#3
RE: Playing Sounds Randomly through a whole map.

Here is a simple example if you wanted a infinite loop and plays different random sounds at the players location.
Spoiler below!
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");
}

(This post was last modified: 03-01-2013, 09:04 PM by Rapture.)
03-01-2013, 09:04 PM
Find




Users browsing this thread: 1 Guest(s)