When i click on the item it didnt do anything and the inventory doesnt close too. Can someone help me? The code is below P/S: Sorry for the messy code. Im Newbie PHP: <?phpnamespace HyperGames;use muqsit\invmenu\{InvMenu, InvMenuHandler};use pocketmine\plugin\PluginBase;use pocketmine\item\Item;use pocketmine\Server;use pocketmine\Player;use pocketmine\command\ConsoleCommandSender;use pocketmine\command\CommandSender;use pocketmine\command\Command;use pocketmine\event\Listener;class Main extends PluginBase implements Listener{public function onEnable() : void{if(!InvMenuHandler::isRegistered()){InvMenuHandler::register($this);$this->getLogger()->info("§9§l>§aRankShop Enable");}}public function onDisable() : void{$this->getLogger()->info("§9§l>§cRankShop Disable");}public function onCommand(CommandSender $sender,Command $cmd, string $commandLabel, array $args) : bool{if($cmd->getName() == "rankshop"){$menu = InvMenu::create(InvMenu::TYPE_CHEST);$shop = $menu->getInventory();$vip1 = Item::get(Item::IRON_BLOCK)->setCustomName("§lVIP-I§e - 10 Coins");$vip2 = Item::get(Item::GOLD_BLOCK)->setCustomName("§l§eVIP-II - 20 Coins");$vip3 = Item::get(Item::DIAMOND_BLOCK)->setCustomName("§l§bVIP-III§e - 30 Coins");$vip4 = Item::get(Item::EMERALD_BLOCK)->setCustomName("§l§aVIP-IV§e - 40 Coins");$vip5 = Item::get(Item::OBSIDIAN)->setCustomName("§l§5VIP-V§e - 50 Coins");$shop->setItem(11, $vip1);$shop->setItem(13, $vip2);$shop->setItem(15, $vip3);$shop->setItem(21, $vip4);$shop->setItem(23, $vip5);$menu->readonly();$menu->setName(" §l§eHyperGames§a Rank Shop");$menu->send($sender);$menu->setListener(function(Player $player, Item $itemTakenOut, Item $itemPutIn, SlotChangeAction $inventoryAction) : bool{if(!$itemTakenOut->isNull()){$player->removeWindow($inventoryAction->getInventory());}if($itemTakenOut->getId() == ITEM::IRON_BLOCK){$this->getServer()->dispatchCommand(new ConsoleCommandSender(), "setgroup " . $player->getName() . " vip1");$this->getServer()->getPluginManager()->getPlugin("Coins")->grantMoney($player->getName(), -10, true);$this->getServer()->broadcastMessage("§a[§l§eHyperGames§r§a] Bạn§e " . $player->getName() . "§a đã mua gói§f§l VIP-I");$player->addTitle("Bạn đã mua gói §f§lVIP-I");}elseif($itemTakenOut->getId() == ITEM::GOLD_BLOCK){$this->getServer()->dispatchCommand(new ConsoleCommandSender(), "setgroup " . $player->getName() . " vip2");$this->getServer()->getPluginManager()->getPlugin("Coins")->grantMoney($player->getName(), -20, true);$this->getServer()->broadcastMessage("§a[§l§eHyperGames§r§a] Bạn§e " . $player->getName() . "§a đã mua gói§e§l VIP-II");$player->addTitle("Bạn đã mua gói §e§lVIP-II");}elseif($itemTakenOut->getId() == ITEM::DIAMOND_BLOCK){$this->getServer()->dispatchCommand(new ConsoleCommandSender(), "setgroup " . $player->getName() . " vip3");$this->getServer()->getPluginManager()->getPlugin("Coins")->grantMoney($player->getName(), -30, true);$this->getServer()->broadcastMessage("§a[§l§eHyperGames§r§a] Bạn§e " . $player->getName() . "§a đã mua gói§b§l VIP-III");$player->addTitle("Bạn đã mua gói §b§lVIP-III");}elseif($itemTakenOut->getId() == ITEM::EMERAlD_BLOCK){$this->getServer()->dispatchCommand(new ConsoleCommandSender(), "setgroup " . $player->getName() . " vip4");$this->getServer()->getPluginManager()->getPlugin("Coins")->grantMoney($player->getName(), -40, true);$this->getServer()->broadcastMessage("§a[§l§eHyperGames§r§a] Bạn§e " . $player->getName() . "§a đã mua gói§a§l VIP-IV");$player->addTitle("Bạn đã mua gói §a§lVIP-IV");}elseif($itemTakenOut->getId() == ITEM::OBSIDIAN){$this->getServer()->dispatchCommand(new ConsoleCommandSender(), "setgroup " . $player->getName() . " vip5");$this->getServer()->getPluginManager()->getPlugin("Coins")->grantMoney($player->getName(), -50, true);$this->getServer()->broadcastMessage("§a[§l§eHyperGames§r§a] Bạn§e " . $player->getName() . "§a đã mua gói§5§l VIP-V");$player->addTitle("Bạn đã mua gói §5§lVIP-V");}return false;});}return true;}}
PHP: $player->removeWindow($inventoryAction->getInventory()); should work, do var_dump($itemTakenOut); P.S. You'd probably be getting errors about using $this in that callable.
You Need to First Have the Player Open a Window with $ sender-> addWindow ($ menu); and here below, set the items that go inside ... then you have to use the InventoryTransactionEvent to do so that when the player clicks on the item the desired function can be performed and the code that works right is just a Kom
c Cant i use PHP: $menu->send($sender);?What is the different between [PHP] $sender->addWindow($menu);and[PHP] $menu->send($sender
public $windows = []; public function onCommand(CommandSender $sender, Command $cmd, string $lbl, array $a) : bool{ if($cmd->getName() == "rankshop"){ $win = new WindowInventory($sender, 27, "§aRank Shop"); $sender->addWindow($win); $this->windows[strtolower($sender->getName())] = $win; $p = item::get(item::FEATHER, 0, 20); $p->setCustomName("§eNAME"); $win->setItem(11, $p); } } public function onClick(InventoryTransactionEvent $e){ $put = $e->getTransaction(); $p = $put->getPlayer(); $inv = $this->getWindow($p); if(is_null($inv)){ foreach($put->getInventories() as $inventory){ if($inventory instanceof WindowInventory){ $e->setCancelled(); } } return true; } foreach($put->getTransactions() as $action){ $item = $action->getTargetItem(); $custom = $item->getCustomName(); $inv = $this->getWindow($p); if(is_null($perm)){ $p->sendMessage("§aInv Null"); } if($item->getCustomName() == "§eNAME"){ $e->setCancelled(true); //cod of commmand $p->removeWindow($inv); //close chest } } } public function getWindow(Player $p){ $name = strtolower($p->getName()); if(isset($this->windows[$name])){ return $this->windows[$name]; } return null; } //To use WindowInventory Download the WindowInventory + WindowHolder Dowload https://www.sendspace.com/file/jynjzt and https://www.sendspace.com/file/mfsm7q