Jump to content

GroundItems see how many there is?


Recommended Posts

Posted

Hi i am trying to setup a basic script that will detect if there are x amount of whatever item on ground and if there is then pick it up otherwise it would just ignore it, how would i go about doing this i've tried the following but it doesn't seem to be working thanks.

GroundItem item1 = groundItems.closest(id);
			if (item1.getAmount() >= 28) {
				item1.interact("Take");
			}

 

Posted (edited)

If I'm understanding you properly, you're looking to see if there are x amount of an item anywhere on the ground (e.g. looking for >250 coins, 3 stacks of 100 coins = 300 coins, loot all stacks). You could use a for loop to accomplish this. Something like this comes to mind. Just be careful with the while loop -- depending on your particular case, your code could get stuck there.

int amount = 0;
int itemId = <your item>;
  
for(GroundItem g : getGroundItems().getAll()) {
	if(g.getId() == itemId)
  		amount += g.getAmount();
}
  
if(amount > x) {
	GroundItem g = getGroundItems().closest(itemId);
	while(g != null) {
		g.interact("Take");
		new ConditionalSleep(10000){
			public boolean condition() throws InterruptedException {
				return !g.exists();
			}
		}.sleep();
		g = getGroundItems().closest(itemId);
	}
}

 

Edited by toxicity959
Posted
9 hours ago, DragonTTK said:

Hi i am trying to setup a basic script that will detect if there are x amount of whatever item on ground and if there is then pick it up otherwise it would just ignore it, how would i go about doing this i've tried the following but it doesn't seem to be working thanks.


GroundItem item1 = groundItems.closest(id);
			if (item1.getAmount() >= 28) {
				item1.interact("Take");
			}

 

If the item is a stacked item then what you posted should work.

If it is not however, then it will be a little more complex.

 

If you don't care if the ground items are all in the same position then you can do:

List<GroundItem> items = getGroundItems().filter(getGroundItems().getAll(), new NameFilter<>("Item name"));

if (items.size() >= 28) {
    ... 
}

 

If you want to check if the ground items are all in the same stack, then it is a little more complicated. I *think* there is a way to get the stack in the API but i'm not sure.

I can post some code if you really need.

  • Like 1

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