Lewis Posted December 1, 2016 Posted December 1, 2016 (edited) looking for my script to run to the closest bank, but i dont know how to get if closest bank contains myplayer code is: private final Area[] BANKS = { (Banks.DRAYNOR), (Banks.AL_KHARID), (Banks.LUMBRIDGE_UPPER), (Banks.FALADOR_EAST), (Banks.FALADOR_WEST), (Banks.FALADOR_EAST), (Banks.VARROCK_WEST), (Banks.CAMELOT), (Banks.CATHERBY), (Banks.EDGEVILLE), (Banks.YANILLE), (Banks.GNOME_STRONGHOLD), (Banks.ARDOUGNE_NORTH), (Banks.ARDOUGNE_SOUTH), (Banks.CASTLE_WARS), (Banks.DUEL_ARENA), (Banks.PEST_CONTROL), (Banks.CANIFIS), (Banks.TZHAAR)}; && if (!BANKS.contains(myPlayer())) { walking.webWalk(BANKS); sleep(random(250, 300)); Edited December 1, 2016 by Lewis
Saiyan Posted December 1, 2016 Posted December 1, 2016 make a webwalk event and throw all the banks into the webwalk event and it'll walk to the closest one (this is the solution for walking to the closest bank)
Vilius Posted December 1, 2016 Posted December 1, 2016 (edited) List<Area> closestArea = new ArrayList<Area>(); closestArea.add(Banks.AL_KHARID); closestArea.sort(new Comparator<Area>() { public int compare(Area entry1, Area entry2) { return entry1.getRandomPosition().distance(myPlayer()) - entry2.getRandomPosition().distance(myPlayer()); } }); getWalking().webWalk(closestArea.get(0)); if(!closestArea.get(0).contains(myPlayer()) getWalking().webWalk(closestArea.get(0)); here you go man, just add more banks to the ArrayList closestArea.get(0) returns the closest area. Edited December 1, 2016 by Vilius
Explv Posted December 1, 2016 Posted December 1, 2016 (edited) looking for my script to run to the closest bank, but i dont know how to get if closest bank contains myplayer code is: private final Area[] BANKS = { (Banks.DRAYNOR), (Banks.AL_KHARID), (Banks.LUMBRIDGE_UPPER), (Banks.FALADOR_EAST), (Banks.FALADOR_WEST), (Banks.FALADOR_EAST), (Banks.VARROCK_WEST), (Banks.CAMELOT), (Banks.CATHERBY), (Banks.EDGEVILLE), (Banks.YANILLE), (Banks.GNOME_STRONGHOLD), (Banks.ARDOUGNE_NORTH), (Banks.ARDOUGNE_SOUTH), (Banks.CASTLE_WARS), (Banks.DUEL_ARENA), (Banks.PEST_CONTROL), (Banks.CANIFIS), (Banks.TZHAAR)}; && if (!BANKS.contains(myPlayer())) { walking.webWalk(BANKS); sleep(random(250, 300)); Consider reading this tutorial on Arrays: https://docs.oracle.com/javase/tutorial/java/nutsandbolts/arrays.html Edited December 1, 2016 by Explv 2
Lewis Posted December 1, 2016 Author Posted December 1, 2016 make a webwalk event and throw all the banks into the webwalk event and it'll walk to the closest one (this is the solution for walking to the closest bank) need to figure out how to return true if for example: GE is closest, bank, it walks to ge // i got working then if GE contains myplayer { w.e *GE will be closest bank
Explv Posted December 1, 2016 Posted December 1, 2016 need to figure out how to return true if for example: GE is closest, bank, it walks to ge // i got working then if GE contains myplayer { w.e *GE will be closest bank All you need to do is check if any of the Areas in the Area[] contain your Position. I'll give you a hint, you might want to use a for loop: https://docs.oracle.com/javase/tutorial/java/nutsandbolts/for.html 2
Acerd Posted December 1, 2016 Posted December 1, 2016 need to figure out how to return true if for example: GE is closest, bank, it walks to ge // i got working then if GE contains myplayer { w.e *GE will be closest bank Consider reading this tutorial on Arrays: https://docs.oracle.com/javase/tutorial/java/nutsandbolts/arrays.html
Lewis Posted December 1, 2016 Author Posted December 1, 2016 (edited) Doesn't seem like you saw my post. List<Area> closestArea = new ArrayList<Area>(); closestArea.add(Banks.AL_KHARID); closestArea.add(Banks.DRAYNOR); closestArea.add(Banks.VARROCK_WEST); closestArea.sort(new Comparator<Area>() { public int compare(Area entry1, Area entry2) { return entry1.getRandomPosition().distance(myPlayer()) entry2.getRandomPosition().distance(myPlayer()); } }); getWalking().webWalk(closestArea.get(0)); if(!closestArea.get(0).contains(myPlayer()) getWalking().webWalk(closestArea.get(0)); just add more closestArea.add(Banks.DRAYNOR); ? or do i need to add, entry 1,2,3,4 etc also? Edited December 1, 2016 by Lewis
Vilius Posted December 1, 2016 Posted December 1, 2016 List<Area> closestArea = new ArrayList<Area>(); closestArea.add(Banks.AL_KHARID); closestArea.add(Banks.DRAYNOR); closestArea.add(Banks.VARROCK_WEST); closestArea.sort(new Comparator<Area>() { public int compare(Area entry1, Area entry2) { return entry1.getRandomPosition().distance(myPlayer()) entry2.getRandomPosition().distance(myPlayer()); } }); getWalking().webWalk(closestArea.get(0)); if(!closestArea.get(0).contains(myPlayer()) getWalking().webWalk(closestArea.get(0)); just add more closestArea.add(Banks.DRAYNOR); ? or do i need to add, entry 1,2,3,4 etc also? Just do closestArea.add(...); no need to make more sorters.
Lewis Posted December 1, 2016 Author Posted December 1, 2016 Just do closestArea.add(...); no need to make more sorters. done like so: List<Area> closestArea = new ArrayList<Area>(); @[member=Override] public void onStart() { gui = new GUI(); closestArea.add(Banks.AL_KHARID); closestArea.add(Banks.DRAYNOR); closestArea.add(Banks.VARROCK_WEST); closestArea.sort(new Comparator<Area>() { public int compare(Area entry1, Area entry2) { return entry1.getRandomPosition().distance(myPlayer()) entry2.getRandomPosition().distance(myPlayer()); } }); } although on line : return entry1.getRandomPosition().distance(myPlayer()) entry2.getRandomPosition().distance(myPlayer()); it wants me to insert ; to complete the block (if i do insert ; then entry 2 gets full error)
Vilius Posted December 1, 2016 Posted December 1, 2016 (edited) done like so: List<Area> closestArea = new ArrayList<Area>(); @[member='Override'] public void onStart() { gui = new GUI(); closestArea.add(Banks.AL_KHARID); closestArea.add(Banks.DRAYNOR); closestArea.add(Banks.VARROCK_WEST); closestArea.sort(new Comparator<Area>() { public int compare(Area entry1, Area entry2) { return entry1.getRandomPosition().distance(myPlayer()) entry2.getRandomPosition().distance(myPlayer()); } }); } although on line : return entry1.getRandomPosition().distance(myPlayer()) entry2.getRandomPosition().distance(myPlayer()); it wants me to insert ; to complete the block (if i do insert ; then entry 2 gets full error) oops should be: return entry1.getRandomPosition().distance(myPlayer()) - entry2.getRandomPosition().distance(myPlayer()); you should only add the banks in on start, then sort the array list when you want to walk or do something. Edited December 1, 2016 by Vilius
Lewis Posted December 1, 2016 Author Posted December 1, 2016 oops should be: return entry1.getRandomPosition().distance(myPlayer()) - entry2.getRandomPosition().distance(myPlayer()); you should only add the banks in on start, then sort the array list when you want to walk or do something. thank you no error, ill let you know how it works
Explv Posted December 1, 2016 Posted December 1, 2016 (edited) oops should be: return entry1.getRandomPosition().distance(myPlayer()) - entry2.getRandomPosition().distance(myPlayer()); you should only add the banks in on start, then sort the array list when you want to walk or do something. Why would you sort the Areas to determine if you are in the closest bank? Just loop over the Area[]... if you are in one of the Areas, guess what? You are in the closest bank. To walk to the closest bank you can just call getWalking().webWalk(bankAreas) Edited December 1, 2016 by Explv
Vilius Posted December 1, 2016 Posted December 1, 2016 (edited) Why would you sort the Areas to determine if you are in the closest bank? Just loop over the Area[]... if you are in one of the Areas, guess what? You are in the closest bank. To walk to the closest bank you just call getWalking().webWalk(bankAreas) Ofcourse, you can do that too, I'm not judging. I just find sorting the areas to be more useful rather than just iterating through them. And for the new guy it will be easier to understand boolean logic, I guess. Albeit this snippet I posted was for closest position finding from an array list, but it works for areas too, more versatile I suppose. Edited December 1, 2016 by Vilius
Chris Posted December 1, 2016 Posted December 1, 2016 private enum Bank { DRAYNOR(Banks.DRAYNOR), AL_KHARID(Banks.AL_KHARID), LUMBRIDGE(Banks.LUMBRIDGE_UPPER), FALADOR_EAST(Banks.FALADOR_EAST), FALADOR_WEST(Banks.FALADOR_WEST), VARROCK_EAST(Banks.FALADOR_EAST), VARROCK_WEST(Banks.VARROCK_WEST), SEERS(Banks.CAMELOT), CATHERBY(Banks.CATHERBY), EDGEVILLE(Banks.EDGEVILLE), YANILLE(Banks.YANILLE), GNOME_STRONGHOLD(Banks.GNOME_STRONGHOLD), ARDOUNGE_NORTH(Banks.ARDOUGNE_NORTH), ARDOUNE_SOUTH(Banks.ARDOUGNE_SOUTH), CASTLE_WARS(Banks.CASTLE_WARS), DUEL_ARENA(Banks.DUEL_ARENA), PEST_CONTROL(Banks.PEST_CONTROL), CANIFIS(Banks.CANIFIS), BLAST_FURNACE(new Area(1949, 4956, 1947, 4958)), TZHAAR(Banks.TZHAAR); private final Area area; Bank(Area area) { this.area = area; } } public static Area closestTo(Entity e) { HashMap<Bank, Integer> distMap = new HashMap<Bank, Integer>(); for (Bank b : Bank.values()) { distMap.put(b, e.getPosition().distance(b.area.getRandomPosition())); } HashMap<Integer, Bank> distMapSorted = sortByDistance(distMap); Area cBank = distMapSorted.values().toArray(new Bank[Bank.values().length])[0].area; return cBank; } private static <K, V extends Comparable<? super V>> HashMap<V, K> sortByDistance(Map<K, V> map) { HashMap<V, K> result = new LinkedHashMap<>(); Stream<Map.Entry<K, V>> st = map.entrySet().stream(); st.sorted(Map.Entry.comparingByValue()).forEachOrdered(e -> result.put(e.getValue(), e.getKey())); return result; } @LP