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.

getNearestBank();

Featured Replies

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 :)

I made the same 2 days ago ohmy.png

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;
	}

}

  • 2 weeks later...

the enum is entirely redundant

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 by lisabe96

  • 3 weeks later...

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!

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 smile.png

 

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 by Explv

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)

  • 2 years later...

why doesnt this work?

getWalking().webWalk(bank);

Untitled.png.4cd3ccb9f606d9ecee2f34ee0106a5ea.png

its not recognizing the "bank" from WebBank enum?

On 6/17/2018 at 2:48 PM, alkku15 said:

why doesnt this work?


getWalking().webWalk(bank);

Untitled.png.4cd3ccb9f606d9ecee2f34ee0106a5ea.png

its not recognizing the "bank" from WebBank enum?

Because it's not an Area or a Position

But it has a getArea method.

Edited by FrostBug

  • 1 year later...
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.

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.

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.