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

Item that does damage to the opponent's armor !

Discussion in 'Development' started by Bluzzi, Mar 26, 2017.

  1. Bluzzi

    Bluzzi Spider Jockey

    Messages:
    46
    Hi, I'm looking for how to inflict damage to the opponent's armor that I tappe, but I can not figure out how to do this, do you have a solution?

    Thank you in advance ! And excuse me for my way English decricre, I am french! : P

    PHP:
    public function Tracker(EntityDamageEvent $event){
            
    $player $event->getEntity();
            if(
    $event instanceof EntityDamageByEntityEvent){
                
    $damager $event->getDamager();
                
    $inv $player->getInventory();
             
                if(
    $player->getItemInHand()->getId() == 352){
                    
    $inv->getHelmet()->setDamage($inv->getHelmet()->getDamage() + 100);
                    }
                }
            }
     
  2. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    Your code is correct (not. $player->getItemInHand() does not exist), except, you haven't updated the armor slots of the player.
    PHP:
    if($inv->getItemInHand()->getId() === 352){
        
    $helmet $inv->getHelmet();
        
    $helmet->setDamage($helmet->getDamage() + 100);
        
    $inv->setHelmet($helmet);
    }
     
    Bluzzi likes this.
  3. EdwardHamHam

    EdwardHamHam Skeleton

    Messages:
    962
    GitHub:
    edwardhamham
    Last time I checked, PocketMine had a bug where armor didn't take damage. Correct me if I'm wrong though, my info may be outdated.
     
  4. Zayd

    Zayd Witch

    Messages:
    55
    GitHub:
    ZaydPE
    Use an axe XD
     
  5. corytortoise

    corytortoise Skeleton

    Messages:
    825
    GitHub:
    corytortoise
    That's entirely false. Axes deal the same amount of damage to armor as any other tool by default.
     
  6. Zayd

    Zayd Witch

    Messages:
    55
    GitHub:
    ZaydPE
  7. PocketKiller

    PocketKiller Slime

    Messages:
    83
    GitHub:
    iPocket
    We're here to answer, not to joke about answers.
     
    EdwardHamHam likes this.
  8. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    It still does. But you can code an easy plugin to manage armor durability. Just keep increasing the item's damage by 1.
     
    corytortoise likes this.
  9. Bluzzi

    Bluzzi Spider Jockey

    Messages:
    46
    OK ! it works ! But do you have a solution for that if EntityDamageEvent is canceled in the box then the code has no effect? (I do not understand how isCancelled works, is it buggy ?)
     
  10. corytortoise

    corytortoise Skeleton

    Messages:
    825
    GitHub:
    corytortoise
    You should really set your plugin at lower priority so that other plugins and pocketmine can change or cancel the event(I think). You could do that with something like this:
    PHP:
     /**
     * @param EntityDamageEvent $event
     * @priority LOWEST
     */
     
    public function onDamage(EntityDamageEvent $event) {
     
    //Stuff you want to do
     
    or, you can do this:
    PHP:
     public function onDamage(PlayerDamageEvent $event) {
       
    //Checks if the event is not cancelled, and continues if returns true.
       
    if(!$event->isCancelled()) {
       
    //Your stuff here
       
    }
     }
    You may want to check me on the first method, I can't remember all of the priorities.
     
    Bluzzi likes this.
  11. Bluzzi

    Bluzzi Spider Jockey

    Messages:
    46
    Hm ... I will try, I keep you informed, and I do not use any plugin, except the "SympCore" which gathers all the functionalities of my server ! :p
     
  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.