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


Messages In This Thread
Ambient sounds - by Danny Boy - 04-19-2011, 12:30 AM
RE: Ambient sounds - by Danny Boy - 04-19-2011, 02:33 AM
RE: Ambient sounds - by Anxt - 04-19-2011, 02:53 AM
RE: Ambient sounds - by Apjjm - 04-19-2011, 04:36 AM



Users browsing this thread: 1 Guest(s)