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

how to set onClick ?

Discussion in 'Plugin Help' started by tokoyami ds, Jul 14, 2020.

  1. tokoyami ds

    tokoyami ds Spider Jockey

    Messages:
    25
    PHP:
    public function onClick(PlayerInteractEvent $event){
            
    $player $event->getPlayer();
            
            
        }
    how to set item ID and sendMessage on this?
     
  2. Primus

    Primus Zombie Pigman

    Messages:
    749
    What do you want to accomplish?

    PHP:
    $player->sendMessage("Your message");
    As for "set item ID", it doesn't make sense in this context without further explanation.
     
  3. tokoyami ds

    tokoyami ds Spider Jockey

    Messages:
    25
    No I know send message .
    set item id plz
    And
    I prefer not to say
     
  4. Primus

    Primus Zombie Pigman

    Messages:
    749
    sure, here you go
    PHP:
    $player->getInventory()->setItem(0, \pocketmine\item\ItemFactory::get(\pocketmine\item\ItemIds::DIAMOND_SWORD));
     
  5. tokoyami ds

    tokoyami ds Spider Jockey

    Messages:
    25
    And message ?
     
  6. GodWeedZao

    GodWeedZao Zombie Pigman

    Messages:
    401
    GitHub:
    godweedzao
    Hello, i think you want to add item in to player inv?
    for do this you need this code:

    PHP:
    public function GodWeedZao(PlayerInteractEvent $event) {

      
    $event->getPlayer()->getInventory()->addItem(Item::get(Item::DIAMOND010)); // this will add items to player inventory (10 diamond).

      
    $event->getPlayer()->sendMessage("This is a Test !"); //sending msg to player
     
    }
     
  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.