DragonTTK Posted December 2, 2017 Share Posted December 2, 2017 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"); } Quote Link to comment Share on other sites More sharing options...
H0rn Posted December 2, 2017 Share Posted December 2, 2017 Create a list of lootable items and then use the grounditems with a filter to check for them Quote Link to comment Share on other sites More sharing options...
dreameo Posted December 2, 2017 Share Posted December 2, 2017 something like: getGroundItems.getAll() then just iterate through the items and pick up the ones with ur req Quote Link to comment Share on other sites More sharing options...
toxicity959 Posted December 2, 2017 Share Posted December 2, 2017 (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 December 2, 2017 by toxicity959 Quote Link to comment Share on other sites More sharing options...
Explv Posted December 2, 2017 Share Posted December 2, 2017 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. 1 Quote Link to comment Share on other sites More sharing options...