Jump to content

Adding a bank failsafe


UkBenH

Recommended Posts

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?

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

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