Im making a deposit sign where players can exchange gold ingots for coins. It works except for 1 error. When you tap the sign holdng gold ingots, it creates another stack of gold ingots in your inventory instead of actually removing them. So now you have two stacks of gold ingots that are identical, except the original stack doesnt get removed from your hand when you tap the sign, but the duplictae one does. Where is the error? PHP: // Public function onTouch(PlayerInteractEvent $event) if($this->isDepositSign($tile)) { $item = $player->getInventory()->getItemInHand(); $index = $player->getInventory()->getHeldItemIndex(); if($player->getInventory()->getItemInHand()->getId() == "266") { $player->getInventory()->setItem($index, Item::get($item->getId(), 0, $item->getCount() - 1)); $this->player->set("coins", $this->getCoins($player) + 10); $this->savePlayerData($player); $player->sendPopup("§bGold deposited\n§bNew balance: " . $this->getCoins($player)); } else { $player->sendPopup("§cYou are not holding any §eGold Ingots"); } } }
Nvm. I have fixed the problem by changing PHP: $player->getInventory()->setItem($index, Item::get($item->getId(), 0, $item->getCount() - 1)); to PHP: $player->getInventory()->setItemInHand(Item::get($item->getId(), 0, $item->getCount() - 1));
Yes, and it is bad practice to compare things incorrectly. I said should. Moreover, it is indeed slower in terms of performance to compare an int with a string while you can compare two ints directly. And it shows you have wrong concept if you do that.