removing items from player's inventory

Discussion in 'Plugin Development' started by Visagalis, Apr 8, 2011.

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

    Visagalis

    i'm trying to remove item from player's inventory if he exists, but i can't seem to find good way of doing that.

    this is what i have:

    Code:
           if (seller.getInventory().contains(itemID, count))
                seller.getInventory().remove(xxxx); // problem is here, because i can't use itemID,count in params.
            else
                return false;
    
    howcome i can use those variables in contains method, but can't use in remove?
     
  2. Offline

    Joeyy

    Use something like this:

    ItemStack[] i = player.getInventory().contains(itemID, count);
    player.getInventory().removeItem(i);
     
  3. Offline

    Ne0nx3r0

    Take a look at this thread. The examples might be helpful.
     
  4. Offline

    Visagalis

    Code:
            if (!seller.getInventory().contains(itemID))
                return false;
    
            ItemStack item = new ItemStack(itemID,count);
            HashMap<Integer,ItemStack> itemsLeft = seller.getInventory().removeItem(item);
    
            if (itemsLeft.isEmpty())
                 seller.sendMessage("Item added to shop");
            else
            {
                item.setAmount(count - item.getAmount());
                seller.getInventory().addItem(item);
                seller.sendMessage("Item not added to shop");
            }
    after long investigation and some work from guys from IRC, i've made it work :)
    Thanks to: MattTwoPointOh and Pluckerpluck
     
  5. Offline

    woodzy

    or just do a search for "isee" plugin it does the same thing but u have to be like next to them
     
Thread Status:
Not open for further replies.

Share This Page