Random sounds and remap questions

mersox

Active member
Hey guys, I'm having trouble in two areas:

1. Random sounds: I know this has been done before, but I'm having trouble finding examples. Basically I have different "swish" sounds and I want Openbor to play one of them randomly each time the characters performs a punch or kick.

2. Remap! I'm having trouble in this area. I have six different "map" sprites of one character and I want to use them when spawning them. I have been successful in using one remap (which means I have the same character in two different colors on screen) but that's it, when I want to add another one the program crashes.

Right now the character txt says:
remap data/chars/shermie/idle1.gif data/chars/shermie/map1.gif

and the level txt says:
spawn Shermie
map 1
alias putty
coords 350 220
at 15

If I add a "map 2" it all goes to hell. I think it's because I would have numerous "remap" commands in the char's file, so I tried numbering them like "remap2" and "remap 2" (with a space) but it didn't work. Ideas?
 
You know what? I'm scrapping the remap idea. After all, the recolored characters are in essence new chars so they will need their own txt. I'll use the palette trick.

I'm still lost regarding random sounds.
 
1)
Save this code as randsound.c and call it in your animationscript
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);
}

You will have two options - randSound and randSound2. The first use 3 files, the second uses 6 files.
usage:

@cmd randSound "sounds/voice1.wav" "sounds/voice2.wav" "sounds/voice3.wav"
(there is no "data" before the path, since its already included on the code)

or

@cmd randSound2 "sounds/voice1.wav" "sounds/voice2.wav" "sounds/voice3.wav" "sounds/voice4.wav" "sounds/voice5.wav" "sounds/voice6.wav"

2) you can try to use Palette and Alternatepal, is way easier
palette      data/chars/beast/id1.pcx
alternatepal  data/chars/beast/pal2.pcx
 
hmm im getting this error with it
Script compile error: can't find function 'randSound2'

Script compile error in 'animationscript': randSound2 line 49, column 12

********** An Error Occurred **********
*            Shutting Down            *

Can't compile script!
Total Ram: 4294967295 Bytes
Free Ram: 4294967295 Bytes
Used Ram: 30121984 Bytes

Release level data...........Level Unloading: 'data/levels/dangerroom.txt'
Total Ram: 4294967295 Bytes
Free Ram: 4294967295 Bytes
Used Ram: 30130176 Bytes

Done.
Total Ram: 4294967295 Bytes
Free Ram: 4294967295 Bytes
Used Ram: 30130176 Bytes

Done!
Release graphics data........ Done!
Release game data............

Unload 'Flash' ..................done.
Unload 'Flash2' ..................done.
Unload 'Flash3' ..................done.
Unload 'Flash4' ..................done.
Unload 'Flash5' ..................done.
Unload 'Flash6' ..................done.
Unload 'Flash7' ..................done.
Unload 'Cyclops' ..................done.
Unload 'Emma_Frost' ..................done.
Unload 'Armor' ..................done.
Unload 'arm' ..................done.
Unload 'Armor2' ..................done.
Unload 'crack' ..................done.
Unload 'transnn' ..................done.
Unload 'quakearm' ..................done.
Unload 'quakearm2' ..................done.
Unload 'tent' ..................done.
Unload 'armbio' ..................done.
Unload 'Cyclops2' ..................done.
Unload 'Emma2' ..................done.
Unload 'Beam' ..................done.
Unload 'InvisBeam' ..................done.
Unload 'InvisBeam2' ..................done.
Unload 'OpticBeam' ..................done.
Unload 'OpticBlast' ..................done.
Unload 'emat1' ..................done.
Unload 'emat2' ..................done.
Unload 'emat3' ..................done.
Unload 'psy' ..................done.
Unload 'emair1' ..................done.
Unload 'emair2' ..................done.
Unload 'riseatk' ..................done.
Unload 'throwfx' ..................done.
Unload 'spfx' ..................done.
Unload 'spcfx' ..................done.
Unload 'dsh' ..................done.
Unload 'dmdform' ..................done.
Unload 'eshot' ..................done.
Unload 'transn' ..................done.
Unload 'light' ..................done.
Unload 'cat' ..................done.
Unload 'Darkstar' ..................done.
Unload 'Dazzler' ..................done.
Unload 'Elixir' ..................done.
Unload 'Havok' ..................done.
Unload 'Iceman' ..................done.
Unload 'Namor' ..................done.
Unload 'Magma' ..................done.
Unload 'Polaris' ..................done.
Unload 'SunSpot' ..................done.
Unload 'Surge' ..................done.
Unload 'X23' ..................done.
Unload 'DarkBeam' ..................done.
Unload 'DazzSpark' ..................done.
Unload 'Dolphin' ..................done.
Unload 'HealFX' ..................done.
Unload 'Ice' ..................done.
Unload 'MagmaRain' ..................done.
Unload 'HavPlasma' ..................done.
Unload 'SeaWater' ..................done.
Unload 'SunBlast' ..................done.
Unload 'XSlash' ..................done.
Unload 'Xplos' ..................done.
Unload 'pain7' ..................done.
Unload 'ReactFX' ..................done.
Unload 'ReactFX1' ..................done.
Unload 'ReactFX2' ..................done.
Unload 'Empty' ..................done.
Unload 'DangerLight' ..................done.
Unload 'DangerPlat' ..................done.
Unload 'X' ..................done.
Unload 'SGunPur' ..................done.
Unload 'GunShot' ..................done.
Unload 'Grenade' ..................done.
Unload 'ShockShot' ..................done.
Unload 'IceShot' ..................done.
Unload 'GunPur3' ..................done.
Unload 'MalePur1' ..................done.
Unload 'GunPur1' ..................done.
Unload 'FemPur3' ..................done.
Unload 'StroPur' ..................done.
Unload 'GunPur2' ..................done.
Unload 'FemPur2' ..................done.
Unload 'StroPur3' ..................done.
Unload 'FemPur' ..................done.
Unload 'StroPur2' ..................done.
Unload 'Sentinel' ..................done.
Unload 'slaser' ..................done.
Unload 'slaser2' ..................done.
Unload 'sdie' ..................done.
Unload 'sdust' ..................done.
Unload 'sdust2' ..................done.
Unload 'sgren' ..................done.
Unload 'ssmoke' ..................done.

Release game data............ Done!
Release timer................ Done!
Release input hardware....... Done!
Release sound system......... Done!
Release FileCaching System... Done!

**************** Done *****************

Can't compile script!
 
I keep certain characters sounds in a folder in the character folders can I just write the path while calling the script or will it only work if they're stored in the sounds folder?
 
You can, cause the function to load SFX accepts path from data folder. Here's an example:

Code:
int SFX = loadsample("data/sounds/clang.wav");

As you can see, the path is data/sounds/clang.wav. You can change it to data/chars/hero/sounds/clang.wav if you'd like
Though, if you do that, your function will be very specific and you might ended up having multiple functions which do the same.
 
Back
Top Bottom