breakfastyum Posted February 8, 2018 Share Posted February 8, 2018 im using this wilderness looting script that takes items from the ground. it works pretty well except when it finds an item that is so far away or behind a hill so that the take menu is not available and it just gets stuck. how would i fix this to walk towards the item if it is too far away? or at least ignore if it cant actually be picked up. for(int i = 0;i<P2PLoot.length;i++){ for(GroundItem g: groundItems.getAll()){ if(g.getName().equals(P2PLoot[i])&&g !=null){ if(inventory.isFull()||skills.getDynamic(Skill.HITPOINTS)<=6||myPlayer().isUnderAttack()){ break; } log("found item!"+ P2PLoot[i]); GroundItem a= groundItems.closest(P2PLoot[i]); a.interact("Take"); sleep(300); do{ sleep(200); }while(myPlayer().isAnimating()); breaker = true; break; } } Quote Link to comment Share on other sites More sharing options...
Chris Posted February 8, 2018 Share Posted February 8, 2018 make new code Quote Link to comment Share on other sites More sharing options...
dreameo Posted February 8, 2018 Share Posted February 8, 2018 if item distance < x loot else walk to item WalkCondition should break on distance threshold being met 1 Quote Link to comment Share on other sites More sharing options...
scriptersteve Posted February 8, 2018 Share Posted February 8, 2018 this snippet may be helpful: public GroundItem getTokkul() { Filter<GroundItem> b = item -> (item.getName().contains("Tokkul") && item.getAmount() > tokkulloot && getMap().realDistance(item) < 7 ); GroundItem tokkul = getGroundItems().closest(b); return tokkul; } I.e this only returns the tokkul is there if you could also add a getMap().canReach(item), this means if you can't reach it it won't return as true getMap().realDistance(item) < 7 Quote Link to comment Share on other sites More sharing options...
scriptersteve Posted February 8, 2018 Share Posted February 8, 2018 if(g.getName().equals(P2PLoot[i])&&g !=null){ change to: if(g.getName().equals(P2PLoot[i])&&g !=null && getMap().canReach(g) && getMap().realDistance(g) < ARBITRARY NUMBER say 7){ Then if you wanted you can do if your g = null (so you prioritise looting stuff nearer to your character) walk to items further away and loot them When sleeping - your using static sleeps: Below is a way of randomising that sleep time - just makes it a tad less botlike try{ sleep(random(300,600)); } catch(Exception e){ } Quote Link to comment Share on other sites More sharing options...
liverare Posted February 9, 2018 Share Posted February 9, 2018 (edited) You can test whether the tile is reachable, which can found here. You should definitely separate out your logic, because you're looking for items and, whilst in the midst of doing that, are re-checking whether you're in danger. You don't/shouldn't do that. You should check whether you're in danger first then find those items: IF IN DANGER GO AND RECOVER ELSE IF FOUND ITEMS LOOT ITEMS ELSE WAIT FOR ITEMS I'm not going to write your entire script, but I will help you find items: private boolean isGroundItemSomethingWeWant(GroundItem item) { boolean yes = false; String itemName = item.getName(); for (String name : P2PLoot) { if (itemName.equals(name)) { yes = true; break; } } return yes; } Then you can do this: List<GroundItem> items = groundItems.getAll().stream() .filter(this::isGroundItemSomethingWeWant) .filter(map::canReach) .collect(Collectors.toList()); Edited February 9, 2018 by liverare Quote Link to comment Share on other sites More sharing options...