Jump to content
View in the app

A better way to browse. Learn more.

OSBot :: 2007 OSRS Botting

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Get closest bank!

Featured Replies

Hello,

 

is there any way to get the closest bank starting from your current location?

  • Author

Use the webwalker.

 

Just input all the locations of the bank and it will walk towards the closest one ^^

 

So I make a list of all banks, put them into getWalker.webwalk(list) and he will walk to the closest one?

Hello,

 

is there any way to get the closest bank starting from your current location?

 

Taken from my Stealth Quester's API:

public static Position getClosestBank(API api) {
	ArrayList<BankEntry> banks = new ArrayList<BankEntry>();
	for (Bank bank : Bank.values()) {
		if (!api.worlds.isMembersWorld() && !bank.isF2P)
			continue;
		List<IDirection> directions = api.finder.route(api, api.myPosition(), bank.walkablePosition);
		if (directions != null) {
			banks.add(new BankEntry(bank.walkablePosition, bank, directions.size()));
		}
	}
	banks.sort(new Comparator<BankEntry>() {
		public int compare(BankEntry entry1, BankEntry entry2) {
		        return entry1.directions - entry2.directions;
	        }
	});
	if (banks.size() > 0) {
		Bank closestBank = banks.get(0).bank;
		api.log("[DEBUG][BANKING] Closest bank is: " + closestBank + " " + banks.get(0).walkablePosition);
		return banks.get(0).walkablePosition;
	} else {
		return null;
	}
}

As you may notice this actually finds the closest bank based on webwalking paths and NOT PLAIN DISTANCE. The banks are associated "walkable" positions so it only polls those positions making the algorithm run a lot faster. This method may take up to ~15 seconds to execute if you poll all positions in every bank so I strongly advise you to do it like I did with the walkablePosition when defining the Bank enum.

public static class BankEntry {
	public BankEntry(Position walkablePosition, Bank bank, int directions) {
		this.walkablePosition = walkablePosition;
		this.bank = bank;
		this.directions = directions;
	}

	Position walkablePosition;
	Bank bank;
	int directions;
		
}

The BankEntry class was defined for the sake of being a data structure (as I'm used to lower level programming languages), you may find more "OOP" implementations for this or you can just remove the class altogether and do the data mapping inside that method.

 

 

EDIT: The purpose of this method is to actually find the closest bank without being forced to walk to it. You may walk to it if you want as the returned position is guaranteed to be accessible by the webwalker.

Edited by Token

Hello,

 

is there any way to get the closest bank starting from your current location?

 

If you just want to walk there then the simplest method is:

private final Area[] BANKS = { Banks.AL_KHARID, Banks.ARDOUGNE_NORTH }; // add the rest

public void walkToClosestBank(){
    getWalking().webWalk(BANKS);
}

Without using web walking (not accurate if you have banks close to each other):

 

banks.sort(new Comparator<Area>() {
            public int compare(Area bank1, Area bank2) {
                return bank1.getRandomPosition().distance(myPosition()) - bank2.getRandomPosition().distance(myPosition());
            }
        });
First index in the collection will be to your closest position, last would be furthest. 

This isn't 100% accurate though, what if you gto a ring of duelling and you are almost in the varrock?

It should return CW instead of varrock bcs its faster ^^

 

If you input an array of positions from the banks the webwalker will calculate the fastest route to a bank.

I agree, Web would be ideal, i think i wrote that before the web even came out. So yeah it doesn't calculate the path heuristics. 

Taken from my Stealth Quester's API:

public static Position getClosestBank(API api) {
	ArrayList<BankEntry> banks = new ArrayList<BankEntry>();
	for (Bank bank : Bank.values()) {
		if (!api.worlds.isMembersWorld() && !bank.isF2P)
			continue;
		List<IDirection> directions = api.finder.route(api, api.myPosition(), bank.walkablePosition);
		if (directions != null) {
			banks.add(new BankEntry(bank.walkablePosition, bank, directions.size()));
		}
	}
	banks.sort(new Comparator<BankEntry>() {
		public int compare(BankEntry entry1, BankEntry entry2) {
		        return entry1.directions - entry2.directions;
	        }
	});
	if (banks.size() > 0) {
		Bank closestBank = banks.get(0).bank;
		api.log("[DEBUG][BANKING] Closest bank is: " + closestBank + " " + banks.get(0).walkablePosition);
		return banks.get(0).walkablePosition;
	} else {
		return null;
	}
}

As you may notice this actually finds the closest bank based on webwalking paths and NOT PLAIN DISTANCE. The banks are associated "walkable" positions so it only polls those positions making the algorithm run a lot faster. This method may take up to ~15 seconds to execute if you poll all positions in every bank so I strongly advise you to do it like I did with the walkablePosition when defining the Bank enum.

public static class BankEntry {
	public BankEntry(Position walkablePosition, Bank bank, int directions) {
		this.walkablePosition = walkablePosition;
		this.bank = bank;
		this.directions = directions;
	}

	Position walkablePosition;
	Bank bank;
	int directions;
		
}

The BankEntry class was defined for the sake of being a data structure (as I'm used to lower level programming languages), you may find more "OOP" implementations for this or you can just remove the class altogether and do the data mapping inside that method.

 

 

EDIT: The purpose of this method is to actually find the closest bank without being forced to walk to it. You may walk to it if you want as the returned position is guaranteed to be accessible by the webwalker.

best snippet 2k16

Taken from my Stealth Quester's API:

public static Position getClosestBank(API api) {
	ArrayList<BankEntry> banks = new ArrayList<BankEntry>();
	for (Bank bank : Bank.values()) {
		if (!api.worlds.isMembersWorld() && !bank.isF2P)
			continue;
		List<IDirection> directions = api.finder.route(api, api.myPosition(), bank.walkablePosition);
		if (directions != null) {
			banks.add(new BankEntry(bank.walkablePosition, bank, directions.size()));
		}
	}
	banks.sort(new Comparator<BankEntry>() {
		public int compare(BankEntry entry1, BankEntry entry2) {
		        return entry1.directions - entry2.directions;
	        }
	});
	if (banks.size() > 0) {
		Bank closestBank = banks.get(0).bank;
		api.log("[DEBUG][BANKING] Closest bank is: " + closestBank + " " + banks.get(0).walkablePosition);
		return banks.get(0).walkablePosition;
	} else {
		return null;
	}
}

As you may notice this actually finds the closest bank based on webwalking paths and NOT PLAIN DISTANCE. The banks are associated "walkable" positions so it only polls those positions making the algorithm run a lot faster. This method may take up to ~15 seconds to execute if you poll all positions in every bank so I strongly advise you to do it like I did with the walkablePosition when defining the Bank enum.

public static class BankEntry {
	public BankEntry(Position walkablePosition, Bank bank, int directions) {
		this.walkablePosition = walkablePosition;
		this.bank = bank;
		this.directions = directions;
	}

	Position walkablePosition;
	Bank bank;
	int directions;
		
}

The BankEntry class was defined for the sake of being a data structure (as I'm used to lower level programming languages), you may find more "OOP" implementations for this or you can just remove the class altogether and do the data mapping inside that method.

 

 

EDIT: The purpose of this method is to actually find the closest bank without being forced to walk to it. You may walk to it if you want as the returned position is guaranteed to be accessible by the webwalker.

Sorry if this is grave digging but Im using this method and it's so fucking good

Would donate my organs to Token!!@!@@!

  • 4 weeks later...

Some dank Java 8:

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),
		    TZHAAR(Banks.TZHAAR);

		    private final Area area;

		    Bank(Area area) {
		        this.area = area;
		    }
		}

		public static Area closestTo(lemons.api.script.entities.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;
		}
----------------------------------------------------------------------------------------------------------------
WebWalk.walk(closestTo(myPlayer());

Edited by LoudPacks

Create an account or sign in to comment

Recently Browsing 0

  • No registered users viewing this page.

Account

Navigation

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.