Hi, I have been also working on a GUI/ Chest tile plugins. The reason of my creating this thread is how do I add functions in the Chest. Example: when someone open the tile. It shows an item, when they click it, it allows the player to get a kit once tapped and how do I cancel the Chest inventory item adding 'event' if it's an event. Thank you very much.. I hope I'm making sense here. PHP: <?phpnamespace GUI;use pocketmine\block\Block;use pocketmine\command\Command;use pocketmine\command\CommandSender;use pocketmine\event\Listener;use pocketmine\item\Item;use pocketmine\level\Position;use pocketmine\level\Level;use pocketmine\Player;use pocketmine\math\Vector3;use pocketmine\nbt\NBT;use pocketmine\nbt\tag\CompoundTag;use pocketmine\nbt\tag\IntTag;use pocketmine\nbt\tag\ListTag;use pocketmine\nbt\tag\StringTag;use pocketmine\plugin\PluginBase;use pocketmine\tile\Chest;use pocketmine\tile\Tile;class GUI extends PluginBase implements Listener { public function onEnable() { $this->getServer()->getPluginManager()->registerEvents($this, $this); } public function onCommand(CommandSender $sender, Command $cmd, $label, array $param) { switch(strtolower($cmd->getName())) { case "gui": $this->onOpen($sender); return true; break; } } public function onOpen(Player $player){ // Thanks to https://github.com/G******FTW/addWindow/tree/master/src/G******FTW $block = Block::get(54); $player->getLevel()->setBlock(new Vector3($player->x, $player->y - 2, $player->z), $block, true, true); $nbt = new CompoundTag("", [ new ListTag("Items", []), new StringTag("id", Tile::CHEST), new IntTag("x", floor($player->x)), new IntTag("y", floor($player->y) - 2), new IntTag("z", floor($player->z)) ]); $nbt->Items->setTagType(NBT::TAG_Compound); $tile = Tile::createTile("Chest", $player->getLevel()->getChunk($player->getX() >> 4, $player->getZ() >> 4), $nbt); $i = $tile->getInventory(); $i->addItem(Item::get(Item::STONE, 0, 1)); $player->addWindow($tile->getInventory()); } public function onDisable() { }}
Okay, what about function in certain blocks? Idk how to explain it but it has function like gives the person who taps it Kit.
Not Exactly sure what're you asking But what I do for My server is Run a task for every second and check each players inventory and see if they have a certain item in their inventory that they could only obtain from the Chest Tile
Thats a horrible way to do it, just use events, easier & faster You can use InventoryOpenEvent then set the item on the $event->getInventory() Use InventoryTransactionEvent to check if a player took an item from the specific inventory, and cancel it then run your code code: InventoryOpenEvent: PHP: onOpen(InventoryOpenEvent $event){ $inventory = $event->getInventory(); $chestBlock = $inventory->getHolder(); if($chestBlock instanceof \pocketmine\block\Chest){//if the block is a chest if($block->getPosition() === new Position($x, $y, $z, $level)){ // a way to check if its the chest you want, there alot of ways to check, but i dont know what is the specific way you want $inventory->addItem($item); // $item is the item you want to add } }} InventoryTransactionEvent: PHP: public function onTransaction(InventoryTransactionEvent $event){ $transa = $event->getTransaction()->getTransactions(); $int = $event->getTransaction()->getInventories(); foreach($transa as $t=>$value){ foreach($int as $inst) { $inst = $inst->getHolder(); if($inst instanceof Player){ $player = $inst; } if($inst instanceof Chest){ $chest = $inst; } $targetitem = $value->getTargetItem(); } } $block = $chest->getBlock(); if($block->getPosition() === new Position($x, $y, $z, $level)){//same concept if($targetitem->getId() === $item->getId() && $targetitem->getDamage() === $item->getDamage()){//$item is the item you want to check $event->setCancelled(); //your code } } }}