Hi, i'm new on pmmp, i learned apis and now i started developing, but i'm noob at the moment. that's a piece of my code: public function onTouch(PlayerInteractEvent $event){ $player = $event->getPlayer(); $item = $event->getItem(); if($item->getId() == 345){ $player->getInventory()->clearAll(); $player->getInventory()->addItem(Item::get(267,0,1)); $player->sendMessage(TextFormat::GRAY . ">-------------------------------------------<"); $player->sendMessage(TextFormat::GOLD . "-" . TextFormat::YELLOW . "Non usare hacks" . TextFormat::GRAY . "!"); $player->sendMessage(TextFormat::GOLD . "-" . TextFormat::YELLOW . "Non spammare" . TextFormat::GRAY . "!"); $player->sendMessage(TextFormat::GOLD . "-" . TextFormat::YELLOW . "Non chiedere OP" . TextFormat::GRAY . "!"); $player->sendMessage(TextFormat::GRAY . ">-------------------------------------------<"); }elseif($item->getId() == 267) { $event->getPlayer()->sendMessage(TextFormat::RED . "- " . TextFormat::GRAY . "PvP Mode Correctly " . TextFormat::WHITE . "Activated!"); $player->getInventory()->clearAll(); $player->getInventory()->addItem(Item::get(267,0,1)); $player->getInventory()->addItem(Item::get(306,0,1)); $player->getInventory()->addItem(Item::get(307,0,1)); $player->getInventory()->addItem(Item::get(308,0,1)); $player->getInventory()->addItem(Item::get(309,0,1)); $player->getInventory()->addItem(Item::get(261,0,1)); $player->getInventory()->addItem(Item::get(262,0,64)); $player->getInventory()->addItem(Item::get(331,0,1)); $this->hubpvp = true; }elseif ($this->hubpvp == true) { $e->setCancelled(); } but when i get the sword and click one time, it giev me right itemes but i can reclick the sword and it will reset inventory and guve new sword, new and also i don't know why i cant wear armor directly clicking, its blocked but i can only whith inventory opened. Thanks
Sorry i want to help you but i dont really understand wath do you want to do? PHP: $e->setCancelled(); the variable $e is undefined PHP: $event->getPlayer()->sendMessage(TextFormat::RED . "- " . TextFormat::GRAY . "PvP Mode Correctly " . TextFormat::WHITE . "Activated!"); you have already defined $player then you can replace $event->getPlayer(); by $player
Thanks for the correction, I had not noticed. Basically I want that when I click the sword, the command that runs rejoices to make clear inventory and put another sword etc, functions only once is already active does not go. Because now the players are repeating the sword many times, the function starts all over again.
public $click = array(); PHP: public function onTouch(PlayerInteractEvent $event){$player = $event->getPlayer();$item = $event->getItem();if($item->getId() == 345){// do things$this->click[strtolower($p->getName())] = $p->getName(); }if(in_array(strtolower($p->getName()), $this->click)){$event->setCancelled(true);}else{$event->setCancelled(false);}}
PHP: /** @var int[] $touched */protected $touched = [];public function onTouch(PlayerInteractEvent $event){ $player = $event->getPlayer(); $item = $event->getItem(); if(isset($this->touched[$player->getXuid()])){ $event->setCancelled(); return; }//things to do...$this->touched[$player->getXuid()] = 1;}