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

Add damage to an item like bone

Discussion in 'Development' started by Oniii-Chan, Dec 31, 2017.

  1. Oniii-Chan

    Oniii-Chan Witch

    Messages:
    66
    GitHub:
    Vincent583
    Hi guys
    I post this thread for anyone can can help me to add custom damage to an item in the src src of pmmp ?
     
  2. Oniii-Chan

    Oniii-Chan Witch

    Messages:
    66
    GitHub:
    Vincent583
    Can anyone help me ?
     
  3. armagadon159753

    armagadon159753 Zombie

    Messages:
    217
    GitHub:
    armagadon159753
    Which items to you want to midify dommage ?
     
  4. GamakCZ

    GamakCZ Zombie Pigman

    Messages:
    598
    GitHub:
    GamakCZ
    use EntityDamageEvent

    PHP:
    public function onDamage(\pocketmine\event\entity\EntityDamageEvent $event) {
            
    /** @var float $customDamage */
            
    $customDamage 2.6;
            
            
    $entity $event->getEntity();
            if(
    $entity instanceof \pocketmine\Player && $event instanceof \pocketmine\event\entity\EntityDamageByEntityEvent) {
                
    $damager $event->getDamager();
                if(
    $damager instanceof \pocketmine\Player) {
                    if(
    $damager->getInventory()->getItemInHand()->getId() == \pocketmine\item\Item::BONE) {
                        
    $event->setDamage($customDamage);
                    }
                }
            }
        }
     
    OnTheVerge likes this.
  5. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    You can also register the item once more but extend the item class with \pocketmine\item\Durable.
     
  6. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    This is getting confusing. Are you referring to the item durability (a.k.a. damage), or are you referring to the damage dealt when an entity attacks with the item?
     
  7. Oniii-Chan

    Oniii-Chan Witch

    Messages:
    66
    GitHub:
    Vincent583
    I'm refer to the damage deal when I hit a player
     
    Levi likes this.
  8. Oniii-Chan

    Oniii-Chan Witch

    Messages:
    66
    GitHub:
    Vincent583
    Your code won't work but thx for the the help :v
     
  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.