Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Getting and setting damage

Comments in 'Plugin Development' started by minebuilder0110, Feb 15, 2016.

  1. minebuilder0110
    Offline

    minebuilder0110 Notable Member

    Joined:
    Dec 8, 2014
    Posts:
    485
    Minecraft User:
    Apparitional
    I have been making a plugin where the armours actually work (blocking damages etc), but using getDamage() and setDamage() doesn't seems to work. Are those the correct functions? If they are, the are they broken or something?
    PHP:
    $victim $event->getEntity();
            
    $inv $victim->getInventory();
            
    $helmet $inv->getHelmet()->getID();
            
    $chestplate $inv->getChestplate()->getID();
            
    $leggings $inv->getLeggings()->getID();
            
    $boots $inv->getBoots()->getID();
            
    $damage $event->getDamage();
            
    $cause $event->getCause();
    Also, the plugins is keeping on giving me the error on getInventory() function being undefined, but not crashing. I did use pocketmine\inventory\PlayerInventory;, so I don't understand why this error is happening.
  2. AndrewBit
    Offline

    AndrewBit Notable Member

    Joined:
    Jun 18, 2015
    Posts:
    435
    Minecraft User:
    AndrewBit4
    An entity is always a player? I think that no.
    Has a pig an inventory?
  3. minebuilder0110
    Offline

    minebuilder0110 Notable Member

    Joined:
    Dec 8, 2014
    Posts:
    485
    Minecraft User:
    Apparitional
    1. Does that ever look like a full code? That is not even a full function.
    2. If I was talking about armours and inventory, I would obviously test it on myself, not on a pig/zombie/etc.
  4. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Armor does work. Please look at the second parameter of EntityDamageEvent->setDamage.

    Also, these fixes should be done in PocketMine itself. Feel free to create pull requests to fix them.
  5. minebuilder0110
    Offline

    minebuilder0110 Notable Member

    Joined:
    Dec 8, 2014
    Posts:
    485
    Minecraft User:
    Apparitional
    Oh god, I was quite curious on what you were saying when I saw the reply thought the EMail :p
    Anyway, I was creating a plugin that was meant to check people's armour upon damage, calculate the damage and set the correct damage. However, after adding lots of debug messages, the getDamage() seems to give me 1 all the time, and setDamage() didn't work. So that's why I created this thread, just in case these functions are broken like setHealth().
    I may make PR if I both find out how to create one and when I make a working way to do it. :oops:
  6. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Yes, health has problems. I have a pull request that fixes it.
  7. minebuilder0110
    Offline

    minebuilder0110 Notable Member

    Joined:
    Dec 8, 2014
    Posts:
    485
    Minecraft User:
    Apparitional
    Kind of off topic, but does anyone know how to calculate the damage dealt for every armour points? I can't understand the formula on the Minecraft Wiki.
  8. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    applqpak likes this.
  9. minebuilder0110
    Offline

    minebuilder0110 Notable Member

    Joined:
    Dec 8, 2014
    Posts:
    485
    Minecraft User:
    Apparitional
    Is the setDamage function broken, or did I use it incorrectly? I have written:
    PHP:
    $event->setDamage($newdamage$cause);
    where $newdamage is the new damage that should be dealt. However, the damage is not dealt.
  10. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    There are other modifiers. The second parameter is the modifier, not cause.
    EntityDamageEvent is composed of multiple damage modifiers. One is the MODIFIER_BASE, which is the normal damage. Other common ones include MODIFIER_ARMOR, MODIFIER_RESISTANCE, etc. Refer to EntityDamageEvent.php for these constants.
    The final damage dealt to the player is the sum of all modifiers.
  11. minebuilder0110
    Offline

    minebuilder0110 Notable Member

    Joined:
    Dec 8, 2014
    Posts:
    485
    Minecraft User:
    Apparitional
    Okay, I have fixed the code, but it still doesn't affect it at all. I tried to dive into lava with full set of diamond set and still deals 4 health points of damage, despite the fact that I have made a debug message to send message to the victim, and it clearly said I would only receive 1 health point of damage. Instead, I just get killed almost instantly. Is it that setDamage() just damages the player additionally during the event?
  12. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    If you want to reduce the damage, the modifier should be negative.

    Use $event->getFinalDamage() to see the final damage you will be dealing.
    minebuilder0110 likes this.

Share This Page

Advertisement