I am trying to make a plugin that has a feature that when you swap 2 items in the inventory it takes one of each then gives you a new item. I have the new item part taken care of just not the finding the item part
Try this PHP: $inventory = $player->getInventory();$num = rand(0,35);$slot = $num;while($inventory->isSlotEmpty($slot)) { $slot = rand(0,35);}$item = $inventory->get($slot);
check if $player->getInventory()->getHotbarSlot(rand(1, 30)); is emptyslot, so some thing (im not in ide, mybe i have typo in code
How do I get it to remove a itemas I'm trying to make a plugin that when you swap 2 items it takes one of each
swap 2 items? you should use config, really i dont think there isn't way to do that without using cfg, because you need to save swap numbers, and if swap num of player in 2, remove random item from player inventory.
i think you should save players name like array and set in to players name in cfg like: GodWeedZao: - 0 when they join or... and then onTransAction(InventoryTransactionEvent) check if event instanceof slotchange, and if under name player in cfg !== 2, set player under name to $num++ and its working for when player using 2 item, doing stuff, and for remove items from player inventory random, you need to get all items in player inv (array) and check PHP: if (!is_null($inv)) { //this is for check if player have an item in his inventory.//do stuff } and for get random items: https://3v4l.org/0Diqd see this code. and for set item: $inv->setItem($b, Item::get(0, 0, 0));
this is my idea and its working for me, if you have problem - errors, tell me here, or if its bad idea (its laggy for server iknow) wait for other people posts, i cant think good rn, tomorrow i'll checl your thread again to find better anwser