Random audio player

Posted By: Redoine

Random audio player - 02/11/13 14:29

hello guys

i finshed working on my litle FPS game thanx to you guys

but i still don't know how to make a random audio player

because when i shoot the enemy or enemy shoots me i hear the same

thing (the voice that player say when he gets heard)

so i want to add deferent sounds and make a program that plays

those sounds randomly

thank you very much
Posted By: 3run

Re: Random audio player - 02/11/13 14:35

That will be pretty simple, you'll need to use "integer" and "random", as in this example:
Code:
var randomSound = integer(random(2)); // two random sounds
if(randomSound == 0){ 
     // play first sound here 
}
if(randomSound == 1){
     // play second sound here
}

But, you have to understand, that the value, which is returned by "integer(random(2));", will be always smaller than "2"!
So if you'll try something like this:
Code:
if(randomSound == 2){
    // play something here
}

It won't work! Good luck!
Posted By: lostzac

Re: Random audio player - 02/11/13 14:35

Just off the top of my head probably a better way

Code:
var num_songs = 2;
var sound_handle;

function switch_sound(snd)
{
     switch(snd)
     {
        CASE 0:
        sound_handle = snd_play(sound1, 100, 0);
        break;

        CASE 1:
        sound_handle = snd_play(sound2, 100, 0);
        break;

     }
}

void main()
{
   random_seed(0);
   var random_sound = integer(random(num_songs ));
   switch_sound(random_sound );
}



Just typed this have not tested it
Posted By: Redoine

Re: Random audio player - 02/11/13 14:40

Thank you guys very much
© 2024 lite-C Forums