Jump to content

Check if inventory contains at least X of an item


Recommended Posts

Posted

Hi I'm fairly new to this so please don't shoot me :doge:

 

What I'm trying to accomplish is to check if my script has at least two or more of an item, if not, it should bank.

I currently have this boolean:

    private boolean hasRequiredItems() {

    if(!getInventory().contains("Plank") || !getInventory().contains("Hammer") || !getInventory().contains("Saw") || !getInventory().contains("Steel nails"))

    {

    return false;

    }

return true;

}

 

Would it be something like if(getInventory().contains("Plank", 1)  (which is the only number less than 2)

But what if I wanna check if the inventory contains at least 10 steel nails. 

 

Appreciate the help in advance, I've looked through the API but I find it a bit hard to read :facep:

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...