Jump to content

Check that inventory is empty "except Item ID"


Recommended Posts

Posted

So, I'm trying to get a script to continue an action once there is no longer a particular item in the inventory. It's easy to get it to drop the item, just 

Spoiler

inventory.dropAll(item ID's here);

But then I would like it to continue mining/thieving/chopping etc once the inventory is empty of that particular item(s).

I've tried

Spoiler

if (!inventory.isEmpty(Item ID here))
     return State.STATE1;

as well as

Spoiler

if (!inventory.contains(0-Item ID here))
            return State.STATE1;

(a few different versions of this one)

But I cant seem to find a way to get it to ONLY check that the inventory is empty of a specific item/items.

The reverse seems easy(Checking that the inventory DOES contain a specific item ID's), seems odd that it cant check for the lack of an item the same way.

I'm probably missing something stupidly easy, but I'm new to this and have been looking for a solution off and on all day. :/

 

any help is really appreciated!

Posted
7 minutes ago, Butters said:

Just use inventory.isEmptyExcept();

And I strongly advise to use item names (Strings) and not id's for reasons like code clarity and for the fact that ids might change.

 

Is empty except would mean I would have to list everything outside of the one or two items i want it to drop, so in this case it would be a pretty long list. like, thousands. :/

Posted
13 minutes ago, sudoinit6 said:

If it were me I would use strings and say !inventory.contains(String), but I am a noob, and kinda drunk so maybe that isn't helpful.

i dont think that would work though for the same reason above. I need to to check that a specific item is missing, not that any item besides that is there. Because I need to to work weather the inventory is empty, AND/OR at least doesnt have that particular item there. 

Posted
12 minutes ago, deadfish said:

i dont think that would work though for the same reason above. I need to to check that a specific item is missing, not that any item besides that is there. Because I need to to work weather the inventory is empty, AND/OR at least doesnt have that particular item there. 

I don't get what's wrong with !inventory.contains() ?

If inventory contains some fancy item - do something, if it doesn't - do something else

Posted
1 hour ago, deadfish said:

i dont think that would work though for the same reason above. I need to to check that a specific item is missing, not that any item besides that is there. Because I need to to work weather the inventory is empty, AND/OR at least doesnt have that particular item there. 

if (!getInventory().contains("your item") {

// continue

}

If the inventory does not contain the item do something.

"I need to to check that a specific item is missing, not that any item besides that is there"

You are checking if that specific item is missing with that code.

  • Like 1
Posted (edited)
7 minutes ago, Antonio Kala said:

if (!getInventory().contains("your item") {

// continue

}

If the inventory does not contain the item do something.

"I need to to check that a specific item is missing, not that any item besides that is there"

You are checking if that specific item is missing with that code.

this looks like it is what i needed. I mean to say, i think this is going to involve a bit more change than I thought. Thank you for the input!

 

 

so really the part where im hung up is

Quote

If the inventory does not contain the item do something.

How tf do i write that using the osbot api?

Edited by deadfish
Posted
6 minutes ago, deadfish said:

this looks like it is what i needed. I mean to say, i think this is going to involve a bit more change than I thought. Thank you for the input!

 

 

so really the part where im hung up is

How tf do i write that using the osbot api?

if (!inventory.contains("Item name") {
  //walking.webwalk(Banks.FALADOR_EAST);
  /* RS2Object oakTree = objects.closest("Oak");
    if (oakTree != null)
    	oakTree.interact("Cut");
  */
  // etc etc etc
}

Hard to understand what you really need.

I recommend reading a few of OSBot API tutorials here on OSBot. Some are very good

Posted
10 minutes ago, Butters said:

if (!inventory.contains("Item name") {
  //walking.webwalk(Banks.FALADOR_EAST);
  /* RS2Object oakTree = objects.closest("Oak");
    if (oakTree != null)
    	oakTree.interact("Cut");
  */
  // etc etc etc
}

Hard to understand what you really need.

I recommend reading a few of OSBot API tutorials here on OSBot. Some are very good

Sorry if i havent been very clear. Ive been skimming through tutorials for like a day and a half now and cant find an alternative. though i noticed that there are some good paid scripts that actually suffer from this problem tht im trying to prevent. Basically, lets say I have a power miner, that needs to mine iron and then drop it all, then once its all dropped needs to keep mining. well, there is at least one paid script i've used that will drop everything in the inventory except pickaxes. this means they probably said for the script to drop everything except pickaxes, and then just to check that the inventory was empty aside from those pickaxes. well, it may be a waste of time, but i want my script to literally only drop one or two things, and keep everything else there. so like, if you start the power miner with some random shit in your inventory, it wont get dropped just because its not on a specific list to be ignored.

Posted (edited)
Quote

but i want my script to literally only drop one or two things, and keep everything else there. so like, if you start the power miner with some random shit in your inventory, it wont get dropped just because its not on a specific list to be ignored.

 

When starting the script create a list of items that contains all the Items in your inventory. Then you can drop everything else except those items with this

getInventory().dropAllExcept(List<Item>)

 

Edited by goldKeeper
Posted
23 minutes ago, goldKeeper said:

 

When starting the script create a list of items that contains all the Items in your inventory. Then you can drop everything else except those items with this


getInventory().dropAllExcept(List<Item>)

 

Excatly this

String[] itemsToKeep = new String[] { "Rune pickaxe", "Uncut sapphire" } // Etc
if (inventory.isFull()) {
	inventory.dropAllExcept(itemsToKeep);
} else {
	// Do mining
}

Can also write your own stuff for dropping. Like iterating though the inventory and checking items.

Posted

Okay so i think ive been a bit unclear. I already have it set to drop only the items i need it too. the problem is im trying to get it to continue to the previous action once ONLY that item is gone. because right now the problem i have is that it drops the one type of item, then checks that the inventory is empty, then continues. the problem here is that if i still have anything other than that item in the inventory it wont continue, and since it only drops said item, it will just hang there.

Posted
53 minutes ago, deadfish said:

Okay so i think ive been a bit unclear. I already have it set to drop only the items i need it too. the problem is im trying to get it to continue to the previous action once ONLY that item is gone. because right now the problem i have is that it drops the one type of item, then checks that the inventory is empty, then continues. the problem here is that if i still have anything other than that item in the inventory it wont continue, and since it only drops said item, it will just hang there.

so do
 

if(!inventory.contains("ITEM"){
	// do your thing because the item isnt in your inventory
}else{
	inventory.dropAll("ITEM");
}

 

  • Like 1
Posted
2 hours ago, GPSwap said:

so do
 


if(!inventory.contains("ITEM"){
	// do your thing because the item isnt in your inventory
}else{
	inventory.dropAll("ITEM");
}

 

legit think this is actually gonna work perfectly. tyvm man!
I'll report back in this thread when i get the chance to sort it out and get it running :)

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...