Jump to content

Check that inventory is empty "except Item ID"


deadfish

Recommended Posts

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!

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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. 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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 :)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

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