1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

Change resistant of an armor

Discussion in 'Development' started by Flupko, Jan 5, 2019.

  1. Flupko

    Flupko Silverfish

    Messages:
    24
    GitHub:
    Warex
    Hello, I would like to know if there is a way to make a armor more resistant? (Sorry for my english I'm french)
     
  2. Zach1603

    Zach1603 Spider Jockey

    Messages:
    27
    GitHub:
    zedstar16
    Add an unbreaking enchant to it?
     
  3. Flupko

    Flupko Silverfish

    Messages:
    24
    GitHub:
    Warex
    No I would like to change the resistance of the armor in itself without putting enchantments.
     
  4. Flupko

    Flupko Silverfish

    Messages:
    24
    GitHub:
    Warex
    I found a code but when I hit the player with a sword it makes the same number of hearts.
    Code :
    PHP:
                         $armor Item::get(30311);
                         if (
    $damager->getInventory()->getItemInHand() instanceof Sword) {
                            
    $event->setModifier(-($event->getFinalDamage() * 0.2 $armor->getLevel()));
                        }
     
  5. corytortoise

    corytortoise Skeleton

    Messages:
    825
    GitHub:
    corytortoise
    $armor->getLevel shouldn't be valid, because there is no level for items. $event->setModifier requires a parameter for the modifier value, and the modifier type. I'd suggest using 1 for armor. I'd do something like this:
    PHP:
      if ($damager->getInventory()->getItemInHand() instanceof Sword) {
        
    $event->setModifier(($event->getModifier(EntityDamageEvent::MODIFIER_ARMOR) * 1.2), 
    EntityDamageEvent::MODIFIER_ARMOR); //Should make armor 20% more effective.
        
    }
    I wouldn't use final damage, because that will have an affect on other modifiers, like potions and armor enchantments, which I don't think you intend.
     
    Last edited: Jan 6, 2019
    Flupko likes this.
  6. dktapps

    dktapps Administrator Staff Member PMMP Team

    Messages:
    774
    GitHub:
    dktapps
    please don't teach them to hardcode magic numbers... use the constants. https://github.com/pmmp/PocketMine-MP/blob/3.5/src/pocketmine/event/entity/EntityDamageEvent.php#L34
     
    corytortoise likes this.
  7. corytortoise

    corytortoise Skeleton

    Messages:
    825
    GitHub:
    corytortoise
  8. Flupko

    Flupko Silverfish

    Messages:
    24
    GitHub:
    Warex
    Thank you but is it also possible to modify the Defense Points?
     
  9. VincBros

    VincBros Silverfish

    Messages:
    19
    GitHub:
    vincbros
    I would like to know that too
     
  10. Zach1603

    Zach1603 Spider Jockey

    Messages:
    27
    GitHub:
    zedstar16
    You could create your own custom armor class that extends the default and has the properties you want
     
  11. VincBros

    VincBros Silverfish

    Messages:
    19
    GitHub:
    vincbros
    I have no idea how to do that. Could you help me there?
     
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.