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

Solved PlayerInteractEvent

Discussion in 'Development' started by Notjblus, Aug 23, 2019.

  1. Notjblus

    Notjblus Spider Jockey

    Messages:
    28
    GitHub:
    JblusItsMe
    Hello, I would like to add in the code of my server a way of execution of code, for example, with a arrow named "test", one click on a block of emerald and its execute a code (of course all this is is an example), the code I find does not work What for?

    PHP:
    public function onInteract(PlayerInteractEvent $event){
        
    $player $event->getPlayer();
        
    $item $event->getItem();
        
    $block $event->getBlock();

        if(
    $item->getId() == yourid){

            if(
    $block->getId() == yourblock){

                
    $player->sendMessage("Hello world");
            }
        }
    }
     
  2. Fadhel

    Fadhel Witch

    Messages:
    68
    GitHub:
    dimbis
    PHP:
    public function onInteract(PlayerInteractEvent $event){
    $player $event->getPlayer();
    $item $player->getInventory()->getItemInHand();
    $block $event->getBlock();
    if(
    $block->getId() === 1){
    if(
    $item->getId() === 276){
    //TODO
     
  3. MalakasPlayzMCPE

    MalakasPlayzMCPE Zombie Pigman

    Messages:
    667
    PHP:
    use pocketmine\block\Block;
    use 
    pocketmine\event\player\PlayerInteractEvent;
    use 
    pocketmine\item\Item;

        public function 
    onInteract(PlayerInteractEvent $event){
            
    $player $event->getPlayer();
            
    $item $player->getInventory()->getItemInHand();
            
    $block $event->getBlock();
            if(
    $block->getId() === Block::EMERALD_BLOCK && $item->getId() === Item::ARROW && $item->getName() === "test"){
                
    //code
            
    }
        }
     
  4. Fadhel

    Fadhel Witch

    Messages:
    68
    GitHub:
    dimbis
    i just said that already.
     
  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.