Author Topic: Detecting when player is damaged/health increases  (Read 2502 times)

/title
I also need to get the value of the damage/health increased.

I don't think there's a default way of making it detect when your heath increases, but there's a way to tell if it goes down.

Found it.
Code: [Select]
armor::onDamage

Code: [Select]
function standardPlayerArmor::damage(%data, %obj, %sourceObject, %position, %damage, %damageType)
{
   if(%damage > 0)
   {
         announce("Damaged");
   }
   else
   {
        announce("Healed");
   }
   parent::damage(%data, %obj, %sourceObject, %position, %damage, %damageType);
}

That only works if their health goes down, though


-snip-

This is an incredibly bad way to do it. If any other add-on uses this method, they will be incompatible. And this will only work if the player is using the standard player datablock, which for most practical uses, they will not be.

The correct way to do this would be to package armor::damage(%data, %obj, %sourceObject, %position, %damage, %damageType) so that it is fully compatible and works for all player types.

If you are making your own custom playertype datablock, and you only want this script to work for that datablock, then you can use yourDatablock::damage( ... ) as you know that nobody will be overwriting it.

Either way you should be calling parent::damage( ... ) so that the base damage script (and all other scripts packaging armor::damage( ... ) ) is called.

This is an incredibly bad way to do it.
This seems harsh to the point of misleading when the only changes needed are to put it in a package and change the datablock to armor

The medipack (which I have just hastily found in an RTB archive) uses setDamageLevel to heal (setting damage level lower means more health) so onDamage wouldn't pick that up. And HealthPickups (same place) uses addHealth. Oh dear...

I suppose if you could figure out all the different ways health can be changed, you could parent all of them and have them do the same thing.
« Last Edit: November 18, 2015, 07:16:44 PM by Teneksi »

This seems harsh to the point of misleading when the only changes needed are to put it in a package and change the datablock to armor
How is this harsh? And he explained what you said, he's just trying to explain how you should package stuff. Not everyone knows how to script stuff properly because they are learning.

Uh.. medipacks have been using addhealth not setdamagelevel

It does find the health by getdamagelevel, though
« Last Edit: November 18, 2015, 11:40:50 PM by Kyuande »

How is this harsh? And he explained what you said, he's just trying to explain how you should package stuff. Not everyone knows how to script stuff properly because they are learning.

Uh.. medipacks have been using addhealth not setdamagelevel

It does find the health by getdamagelevel, though
Calling something an "incredibly bad way to do it" when it only has a couple quickly-fixed errors is misleading, especially for people who are learning because they think the whole thing must be crap when in fact you have to add a tiny amount of things to make it work properly

I know what I read. Do you think I just make stuff up?

Code: [Select]
package gc_Medipack
{
  function Armor::onCollision(%this,%obj,%col,%a,%b,%c,%d,%e,%f)
  {
    if(%col.dataBlock $= "gc_HealthPickupItem" && %col.canPickup && %obj.getDamagePercent() < 1 && minigameCstar fishe(%obj.client,%col))
    {
      if(%obj.getDamageLevel() > 0)
      {
        cancel(%obj.gc_bleed);
        %obj.setDamageFlash(0);
        %obj.setDamageLevel(%obj.getDamageLevel()-$GCStuff::HealthPickup);
        serverPlay3D(gc_MediPackUseSound,%obj.getTransform());
        if(isObject(%col.spawnBrick))
        {
          %col.fadeOut();
          %col.schedule(%col.spawnBrick.itemRespawnTime,fadein);
        }
        else
          %col.schedule(10,delete);
      }
      return;
    }
    parent::onCollision(%this,%obj,%col,%a,%b,%c,%d,%e,%f);
  }
};
activatePackage(gc_Medipack);

Calling something an "incredibly bad way to do it" when it only has a couple quickly-fixed errors is misleading, especially for people who are learning because they think the whole thing must be crap when in fact you have to add a tiny amount of things to make it work properly

I get what you're saying, but minor differences in coding can mean very different things all the time. I was exaggerating it to make sure that new coders don't think "its only a couple of lines difference, i'm sure it'll be fine". Ideally Path would edit his post and fix it, and then i'll edit mine to avoid confusion, but I cant control that.

I know what I read. Do you think I just make stuff up?

Code: [Select]
package gc_Medipack
{
  function Armor::onCollision(%this,%obj,%col,%a,%b,%c,%d,%e,%f)
  {
    if(%col.dataBlock $= "gc_HealthPickupItem" && %col.canPickup && %obj.getDamagePercent() < 1 && minigameCstar fishe(%obj.client,%col))
    {
      if(%obj.getDamageLevel() > 0)
      {
        cancel(%obj.gc_bleed);
        %obj.setDamageFlash(0);
        %obj.setDamageLevel(%obj.getDamageLevel()-$GCStuff::HealthPickup);
        serverPlay3D(gc_MediPackUseSound,%obj.getTransform());
        if(isObject(%col.spawnBrick))
        {
          %col.fadeOut();
          %col.schedule(%col.spawnBrick.itemRespawnTime,fadein);
        }
        else
          %col.schedule(10,delete);
      }
      return;
    }
    parent::onCollision(%this,%obj,%col,%a,%b,%c,%d,%e,%f);
  }
};
activatePackage(gc_Medipack);
Holy stuff calm down, I can't read your mind

I was thinking of the TF2 medipack

Holy stuff calm down, I can't read your mind
But you can read what I type.


Understandable

but
The medipack (which I have just hastily found in an RTB archive) uses setDamageLevel to heal (setting damage level lower means more health)
I even explain what it's doing; how it lowers your damage level in order to give more health. "Setting damage level lower" is definitely not a description of getDamageLevel or of addHealth. Regardless of what medipack you thought I meant, how or why would I be describing setDamageLevel if it didn't exist?

but seriously, I'm not as annoyed as I might sound, (communicating through text, hooray: add one word of profanity to make an honest question sound furious) I just get a bit peeved with this sort of thing