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

Solved check if the player is equipped with a helmet

Discussion in 'Development' started by armagadon159753, Oct 31, 2017.

  1. armagadon159753

    armagadon159753 Zombie

    Messages:
    217
    GitHub:
    armagadon159753
    how can I check if the player is equipped with a helmet or a head?

    I await your enthusiastic response:shoghi:

    but I can not find the heads of creeper and other
    PHP:
    if($player->getInventory()->getHelmet()->getId() === Item::ZOMBIE HEAD) {
    }
     
    Last edited: Oct 31, 2017
  2. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    wait waht, you should be getting "undefined constant 'HEAD'" error. Item::ZOMBIE_HEAD does not exist too.
     
    armagadon159753 likes this.
  3. armagadon159753

    armagadon159753 Zombie

    Messages:
    217
    GitHub:
    armagadon159753
    Noo :p it's just an example
     
  4. WinterBuild7074

    WinterBuild7074 Zombie Pigman

    Messages:
    693
    GitHub:
    winterbuild7074
    Heads haven’t been added the PMMP yet. You can use ID 397 for now:
    PHP:
    if($player->getInventory()->getHelmet()->getId() === 397 && $player->getInventory()->getHelmet()->getDamage() === 1) { // Wither Skeleton Skull
        // do something
    }
     
    armagadon159753 likes this.
  5. armagadon159753

    armagadon159753 Zombie

    Messages:
    217
    GitHub:
    armagadon159753
    ok, thank you but this code does not work
    PHP:
    public function onInteract(PlayerInteractEvent $event) {
            
    $player $event->getPlayer();
            if(
    $player->getInventory()->getHelmet()->getId() === 397 && $player->getInventory()->getHelmet()->getDamage() === 1){
                
    $player->sendMessage("test");
            }
        }
     
    Last edited: Oct 31, 2017
  6. WinterBuild7074

    WinterBuild7074 Zombie Pigman

    Messages:
    693
    GitHub:
    winterbuild7074
    Are you sure you were wearing a Wither Skeleton Skull? Are you sure you interacted? Try adding an else and you’ll see:
    PHP:
    public function onInteract(PlayerInteractEvent $event) {
        
    $player $event->getPlayer();
        
    $helmet_id $player->getInventory()->getHelmet()->getId();
        
    $helmet_meta $player->getInventory()->getHelmet()->getDamage();
        if(
    $helmet_id === 397 && $helmet_meta === 1){
            
    $player->sendMessage("test");
        } else {
            
    $player->sendMessage("No, you are not wearing a Wither Skleton Skull.");
            
    $player->sendMessage("You are wearing, ID: " $helmet_id ", meta: " $helmet_meta);
        }
    }
     
    armagadon159753 likes this.
  7. armagadon159753

    armagadon159753 Zombie

    Messages:
    217
    GitHub:
    armagadon159753
     
  8. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    937 is not the skull id ✓××
     
    armagadon159753 likes this.
  9. armagadon159753

    armagadon159753 Zombie

    Messages:
    217
    GitHub:
    armagadon159753
    I m agree with you but they the same result with 397
     
  10. WinterBuild7074

    WinterBuild7074 Zombie Pigman

    Messages:
    693
    GitHub:
    winterbuild7074
    You didn’t put the Wither Skeleton Skull on your head. Also, that was a Skeleton Head, not a Wither one.
     
    armagadon159753 likes this.
  11. armagadon159753

    armagadon159753 Zombie

    Messages:
    217
    GitHub:
    armagadon159753
    it works, my mistake was stupid
     
  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.