Pyth 127 Share Posted July 17, 2017 This is just a small snippet to get the closest Area from where your player is at any location, we will be using banks as an example but you could implement this method into anything that uses areas. I haven't seen this posted anywhere so I'll provide my method using HashMaps ClosestBank Class import org.dreambot.api.methods.map.Area; import org.dreambot.api.wrappers.interactive.Entity; import java.util.HashMap; import java.util.LinkedHashMap; import java.util.Map; import java.util.stream.Stream; public class ClosestBank { private Area lumbridgeBank = new Area(3210, 3218, 3207, 3220,2); private Area alKharidBank = new Area(3269, 3173, 3272, 3161); private Area varrockEastBank = new Area(3257, 3424, 3250, 3419); private Area varrockWestBank = new Area(3180, 3447, 3185, 3433); private Area grandExchange = new Area(3160, 3493, 3169, 3483); private Area edgevillageBank = new Area(3098, 3499, 3091, 3488); private Area draynorBank = new Area(3097, 3246, 3092, 3240); private Area faladorBank = new Area(3009, 3358, 3021, 3355); private Area catherbyBank = new Area(2812, 3445, 2806, 3438); private Area seersBank = new Area(2721, 3493, 2730, 3490); private Area adrougneNorthBank = new Area(2621, 3335, 2612, 3330); private Area adrougneSouthBank = new Area(2656, 3287, 2649, 3280); private Area barbAssualt = new Area(2538, 3579, 2529, 3560); private Area yanilleBank = new Area(2616, 3097, 2609, 3088); private Area castleWarsBank = new Area(2437, 3091, 2445, 3081); private Area shiloVillageBank = new Area(2849, 2957, 2855, 2951); private Area canafisBank = new Area(3516, 3483, 3508, 3474); private Area[] bankArea = {lumbridgeBank,alKharidBank,varrockEastBank,varrockWestBank,grandExchange,edgevillageBank,draynorBank,faladorBank,catherbyBank,seersBank,adrougneNorthBank,adrougneSouthBank,barbAssualt,yanilleBank,castleWarsBank,shiloVillageBank,canafisBank}; public Area getClosestBank(Entity e) { HashMap<Area, Integer> distMap = new HashMap<>(); for (Area b : bankArea) { distMap.put(b, (int) e.getTile().distance(b.getRandomTile())); } HashMap<Integer, Area> distMapSorted = sortByDistance(distMap); Area cBank = distMapSorted.values().toArray(new Area[bankArea.length])[0]; 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; } } How to call ClosestBank b = new ClosestBank(); Area closestBankArea = b.getClosestBank(getLocalPlayer()); How to walk an Area getWalking().walk(closestBankArea.getRandomTile()); Link to comment Share on other sites More sharing options...
Manly 879 Share Posted July 17, 2017 Or use getBank().getClosestBankLocation() Link to comment Share on other sites More sharing options...
Pyth 127 Author Share Posted July 17, 2017 Or use getBank().getClosestBankLocation() That does work but I wanted to add unsupported locations which is why I made the method, also you're able to get closest Areas with this not just banks. You can also filter out banks if you don't meet requirements to use them. Link to comment Share on other sites More sharing options...
Dorkinator 64 Share Posted July 17, 2017 That does work but I wanted to add unsupported locations which is why I made the method, also you're able to get closest Areas with this not just banks. You can also filter out banks if you don't meet requirements to use them. I think you can already add new web banks. EDIT: Just kidding it's a fucking enum. https://dreambot.org/forums/index.php/topic/11015-can-web-banks-not-be-an-enum-please/ Link to comment Share on other sites More sharing options...
Nex 2542 Share Posted July 17, 2017 If you leech that"s fine, but at least give the credit the creator. Credits to: Loudpacks (anther bot forum user.) Link to comment Share on other sites More sharing options...
hexagon 18 Share Posted July 17, 2017 m8 y u abuse maps Link to comment Share on other sites More sharing options...
Pyth 127 Author Share Posted July 17, 2017 If you leech that"s fine, but at least give the credit the creator. Credits to: Loudpacks (anther bot forum user.) Adapted from Enums and Banks, thanks Loudpacks! Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.