Author Topic: SetHealth/AddHealth not working correctly (Solved)  (Read 1546 times)

My project is here: http://forum.blockland.us/index.php?topic=262818.0

For some reason it no longer works, the weird thing is that if you add the health below 0 it will work, but adding the health will not work (only occurs using the fake health).

Same for setHealth, it doesn't set the health correctly; not using the fake health it works fine; but when using it, it doesn't set it correctly. I wonder why.

Yes, this is in a package. I even tried using it without the package.
function ShapeBase::setHealth(%this,%health)
   {
      talk("setHealth, is it even being called?");
      if(!isObject(%this))
         return false;
      if(!strLen(%health))
         return false;
      if(%this.maxHealth <= 0)
         {Parent::setHealth(%this,%health);return;}
      if(%health < 0)
      {
         %health = 0;
         %this.health = 0;
         %this.damage(%this,%this.getHackPosition(),%this.getDataBlock().maxDamage*%this.getSize(),$DamageType::Default,"body",true);
         return;
      }
      if(%health > %this.getMaxHealth())
         %health = %this.getMaxHealth();
      %this.health = %health;
      %this.setDamageLevel(%this.getHealthLevel());
      return true;
   }

   function ShapeBase::AddHealth(%this,%health)
   {
      talk("addHealth, is it even being called?");
      if(!isObject(%this))
         return false;
      if(%this.maxHealth <= 0)
         {Parent::AddHealth(%this,%health);return;}
      if(%this.health > 0)
      {
         if(%health < 0)
            %this.damage(%this,%this.getHackPosition(),mAbs(%health),$DamageType::Default,"body",false);
         else
            %this.setHealth(%this.getHealth() + %health);
      }
      if(%this.health < 0)
      {
         %this.health = 0;
         %this.damage(%last,%this.getHackPosition(),%this.getMaxHealth()*%this.getSize(),%damageType,"body",true);
      }
   }


Purple was in there to test if it gets called, it doesn't seem to, even though I called it through events/eval.
« Last Edit: July 19, 2014, 05:48:51 PM by Advanced Bot »

the default setHealth/addHealth events use the "Player" namespace instead of "ShapeBase", try changing it to Player::?

the default setHealth/addHealth events use the "Player" namespace instead of "ShapeBase", try changing it to Player::?
That's odd, everything works though now. Thanks.

Added it to my mod as well, using:
Player
AIPlayer
Vehicle
WheeledVehicle
« Last Edit: July 19, 2014, 05:56:31 PM by Advanced Bot »