N O Special Posted January 6, 2016 Posted January 6, 2016 Couldn't seem to find a method to get nearest bank, and all the Banks were constants... So i threw them into an enum class and made a method to get nearest bank: public enum WebBank { 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), TZHAAR(Banks.TZHAAR); private final Area area; WebBank(Area area) { this.area = area; } public static WebBank getNearest(Script script) { WebBank bank = null; int distance = Integer.MAX_VALUE; for (WebBank b : WebBank.values()) { final int bDistance = b.area.getRandomPosition().distance(script.myPosition()); if (bDistance < distance) { distance = bDistance; bank = b; } } return bank; } public Position getRandomPosition() { return area.getRandomPosition(); } public Area getArea() { return area; } } have fun 3
lisabe96 Posted January 6, 2016 Posted January 6, 2016 I made the same 2 days ago package rqai.utilities; import org.osbot.rs07.api.map.Area; import org.osbot.rs07.api.map.Position; import org.osbot.rs07.api.map.constants.Banks; import org.osbot.rs07.script.Script; /** * * @author randqm * * Represents a bank. * */ public enum Bank { LUMBRIDGE(new Area(new Position(3207, 3220, 0), new Position(3210, 3218, 0))), VARROCK_WEST(Banks.VARROCK_WEST), VARROCK_EAST(Banks.VARROCK_EAST), GRAND_EXCHANGE(new Area(new Position(3162, 3486, 0), new Position(3168, 3493, 0))), DRAYNOR(Banks.DRAYNOR), EDGEVILLE(Banks.EDGEVILLE), SEERS(Banks.CAMELOT); /* The area of the bank. */ private final Area area; /** * Creates a new bank. * * @param area The area of the bank. */ private Bank(Area area) { this.area = area; } /** * Retrieves the area of the bank. * * @return The bank's area. */ public Area getArea() { return area; } /** * Retrieves the closest bank. * * @param script The script. * * @return The closest bank found. */ public static Bank getClosestBank(Script script) { Bank closest = null; for (Bank bank : values()) { if (closest == null || bank.getArea().getRandomPosition().distance(script.myPosition()) < closest.getArea().getRandomPosition().distance(script.myPosition())) { closest = bank; } } return closest; } }
lisabe96 Posted January 19, 2016 Posted January 19, 2016 (edited) the enum is entirely redundant Not at all as not all banks are in the API and some are a bit off. But I read that the next API update will have those fixed Edit: well right now in OP's case it is indeed Edited January 19, 2016 by lisabe96
wallnuts5 Posted February 7, 2016 Posted February 7, 2016 Please excuse my ignorance (only written 2 scripts ever) but to run this I understand I need to call WebBank.getNearest(x); but what do I put in for x? Do I put in (Script name_of_my_script)? Thanks in advance!
Explv Posted February 7, 2016 Posted February 7, 2016 (edited) Couldn't seem to find a method to get nearest bank, and all the Banks were constants... So i threw them into an enum class and made a method to get nearest bank: public static WebBank getNearest(Script script) { WebBank bank = null; int distance = Integer.MAX_VALUE; for (WebBank b : WebBank.values()) { final int bDistance = b.area.getRandomPosition().distance(script.myPosition()); if (bDistance < distance) { distance = bDistance; bank = b; } } return bank; } have fun This is not correct though, as the distance between two positions is not the same as walking distance. Therefore it can easily return a bank that is further away, as it is closer, but the route is longer. Also if you are in a dungeon it will return an incorrect bank due to the way the map is laid out. Edited February 7, 2016 by Explv 1
Bobrocket Posted February 10, 2016 Posted February 10, 2016 This is not correct though, as the distance between two positions is not the same as walking distance. Therefore it can easily return a bank that is further away, as it is closer, but the route is longer. Also if you are in a dungeon it will return an incorrect bank due to the way the map is laid out. Correct. This is the use of a heuristic. To know the actual lengths, you'd need to pathfind every node. However, a heuristic uses a lot less resources and is typically accurate. (In the case of OSRS, can be very very bad due to dungeon layout like you said) 1
alkku15 Posted June 17, 2018 Posted June 17, 2018 why doesnt this work? getWalking().webWalk(bank); its not recognizing the "bank" from WebBank enum?
FrostBug Posted June 20, 2018 Posted June 20, 2018 (edited) On 6/17/2018 at 2:48 PM, alkku15 said: why doesnt this work? getWalking().webWalk(bank); its not recognizing the "bank" from WebBank enum? Because it's not an Area or a Position But it has a getArea method. Edited June 20, 2018 by FrostBug
Jonathan Katz Posted February 2, 2020 Posted February 2, 2020 On 2/6/2016 at 10:45 PM, wallnuts5 said: Please excuse my ignorance (only written 2 scripts ever) but to run this I understand I need to call WebBank.getNearest(x); but what do I put in for x? Do I put in (Script name_of_my_script)? Thanks in advance! i really wish this question was answered and not overlooked.
Camaro Posted February 3, 2020 Posted February 3, 2020 22 hours ago, Jonathan Katz said: i really wish this question was answered and not overlooked. If you're calling the method in onLoop(), it would be 'this' (Main extends Script) Although passing the script instance is bad practice... and I would suggest against using this due to the comments from above. You can pass multiple areas to the webWalker and it will automatically choose the closest.