Jump to content

Adding a bank failsafe


Recommended Posts

Posted

I've edited a script to do what I like, but sometimes when it walks back to the bank tile it'll stand idle until I move my character, where it'll then interact with the bank chest. My bank code is as follows:

public void handleBank() throws InterruptedException {
    if (!getBank().isOpen()){ //If the bank is not open
        getBank().open(); //Opens bank chests, booths, etc.
        if (getBank().isOpen()) {
            getBank().depositAll();
            if (getBank().close()) {
                Sleep.sleepUntil(() -> !getBank().isOpen(), 4000);
            }
        }
    }
}

 

I know nothing about scripting but I'd like to add some sort of failsafe to re-check it can use the bank chest somehow?

Posted (edited)
19 minutes ago, Gunman said:

@UkBenHNeed more code, and post it on https://pastebin.com/ 

EDIT: Also the if's are nested and will get stuck if the bank is already open

https://pastebin.com/M3QpyfX3

 

This is the full thing. I had to change the bank method to use the chest that's nearby as it was set up to use a depositbox. Now sometimes it'll walk to the bank area and stand idle 

 

Edit: It idles when you run out of energy mid-way to the bank

Edited by UkBenH
Posted
4 minutes ago, UkBenH said:

https://pastebin.com/M3QpyfX3

 

This is the full thing. I had to change the bank method to use the chest that's nearby as it was set up to use a depositbox. Now sometimes it'll walk to the bank area and stand idle 

My guess is it's getting stuck because of web walking. Web walking by default will complete if a tile off. But I would just change the position to an area which I think the same area you're walking to is in the Banks API. I would probably restructure it like this
 

private void handleBank() throws InterruptedException {
    if (getBank().isOpen()) {
        currentState = "Depositing";
        if (getBank().depositAll()) {
            Sleep.sleepUntil(() -> getInventory().isEmpty(), 4000);
        }
    } else if (!getBank().open()) {
        currentState = "Navigating to bank";
        getWalking().webWalk(Banks.HOSIDIUS_HOUSE);
    }
}

And the first if in the onLoop I would change to just this

if (getInventory().isFull()) {
    handleBank();
}

If Banks.HOSIDIUS_HOUSE isn't the right location create an area where yours is.

  • Heart 1
Posted
2 hours ago, Gunman said:

My guess is it's getting stuck because of web walking. Web walking by default will complete if a tile off. But I would just change the position to an area which I think the same area you're walking to is in the Banks API. I would probably restructure it like this
 


private void handleBank() throws InterruptedException {
    if (getBank().isOpen()) {
        currentState = "Depositing";
        if (getBank().depositAll()) {
            Sleep.sleepUntil(() -> getInventory().isEmpty(), 4000);
        }
    } else if (!getBank().open()) {
        currentState = "Navigating to bank";
        getWalking().webWalk(Banks.HOSIDIUS_HOUSE);
    }
}

And the first if in the onLoop I would change to just this


if (getInventory().isFull()) {
    handleBank();
}

If Banks.HOSIDIUS_HOUSE isn't the right location create an area where yours is.

Thank you - this helped!

  • Heart 1
Posted
10 minutes ago, UkBenH said:

Thank you - this helped!

In addition to what @Gunman said you can do .getRandomPosition() so that when walking to the bank it will be random every time.

getWalking().webWalk(Banks.HOSIDIUS_HOUSE.getRandomPosition());

You can also use the Bank class to open the bank with a method called .open(). You can read more about that here in the OSBot API Docs.

Quote

Searches for the best bank, based on type and distance from player. This method will only interact with RS2Objects.

 

  • Like 2
Posted
3 hours ago, ExtraBotz said:

In addition to what @Gunman said you can do .getRandomPosition() so that when walking to the bank it will be random every time.


getWalking().webWalk(Banks.HOSIDIUS_HOUSE.getRandomPosition());

You can also use the Bank class to open the bank with a method called .open(). You can read more about that here in the OSBot API Docs.

 

Thank you. I literally just knew how to change the areas it was using; but I'm trying to pick things up. Appreciate your comment.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...