why this dont work in 0.16? PHP: public function onItemUse(DataPacketReceiveEvent $event){$br = C::RESET . C::WHITE . "\n";$pk = $event->getPacket();$player = $event->getPlayer();$level = $event->getPlayer()->getLevel();if($pk instanceof UseItemPacket and $pk->face === 0xff) {$item = $player->getInventory()->getItemInHand();if($item->getName() == C::GREEN ."Help"){$this->Help($player);}
Actually you should use PlayerInteractEvent with right click air. https://github.com/pmmp/PocketMine-...mine/event/player/PlayerInteractEvent.php#L40
Don't dare to call your self a programmer, or anything on that line! PHP: use pocketmine\event\player\PlayerInteractEvent;/** * Super simple code. * * @param PlayerInteractEvent $event * @priority NORMAL * @ignoreCancelled false */public function onPlayerInteract(PlayerInteractEvent $event) { if($event->getAction() === PlayerInteractEvent::RIGHT_CLICK_AIR) { // ... code }}
Please at least explain to him what what does, to help him make his way onto getting a programmer. Don't just bake code for him, and if he wants to change the ingredient salt to sugar, he is unable to do it because he has no recipe. PHP: if($event->getAction() === PlayerInteractEvent::RIGHT_CLICK_AIR) { checks if the action of the InteractEvent is equal to RIGHT_CLICK_AIR, that means if the player did just click in the air, and didn't break a block or sth similar. PHP: @param PlayerInteractEvent $event //Just documentation @priority NORMAL //Will run at normal priority. @ignoreCancelled false //Will not fire the function, if other plugins cancelled the event.
thanks and why this give me syntax error? PHP: if($item->getName() == C::GREEN ."Help"){ here it running without error: PHP: public function onItemUse(DataPacketReceiveEvent $event){$br = C::RESET . C::WHITE . "\n";$pk = $event->getPacket();$player = $event->getPlayer();$level = $event->getPlayer()->getLevel();if($pk instanceof UseItemPacket and $pk->face === 0xff) {$item = $player->getInventory()->getItemInHand();if($item->getName() == C::GREEN ."Help"){$this->Help($player);}
http://phpcodechecker.com/api/?code=if($item->getName() == C::GREEN ."Help"){/public function onItemUse(DataPacketReceiveEvent $event){$br = C::RESET . C::WHITE . "\n";$pk = $event->getPacket();$player = $event->getPlayer();$level = $event->getPlayer()->getLevel();if($pk instanceof UseItemPacket and $pk->face === 0xff) {$item = $player->getInventory()->getItemInHand();if($item->getName() == C::GREEN ."Help"){$this->Help($player);}[/PHP]
Use $item->getCustomName(), not $item->getName(). And give everyone a like here in the thread, especially these, who have pasted code...
Wrong, pocketmine\item\Item::getName() checks if the item has a custom name and returns it if there is one. https://github.com/pmmp/PocketMine-MP/blob/master/src/pocketmine/item/Item.php#L638 And, don't ask for likes (for anybody) unless you're asking to get banned.
I just recommended him to give the people who helped him a like, because he just takes the code... Hard to understand?
Is it hard to understand that people can press the like button when they feel like and not when you or anyone else tells them too?