• All, Gmail is currently rejecting messages from my host. I have a ticket in process, but it may take some time to resolve. Until further notice, do NOT use Gmail for your accounts. You will be unable to receive confirmations and two factor messages to login.
Custom Sounds For Collecting Items

[SCRIPT] Custom sounds for picking itens + animations

Hey O'Ill, now that I see specifically what you are doing, let me give you a tip.

For purposes of debugging and readability, it is generally best to use variables to store results, and then do the work outside of your Switch or If blocks. Like this...

C:
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/power-up.wav"); // load samples
   int SFX2 = loadsample("data/sounds/life-up.wav");
   int SFX3 = loadsample("data/sounds/full-power.wav");
   int SFX4 = loadsample("data/sounds/full-life.wav");
   int SFX5 = loadsample("data/sounds/power-life.wav");
  
   switch(Name) { // check the item name
      case "iMP" : // power up
        sample = SFX1;                
        break;
     
      case "iHP" :  // life up
      case "cola" : // life up
        sample      = SFX2;
        animation   = openborconstant("ANI_IDLE");
        break;
     
      case "iFMP" : // full power up
        sample      = SFX3;
        animation   = openborconstant("ANI_FOLLOW4");        
        break;
     
      case "iFHP" : // full life up
        sample      = SFX4;
        animation   = openborconstant("ANI_FOLLOW3");        
        break;
     
      case "iHPMP" : // life and power up
        changeentityproperty(hit, "mp", power+30);  // add 30 to entity power
        sample      = SFX5;
        animation   = openborconstant("ANI_FOLLOW2");        
        break;
     
      default : // in case of none of above
        break;
   }
  
   spawnAni("aitemFX",0,30,0,animation,NULL(),NULL(),NULL());
   playsample(sample, 0, 120, 120, 100, 0);
}

Also note I replaced the animation string with openborconstant. It's ALWAYS better to pass integers and constants instead of strings whenever possible. I fixed my old function that you modified to reflect this, and also added openborconstant("DIRECTION_LEFT"), supported as of version 4191. See here:

C:
void spawnAni(void vName, float fX, float fY, float fZ, int animation, float Vx, float Vy, float Vz)
{
   //spawnB (Generic spawner) + Specific animation + velocities
   //Damon Vaughn Caskey + Douglas Baldan
   //07/06/2007
   //
   //Spawns entity next to caller.
   //
   //vName: Model name of entity to be spawned in.
   //fX: X location adjustment.
   //fZ: Y location adjustment.
      //fY: Z location adjustment.

   void self = getlocalvar("self"); //Get calling entity.
   void vSpawn; //Spawn object.
   int  iDirection = getentityproperty(self, "direction");

   clearspawnentry(); //Clear current spawn entry.
      setspawnentry("name", vName); //Acquire spawn entity by name.

   // Entity facing left?
   if (iDirection == openborconstant("DIRECTION_LEFT"))
   {                 
          fX = -fX; //Reverse X direction to match facing.
   }

      fX = fX + getentityproperty(self, "x"); //Get X location and add adjustment.
      fY = fY + getentityproperty(self, "a"); //Get Y location and add adjustment.
      fZ = fZ + getentityproperty(self, "z"); //Get Z location and add adjustment.
  
   vSpawn = spawn(); //Spawn in entity.

   changeentityproperty(vSpawn, "position", fX, fZ, fY); //Set spawn location.
   changeentityproperty(vSpawn, "direction", iDirection); //Set direction.
   performattack(vSpawn, animation);
   changeentityproperty(vSpawn, "velocity", Vx, Vy, Vz);

   return vSpawn; //Return spawn.  
}
 
That one is easy. Strings occupy more space in memory, though that's really negligible. The big advantage integers have over strings is that integers are a single comparison, whereas strings require the CPU to check character by character.

Strings are not "bad", but no matter what language you are using, numeric types will always be faster and usually smaller too. It's therefore accepted best practice to save strings for things only they can do (messages to the user, text read outs, etc.) and stick with integers whenever possible for logic.

DC
 
Dc, your version crashes the engine.
This is the log:

Can't translate constant <VT_EMPTY>  Unitialized
Script function 'openborconstant' returned an exception, check the manual for details.
parameters: <VT_EMPTY>  Unitialized, 
 
Moved tutorial to Resources and updated tags to use new forum's code blocks. Associated with this discussion thread.

DC
 
Back
Top Bottom