[Script] Random Sound

aL BeasTie

Well-known member
SCRIPT:  Random Sound Script.

COMMANDS:
'randSound' - choice of 3 sounds

'randSound2' - choice of 6 sounds

USAGE: randSound / randSound2 is case sensitive!

Code:
@cmd	randSound "1.wav" "2.wav" "3.wav"

Code:
@cmd	randSound2 "1.wav" "2.wav" "3.wav" "4.wav" "5.wav" "6.wav"

example in character anim -

Code:
anim     attack1
loop     0
delay
offset  20 100
frame  data/chars/guy/idle.png
@cmd	randSound "1.wav" "2.wav" "3.wav"
frame  data/chars/guy/idle.png


SETUP

- Copy randsound.c to the scripts folder - DATA/SCRIPTS
- in entity/char header add
Code:
animationscript data/scripts/randsound.c

- IF you already have an animationscript in use then add this to the header of the current script.
Code:
#import	"data/scripts/randsound.c"


randSound - Version 1 - plays directly from DATA/SOUNDS

copy and paste to randsound.c
Code:
void randSound(char s1,char s2,char s3)
{
   int r = rand()%300;
   char sound;
   if (r<=-100)
   {
      sound=s1;
   }else if(r<=100){
      sound=s2;
   }else{
      sound=s3;
   }
   playSound("data/sounds/"+sound);
}
void randSound2(char s1,char s2,char s3,char s4,char s5,char s6)
{
   int      r      =   rand()%300+300;
   char   sound   =   "";

   if (r<100){
      sound=s1;
   }else if(r<200){
      sound=s2;
   }else if(r<300){
      sound=s3;
   }else if(r<400){
      sound=s4;
   }else if(r<500){
      sound=s5;
   }else if(r<600){
      sound=s6;
   }
   playSound("data/sounds/"+sound);
}
void playSound(void file)
{
   if(!file||file==""){return;}else{}
   int sfx=loadsample(file);
   playsample(sfx, 0, openborvariant("effectvol"), openborvariant("effectvol"), 100, 0);
}


randSound - Version 2 - Plays from DATA directory,
so you must provide directory in the command,

examples

Code:
@cmd   randSound "sounds/1.wav" "sounds/2.wav" "sounds/3.wav"
Code:
@cmd   randSound "chars/ryu/snd/1.wav" "chars/ryu/snd/2.wav" "chars/ryu/snd/3.wav"


randSound - Version 2

copy and paste to randsound.c
Code:
void randSound(char s1,char s2,char s3)
{
   int r = rand()%300;
   char sound;
   if (r<=-100)
   {
      sound=s1;
   }else if(r<=100){
      sound=s2;
   }else{
      sound=s3;
   }
   playSound("data/"+sound);
}
void randSound2(char s1,char s2,char s3,char s4,char s5,char s6)
{
   int      r      =   rand()%300+300;
   char   sound   =   "";

   if (r<100){
      sound=s1;
   }else if(r<200){
      sound=s2;
   }else if(r<300){
      sound=s3;
   }else if(r<400){
      sound=s4;
   }else if(r<500){
      sound=s5;
   }else if(r<600){
      sound=s6;
   }
   playSound("data/"+sound);
}
void playSound(void file)
{
   if(!file||file==""){return;}else{}
   int sfx=loadsample(file);
   playsample(sfx, 0, openborvariant("effectvol"), openborvariant("effectvol"), 100, 0);
}
 
Very helpful, thanks Beastie! Really wish I saw this sooner. Now I just need voices.

Time to lurk Mugen forums!
 
Back
Top Bottom