December 2, 20178 yr 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"); }
December 2, 20178 yr Create a list of lootable items and then use the grounditems with a filter to check for them
December 2, 20178 yr something like: getGroundItems.getAll() then just iterate through the items and pick up the ones with ur req
December 2, 20178 yr 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, 20178 yr by toxicity959
December 2, 20178 yr 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.
Create an account or sign in to comment