remove function dont work

Discussion in 'Plugin Development' started by Moon_werewolf, Feb 27, 2011.

Thread Status:
Not open for further replies.
  1. Offline

    Moon_werewolf

    i try to make a function that removes items from a chest and the player, like i want to remove 40 gold ingots and the are 30 in the chest and 30 on the player for some reason it only removes 10 on the player :/

    NVM i get it to work
    Code:
    public static void removeSmart(Inventory[] inventory, int itemType, short damage, int amount)
        {
            for(Inventory inv : inventory)
            {
                for(int i=0; i<inv.getSize(); i++)
                {
                    ItemStack item = inv.getItem(i);
                    if(item != null && item.getTypeId() == itemType && item.getDurability() == damage)
                    {
                        int left = item.getAmount() - Math.min(item.getAmount(),amount);
                        amount -= item.getAmount();
                        amount = Math.max(amount,0);
                        
                        if(left <= 0)
                        {
                            inv.clear(i);
                        }else{
                            item.setAmount(left);
                        }
                    }
                }
            }
        }
     
  2. Offline

    DiaAWAY

    Does it remove the 30 from the chest? :) if the first inventory in the array is the chest itself, that would explain it
     
  3. Offline

    Moon_werewolf

    got it to work. it was the way to remove the items that dont wotk so i changed the code little so i could use .clear :)
     
  4. Offline

    DiaAWAY

    ah, thx for the info then ^_^
     
Thread Status:
Not open for further replies.

Share This Page