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

PlayerInteractEvent

Discussion in 'Development' started by Exploit5678, May 14, 2017.

  1. Exploit5678

    Exploit5678 Spider

    Messages:
    12
    GitHub:
    Unknown
    Hey does anyone know how to make a player execute a command when they tap anything with an item?
     
  2. DanielYTK

    DanielYTK Zombie

    Messages:
    227
    You should use something like this:
    PHP:
    public function onInteract(PlayerInteractEvent $ev){
            if(
    $ev->getItem()->getId() === /*Id of Item*/){
                
    $this->getServer()->dispatchCommand($ev->getPlayer(), "say hello world.");
            }
        }
     
    corytortoise likes this.
  3. Exploit5678

    Exploit5678 Spider

    Messages:
    12
    GitHub:
    Unknown
    Thanks it works! btw do u also know how to send a message?
     
  4. DanielYTK

    DanielYTK Zombie

    Messages:
    227
    Send a message to who?
     
  5. Exploit5678

    Exploit5678 Spider

    Messages:
    12
    GitHub:
    Unknown
    Like say u tap a book and it will say some information. How do i do that?
     
  6. jasonwynn10

    jasonwynn10 Moderator Poggit Reviewer

    Messages:
    1,489
    GitHub:
    jasonwynn10
    $event>getPlayer()->sendMessage("");
     
  7. Exploit5678

    Exploit5678 Spider

    Messages:
    12
    GitHub:
    Unknown
    IMG_4736.JPG I get this error
     
  8. DanielYTK

    DanielYTK Zombie

    Messages:
    227
    $ev->getPlayer()->sendMessage("blablabal");
     
  9. jasonwynn10

    jasonwynn10 Moderator Poggit Reviewer

    Messages:
    1,489
    GitHub:
    jasonwynn10
    NEVER just copy code. If you just copy someone else's code it will almost never work for you. Learn how to program properly or no one will assist you.
     
    OnTheVerge, HimbeersaftLP and Miste like this.
  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.