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


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Ambient sounds
Danny Boy Offline
Posting Freak

Posts: 2,718
Threads: 85
Joined: Mar 2011
Reputation: 81
#1
Ambient sounds

ok then... i have seen in some custom stories that people tend to forget to add some ambient sounds like a owl sound in a corner some wind in the back and some wood crakes at the bottom... does eny one knows how to do this? like in a ramdom or ramdom like why?
(This post was last modified: 04-19-2011, 02:33 AM by Danny Boy.)
04-19-2011, 12:30 AM
Website Find
Danny Boy Offline
Posting Freak

Posts: 2,718
Threads: 85
Joined: Mar 2011
Reputation: 81
#2
RE: Ambient sounds

help please... eny one?
04-19-2011, 02:33 AM
Website Find
Anxt Offline
Senior Member

Posts: 588
Threads: 12
Joined: Mar 2011
Reputation: 10
#3
RE: Ambient sounds

I have random ambient sounds in one of my earlier maps, it isn't HARD to do, but it is a fair bit of code the way I did it. There may be a simpler way, but here's how I did it:

In OnEnter and any checkpoints, I call a timer that calls a function that picks a random number 1-8 (the number of sounds I have it choosing from). Then, I have an if statement for each sound I want it to play corresponding to a particular number. So, if the random number happens to be 4, it will play the sound I designated to 4.

Does that makes sense?

04-19-2011, 02:53 AM
Find
Apjjm Offline
Is easy to say

Posts: 496
Threads: 18
Joined: Apr 2011
Reputation: 52
#4
RE: Ambient sounds

If you want to create a pseudo-random effect, just slapping a few flicker lights (with no light) with a sound-play event and some decent delays might do the trick for simple ambient sounds. But lets say you want to get a real random selection there is a very simple way to do it using an array:
//Pick an index of snds at random\\
int r = RandInt(0,3);
string[] snds = {"ambience_wind_eerie.snt",
                      "ambience_sewer_drip.snt",
                      "ambience_voice.snt",
                      "ambience_cave.snt"};
string snd = snds[r];
//And play that sound!\\
AddDebugMessage(snd,false);
PlaySoundAtEntity("RandSnd",snd,"Player",0,false);
There is another way you could tackle this, which would perhaps offer a little more flexibility: For example if you wanted a bank of sounds that changed in size, and can be used, changed and the status stored across maps. To do this you would have to use SetGlobalVarString() (or Local if you don't care about the cross map thing), and set yourself up an array as follows:
//Use at the start of ya game.
AddGlobalVarString("snd0","ambience_wind_eerie.snt");
AddGlobalVarString("snd1","ambience_wind_eerie_no3d.snt");
AddGlobalVarString("snd2","ambience_sewer_drip.snt");
AddGlobalVarString("snd3","ambience_voice.snt");
AddGlobalVarString("snd4","ambience_cave.snt");
AddGlobalVarInt("sndx",4); //Index of the last sound you have.
How to select a sound becomes a little more tricky. As far as i am aware a toString() function isn't accessible, so you have to write you own. But then accessing is still just as easy:
void playsoundrandom()
{
//Pick an index of the variable size "array" snd.
int r = RandInt(0,GetGlobalVarInt("sndx"));
//If you get an error it is in ^ that or V that line\\
string snd = GetGlobalVarString("snd"+toString(r));
//And play!\\
AddDebugMessage(snd,false);
PlaySoundAtEntity("RandSnd",snd,"Player",0,false);
}

string toString(int value)
     { //Returns string representation of value\\
      string sign = ""; string output=""; int diff=0;
      if(value == 0) {return "0";} else if(value < 0) {value = -value; sign = "-";}
      while(value > 0) {
        diff = value; value /= 10; diff -= value * 10;    
        switch(diff) {
         case 0: {output = "0" + output; break;}
         case 1: {output = "1" + output; break;}
         case 2: {output = "2" + output; break;}
         case 3: {output = "3" + output; break;}
         case 4: {output = "4" + output; break;}
         case 5: {output = "5" + output; break;}
         case 6: {output = "6" + output; break;}
         case 7: {output = "7" + output; break;}
         case 8: {output = "8" + output; break;}
         case 9: {output = "9" + output; break;}
                     } }
       return sign+output;
     } //End of toString()\\
This is quite a little bit more effort obviously, but you have a good range of options there, though unless you are going for something really complex (cross map stuff), one of the top two ways should work a treat with a little tweaking. Remember that you can define arrays OUTSIDE OF FUNCTIONS to make them visible to all the functions for that script file:
string[] starts = {"hello","how","are","you"};
void function1()
{
AddDebugMessage(starts[0],false);
}
void function2()
{
AddDebugMessage(starts[1],false);
}
(This post was last modified: 04-19-2011, 04:44 AM by Apjjm.)
04-19-2011, 04:36 AM
Find




Users browsing this thread: 1 Guest(s)