Custom Sounds for Items

Hello  :)
Try using this tutorial to customize a different sound for each item. http://www.chronocrash.com/forum/index.php?topic=3115.0

It works, but all the samples sound at the same time with all the Items
This is the script, can someone help me see if I did something wrong? I'm still a beginner at scripts.

Code:
void main(){
   // Custom sounds for picking itens
   // Douglas Baldan / O Ilusionista - 11/12/2016
   // Thanks Damon Caskey for the support
   
   void self = getlocalvar("self"); //get the self var
   void hit = getlocalvar("damagetaker"); // get target entity
   char Name = getentityproperty(self,"name"); // get target's name
   void power = getentityproperty(hit,"mp"); // get target's current mp
   
   int  sample;     // Sample to play.
   int  animation;  // Animation to apply.
   
   int SFX1 = loadsample("data/sounds/SFXNck/SFXkaiRisa.wav"); // load samples
   int SFX2 = loadsample("data/sounds/SFXNck/Select1Up1.wav"); // load samples
   int SFX3 = loadsample("data/sounds/SFXNck/Select1Up3.wav"); // load samples
   int SFX4 = loadsample("data/sounds/SFXNck/Select1Up3.wav"); // load samples
   int SFX5 = loadsample("data/sounds/SFXNck/Select1Up4.wav"); // load samples
   
   switch(Name) { // check the item name
      case "ItKaty" : // power up, Item del arma
        sample = SFX1;		
        break;

      case "ItMone" : // power up, Item del arma
        sample = SFX2;	
        break;

      case "ItVerte" : // power up, Item del arma
        sample = SFX3;		
        break;

      case "ItRodo" : // power up, Item del arma
        sample = SFX4;		
        break;

      case "ItNath" : // power up, Item del arma
        sample = SFX5;		
        break;		
     
     
      default : // in case of none of above
        break;
   }
   
     //spawnAni("tomalo",0,30,0,"ANI_IDLE",NULL(),NULL(),NULL());
     playsample(SFX1, 0, 120, 120, 100, 0);
     playsample(SFX2, 0, 120, 120, 100, 0);
     playsample(SFX3, 0, 120, 120, 100, 0);
     playsample(SFX4, 0, 120, 120, 100, 0);
     playsample(SFX5, 0, 120, 120, 100, 0);
}

Thanks =)
 
Hello :)

The error of your script are these lines:
Code:
     playsample(SFX1, 0, 120, 120, 100, 0);
     playsample(SFX2, 0, 120, 120, 100, 0);
     playsample(SFX3, 0, 120, 120, 100, 0);
     playsample(SFX4, 0, 120, 120, 100, 0);
     playsample(SFX5, 0, 120, 120, 100, 0);

They simply mean all SFXs are played at once.

I believe you actually meant to use just one line like this:
Code:
playsample(sample, 0, 120, 120, 100, 0);

However, this might cause problem when default condition applies in which no SFX is defined.
I suggest defining default SFX for default condition like this.
Code:
void main(){
   // Custom sounds for picking itens
   // Douglas Baldan / O Ilusionista - 11/12/2016
   // Thanks Damon Caskey for the support
   
   void self = getlocalvar("self"); //get the self var
   void hit = getlocalvar("damagetaker"); // get target entity
   char Name = getentityproperty(self,"name"); // get target's name
   void power = getentityproperty(hit,"mp"); // get target's current mp
   
   int  sample;     // Sample to play.
   int  animation;  // Animation to apply.
   
   int SFX1 = loadsample("data/sounds/SFXNck/SFXkaiRisa.wav"); // load samples
   int SFX2 = loadsample("data/sounds/SFXNck/Select1Up1.wav"); // load samples
   int SFX3 = loadsample("data/sounds/SFXNck/Select1Up3.wav"); // load samples
   int SFX4 = loadsample("data/sounds/SFXNck/Select1Up3.wav"); // load samples
   int SFX5 = loadsample("data/sounds/SFXNck/Select1Up4.wav"); // load samples
   
   switch(Name) { // check the item name
      case "ItKaty" : // power up, Item del arma
        sample = SFX1;		
        break;

      case "ItMone" : // power up, Item del arma
        sample = SFX2;	
        break;

      case "ItVerte" : // power up, Item del arma
        sample = SFX3;		
        break;

      case "ItRodo" : // power up, Item del arma
        sample = SFX4;		
        break;

      case "ItNath" : // power up, Item del arma
        sample = SFX5;		
        break;		
     
     
      default : // in case of none of above
        sample = loadsample("data/sounds/money.wav"); // default SFX
        break;
   }
   
     //spawnAni("tomalo",0,30,0,"ANI_IDLE",NULL(),NULL(),NULL());
     playsample(sample, 0, 120, 120, 100, 0);
}

HTH
 
dont load samples and play them i same script , you will see screen stutterand load sound, looks bad, load sounds in first entity in level script and play them later in other script
Code:
spawn  spawner
@script void main() {
	void sa1 =  loadsample("data/chars/boulic/at.wav");
	void sa2 =  loadsample("data/chars/boulic/at2.wav");
        void sa3 =  loadsample("data/chars/boulic/at3.wav");
	void sa4 =  loadsample("data/chars/boulic/at4.wav");
	void sam1 =  loadsample("data/chars/boulic/dead.wav");
   	void sam2 =  loadsample("data/chars/boulic/dead2.wav");
        void sam3 =  loadsample("data/chars/boulic/dead3.wav");
	void sam4 =  loadsample("data/chars/boulic/dead4.wav");
	void tra =  loadsprite("data/sprites/step3.gif");
} @end_script
coords 620 492
at 0
This will load all samples on level start, and you wont see stutter later
 
Bloodbane said:
Hello :)

The error of your script are these lines:
Code:
     playsample(SFX1, 0, 120, 120, 100, 0);
     playsample(SFX2, 0, 120, 120, 100, 0);
     playsample(SFX3, 0, 120, 120, 100, 0);
     playsample(SFX4, 0, 120, 120, 100, 0);
     playsample(SFX5, 0, 120, 120, 100, 0);

They simply mean all SFXs are played at once.

I believe you actually meant to use just one line like this:
Code:
playsample(sample, 0, 120, 120, 100, 0);

However, this might cause problem when default condition applies in which no SFX is defined.
I suggest defining default SFX for default condition like this.
Code:
void main(){
   // Custom sounds for picking itens
   // Douglas Baldan / O Ilusionista - 11/12/2016
   // Thanks Damon Caskey for the support
   
   void self = getlocalvar("self"); //get the self var
   void hit = getlocalvar("damagetaker"); // get target entity
   char Name = getentityproperty(self,"name"); // get target's name
   void power = getentityproperty(hit,"mp"); // get target's current mp
   
   int  sample;     // Sample to play.
   int  animation;  // Animation to apply.
   
   int SFX1 = loadsample("data/sounds/SFXNck/SFXkaiRisa.wav"); // load samples
   int SFX2 = loadsample("data/sounds/SFXNck/Select1Up1.wav"); // load samples
   int SFX3 = loadsample("data/sounds/SFXNck/Select1Up3.wav"); // load samples
   int SFX4 = loadsample("data/sounds/SFXNck/Select1Up3.wav"); // load samples
   int SFX5 = loadsample("data/sounds/SFXNck/Select1Up4.wav"); // load samples
   
   switch(Name) { // check the item name
      case "ItKaty" : // power up, Item del arma
        sample = SFX1;		
        break;

      case "ItMone" : // power up, Item del arma
        sample = SFX2;	
        break;

      case "ItVerte" : // power up, Item del arma
        sample = SFX3;		
        break;

      case "ItRodo" : // power up, Item del arma
        sample = SFX4;		
        break;

      case "ItNath" : // power up, Item del arma
        sample = SFX5;		
        break;		
     
     
      default : // in case of none of above
        sample = loadsample("data/sounds/money.wav"); // default SFX
        break;
   }
   
     //spawnAni("tomalo",0,30,0,"ANI_IDLE",NULL(),NULL(),NULL());
     playsample(sample, 0, 120, 120, 100, 0);
}

HTH
Thank you very much for the help
I did the test with your code settings, but for some reason, I have only been able to make the sound of 1 item work, the rest play the Default sound.
I tried exchanging the items, but only "ItNath" works good.
I have not been able to figure out the reason why only that one works, the rest of the items are very similar and I already checked them.

This is a sample for my Items
Code:
name      ItMone
type      item
subtype  weapon project
weapnum 3
health		0
gfxshadow 1
setlayer 7
icon   data\chars\enemigos\IconsITN10.gif 0
#propiedades del arma
shootnum 1  #numero de tiros
counter 1
#typeshot 0


didhitscript data/scripts/didhit/item.c   #Script

anim spawn
    loop 0	   
	   delay     5
       offset    34 138
       move -5	   
	   frame data\chars\misc\items\ItMone.gif	   
       offset    34 143			   
	   frame data\chars\misc\items\ItMone.gif
       offset    34 153	   
	   frame data\chars\misc\items\ItMone.gif
       offset    34 163			   
	   frame data\chars\misc\items\ItMone.gif
       offset    34 164	   
	   frame data\chars\misc\items\ItMone.gif
       offset    34 165	   
	   frame data\chars\misc\items\ItMone.gif
       offset    34 166	   
	   frame data\chars\misc\items\ItMone.gif
       offset    34 165		   
	   frame data\chars\misc\items\ItMone.gif
       offset    34 160			   
	   frame data\chars\misc\items\ItMone.gif
       offset    34 145		   
	   frame data\chars\misc\items\ItMone.gif
       offset    34 110			   
	   frame data\chars\misc\items\ItMone.gif
       offset    34 80			   
	   frame data\chars\misc\items\ItMone.gif
       offset    34 63
SOUND data\sounds\SFXNck\sfxItem4It.wav	   
	   frame data\chars\misc\items\ItMone.gif
       offset    34 73	   
	   frame data\chars\misc\items\ItMone.gif
       move -4	   
       offset    34 75		   
	   frame data\chars\misc\items\ItMone.gif
       offset    34 76		   
	   frame data\chars\misc\items\ItMone.gif
       offset    34 75		   
	   frame data\chars\misc\items\ItMone.gif
       offset    34 70		   
	   frame data\chars\misc\items\ItMone.gif
       offset    34 63
SOUND data\sounds\SFXNck\sfxItem4It.wav	   
	   frame data\chars\misc\items\ItMone.gif
       offset    34 65	   
	   frame data\chars\misc\items\ItMone.gif
	   move -2
       offset    34 66	   
	   frame data\chars\misc\items\ItMone.gif
       offset    34 65	   
	   frame data\chars\misc\items\ItMone.gif
       offset    34 63
SOUND data\sounds\SFXNck\sfxItem4It.wav	   
	   frame data\chars\misc\items\ItMone.gif
       offset    34 63	   
	   frame data\chars\misc\items\ItMone.gif

anim idle

	   loop      1 
	   offset    34 63	
 @cmd projectile 1 "coger" -18 0 68 1 1     ### INDICACIÓN	   
	   #sound data\sounds\SFXNck\Hurt1Ligh1.wav
       #bbox 11 5 50 67
       itembox 11 120 50 6
	   delay     80
       drawmethod 256 256 0 0 0 0 0 0 0 0 	   
	   frame data\chars\misc\items\ItMone.gif
	   delay     10
	   drawmethod 256 256 0 0 0 0 0 -1 0 0 	   
	   frame data\chars\misc\items\ItMone.gif
	   delay     80
       drawmethod 256 256 0 0 0 0 0 0 0 0 	   
	   frame data\chars\misc\items\ItMone.gif
	   delay     10
	   drawmethod 256 256 0 0 0 0 0 -1 0 0 	   
	   frame data\chars\misc\items\ItMone.gif
	   delay     80
       drawmethod 256 256 0 0 0 0 0 0 0 0 	   
	   frame data\chars\misc\items\ItMone.gif
	   delay     10
	   drawmethod 256 256 0 0 0 0 0 -1 0 0 	   
	   frame data\chars\misc\items\ItMone.gif	 

Thanks :D
 
bWWd said:
dont load samples and play them i same script , you will see screen stutterand load sound, looks bad, load sounds in first entity in level script and play them later in other script
Code:
spawn  spawner
@script void main() {
	void sa1 =  loadsample("data/chars/boulic/at.wav");
	void sa2 =  loadsample("data/chars/boulic/at2.wav");
        void sa3 =  loadsample("data/chars/boulic/at3.wav");
	void sa4 =  loadsample("data/chars/boulic/at4.wav");
	void sam1 =  loadsample("data/chars/boulic/dead.wav");
   	void sam2 =  loadsample("data/chars/boulic/dead2.wav");
        void sam3 =  loadsample("data/chars/boulic/dead3.wav");
	void sam4 =  loadsample("data/chars/boulic/dead4.wav");
	void tra =  loadsprite("data/sprites/step3.gif");
} @end_script
coords 620 492
at 0
This will load all samples on level start, and you wont see stutter later

Hey, this looks very useful, thank you very much, I'll give it a try.
 
Kalcetin Studio said:
Thank you very much, I think I found a solution by creating a different script for each Item.

But by doing that, you defeat the whole propose of the script.

As BB explained, the script is playing the same sound because you are telling it to.
The playsample was placed on the wrong position - it should be used on each CASE.
And you are missing some samples there, like SFX4 and SFX5

So it should be this:

Code:
void main(){
   // Custom sounds for picking itens
   // Douglas Baldan / O Ilusionista - 11/12/2016
   // Thanks Damon Caskey for the support
   
   void self = getlocalvar("self"); //get the self var
   void hit = getlocalvar("damagetaker"); // get target entity
   char Name = getentityproperty(self,"name"); // get target's name
   void power = getentityproperty(hit,"mp"); // get target's current mp
   
   int  sample;     // Sample to play.
   int  animation;  // Animation to apply.
   
   int SFX1 = loadsample("data/sounds/SFXNck/SFXkaiRisa.wav"); // load samples
   int SFX2 = loadsample("data/sounds/SFXNck/Select1Up1.wav"); // load samples
   int SFX3 = loadsample("data/sounds/SFXNck/Select1Up3.wav"); // load samples
   int SFX4 = loadsample("data/sounds/SFXNck/Select1Up3.wav"); // load samples
   int SFX5 = loadsample("data/sounds/SFXNck/Select1Up4.wav"); // load samples
   
   switch(Name) { // check the item name
      case "ItKaty" : // power up, Item del arma
        sample = SFX1;	
        playsample(sample, 0, 120, 120, 100, 0);	
        break;

      case "ItMone" : // power up, Item del arma
        sample = SFX2;
        playsample(sample, 0, 120, 120, 100, 0);	
        break;

      case "ItVerte" : // power up, Item del arma
        sample = SFX3;
        playsample(sample, 0, 120, 120, 100, 0);		
        break;

      case "ItRodo" : // power up, Item del arma
        sample = SFX4;
        playsample(sample, 0, 120, 120, 100, 0);	
        break;

      case "ItNath" : // power up, Item del arma
        sample = SFX5;
        playsample(sample, 0, 120, 120, 100, 0);	
        break;		
     
     
      default : // in case of none of above
        break;
   }
}

Remember scripts are case sensitive. So the entity should be called "ItNath", exactly how you call it on the script
 
O_Ilusionista said:
Kalcetin Studio said:
Thank you very much, I think I found a solution by creating a different script for each Item.

But by doing that, you defeat the whole propose of the script.

As BB explained, the script is playing the same sound because you are telling it to.
The playsample was placed on the wrong position - it should be used on each CASE.
And you are missing some samples there, like SFX4 and SFX5

So it should be this:

Code:
void main(){
   // Custom sounds for picking itens
   // Douglas Baldan / O Ilusionista - 11/12/2016
   // Thanks Damon Caskey for the support
   
   void self = getlocalvar("self"); //get the self var
   void hit = getlocalvar("damagetaker"); // get target entity
   char Name = getentityproperty(self,"name"); // get target's name
   void power = getentityproperty(hit,"mp"); // get target's current mp
   
   int  sample;     // Sample to play.
   int  animation;  // Animation to apply.
   
   int SFX1 = loadsample("data/sounds/SFXNck/SFXkaiRisa.wav"); // load samples
   int SFX2 = loadsample("data/sounds/SFXNck/Select1Up1.wav"); // load samples
   int SFX3 = loadsample("data/sounds/SFXNck/Select1Up3.wav"); // load samples
   int SFX4 = loadsample("data/sounds/SFXNck/Select1Up3.wav"); // load samples
   int SFX5 = loadsample("data/sounds/SFXNck/Select1Up4.wav"); // load samples
   
   switch(Name) { // check the item name
      case "ItKaty" : // power up, Item del arma
        sample = SFX1;	
        playsample(sample, 0, 120, 120, 100, 0);	
        break;

      case "ItMone" : // power up, Item del arma
        sample = SFX2;
        playsample(sample, 0, 120, 120, 100, 0);	
        break;

      case "ItVerte" : // power up, Item del arma
        sample = SFX3;
        playsample(sample, 0, 120, 120, 100, 0);		
        break;

      case "ItRodo" : // power up, Item del arma
        sample = SFX4;
        playsample(sample, 0, 120, 120, 100, 0);	
        break;

      case "ItNath" : // power up, Item del arma
        sample = SFX5;
        playsample(sample, 0, 120, 120, 100, 0);	
        break;		
     
     
      default : // in case of none of above
        break;
   }
}

Remember scripts are case sensitive. So the entity should be called "ItNath", exactly how you call it on the script

Hello and thanks for helping me, I tested the code, check the names (copy-paste) unfortunately the same problem occurs, only ItNath works. I tried cloning that entity with another name (to see if any of its attributes were the problem) and it doesn't work either.
Maybe I'm just unlucky.
I really appreciate your help.

 
Back
Top Bottom