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

HelpPlayerInteractEvent

Discussion in 'Development' started by TGames, Jan 16, 2019.

  1. TGames

    TGames Silverfish

    Messages:
    18
    Code:
    public function onTap(PlayerInteractEvent $event) {
            $user = $event->getPlayer();
            $item = $event->getItem();
            $player = $event->getPlayer();
            if ($item->getId() == 280) {
                $player->setMaxHealth(50);
               $player->setHealth(50);
               $player->sendMessage('§a»§8'.$player->getName().'§e'.self::NAME_GAME.'§8:§a'.$player->getFolderName());
              
                
            }
        }
    Not found helpme
     
  2. notdrewdev

    notdrewdev Spider Jockey

    Messages:
    39
    GitHub:
    drewsucksatlife
    1) In your use statements, do
    PHP:
    use pocketmine\event\player\PlayerInteractEvent;
    2) Your $user variable looks like it’s unused and you use $player variable instead, you can remove that.

    3) Don’t use loose checks, do strict checks & use constants for items.
    PHP:
    if($item->getId() === Item::STICK)
    4) I’d hope you only want to set the player’s health and not change how much health they can have to 50, you’ll want to remove
    PHP:
    $player->setMaxHealth(50);
    if that’s the case.
     
  3. TGames

    TGames Silverfish

    Messages:
    18
    It has not worked the server is closed and does not give error: 'c
     
  4. Aericio

    Aericio Slime

    Messages:
    99
    GitHub:
    aericio
    Can you send the updated function so we can make sure you correctly fixed the issues @notdrewdev pointed out?
     
    OnTheVerge likes this.
  5. Marabou

    Marabou Baby Zombie

    Messages:
    137
    GitHub:
    wiligangster
    What is '$player->getFolderName()' it supposed to be $player->getLevel()->getFolderName()
    I think that's why your server crashed.
     
  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.