Jump to content

GroundItems see how many there is?


DragonTTK

Recommended Posts

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");
			}

 

Link to comment
Share on other sites

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

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