Jump to content

Not withdrawing from bank properly


xVirtus

Recommended Posts

Hello, im quite new to writing these scripts, and just been messing with it this evening.

I quickly stumbled into a problem when trying to script selling an item to the grand exchange, and i could not find any example on how to do this, so i experimented.

 

My issue is, that an item does not get withdrawn from the bank properly, because of lack of sleeps or whatever, im not completely sure. 

 

if (!getBank().isOpen()) {
            getBank().open();
            getBank().enableMode(Bank.BankMode.WITHDRAW_NOTE);
        } else if (getBank().contains("Kebab")) {
            Sleep.sleepUntil(() -> (getBank().withdrawAll("Kebab")), 5000);
            getBank().close();
        }


        NPC geClerk = npcs.closest("Grand Exchange Clerk");

        if (geClerk != null) {
            Sleep.sleepUntil(() -> (geClerk.interact("Exchange")), 5000);
        }

 

If i have the code above, the kebabs will not be withdrawn when i have the geClerk interact line. Without it, it gets withdrawn fine, but with that line, it skips over the withdrawal and instantly opens the GE window instead. 

 

Hope i explained my issue well enough, and someone can give a helping hand.

(if anyone has a code snippet that just grabs whatever item in a Note and lists it on GE for insta-sell price then that would be perfect too)

 

Edited by xVirtus
Link to comment
Share on other sites

Before opening the ge you should also check to see if you have the kebabs. Also the sleep you are doing when you open the ge will end before it is open since you are just waiting for the click. You should change it to wait until the ge is open. Example

If (geClerk != null && geClerk.interact("Exchange")

Sleep.sleepUntil(() -> getGrandExchange().isOpen());

Sorry for the formating, on my phone atm.

Edited by BravoTaco
  • Like 1
  • Heart 1
Link to comment
Share on other sites

of course, thanks for the help guys

 

@BravoTaco my next line in the code was actually to wait untill the GE was open, but i chose not to include that part in the example just to make it a bit clearer, but i didnt have the interact call in the if statement

Edited by xVirtus
Link to comment
Share on other sites

I tried doing this

if (!getBank().isOpen()) {
    getBank().open();
    getBank().enableMode(Bank.BankMode.WITHDRAW_NOTE);
} else if (getBank().contains("Kebab")) {
    getBank().withdrawAll("Kebab");
    Sleep.sleepUntil(() -> !getBank().contains("Kebab"),5000);
} else if(getInventory().contains("Kebab")){
        getBank().close();
}


NPC geClerk = npcs.closest("Grand Exchange Clerk");


if (geClerk != null && geClerk.interact("Exchange")) {
    Sleep.sleepUntil(() -> (getGrandExchange().isOpen()), 5000);
} else if (getGrandExchange().isOpen()){
    getGrandExchange().sellItem(1971, 1, (int) getInventory().getAmount("Kebab"));
    Sleep.sleepUntil(this::canCollect, 5000);
}

But it still skips over the withdrawal of the kebabs from the bank. It seems to skip over the 

Sleep.sleepUntil(() -> !getBank().contains("Kebab"),5000);

statement

Link to comment
Share on other sites

You need to check if the kebabs are in your inventory before opening the exchange i believe what is happening is that if the bank is not open than you open the bank and than run the next code that would be opening the exchange. So it closes out of the bank before grabbing the kebabs. So something like this.

If(getInventory().contains("kebabs") && geClerk != null && geClerk.interact("Exchange"))

Take note of the order of which you are checking as well. If the check for null and the check for the ininteraction is before the kebabs it will still exit the bank and try to interact with the clerk.

Again sorry for the formating still only have access to my phone atm.

Edited by BravoTaco
Link to comment
Share on other sites

33 minutes ago, BravoTaco said:

You need to check if the kebabs are in your inventory before opening the exchange i believe what is happening is that if the bank is not open than you open the bank and than run the next code that would be opening the exchange. So it closes out of the bank before grabbing the kebabs. So something like this.

If(getInventory().contains("kebabs") && geClerk != null && geClerk.interact("Exchange"))

Take note of the order of which you are checking as well. If the check for null and the check for the ininteraction is before the kebabs it will still exit the bank and try to interact with the clerk.

Again sorry for the formating still only have access to my phone atm.

ah of course, i'm a bit new to "async" programming like this botting API stuff, so i appreciate the help :). It does withdraw the kebabs without the GE code, which is why i was confused

Link to comment
Share on other sites

if (!getInventory().contains("Kebab")) {
	if (getBank().isOpen()) {
		getBank().enableMode(Bank.BankMode.WITHDRAW_NOTE);
			if (getBank().contains("Kebab")) {
				getBank().withdrawAll("Kebab");
					if (getBank().close()) {
						Sleep.sleepUntil(() -> !getBank().isOpen(), 9000);
					}
			}
		} else {
			if (getBank().open()) {
				Sleep.sleepUntil(() -> getBank().isOpen(), 9000);
			}
		}
		} else {
			NPC n = npcs.closest("Grand Exchange Clerk");
				if (n != null) {
					if (n.interact("Exchange")) {
						Sleep.sleepUntil(() -> getGrandExchange().isOpen(), 9000);
					}
			}
	}

I'm sorry if its messy, dont got a IDE here to make it look clean 😛 CTRL + SHIFT + F on eclipse would clean this for u.

U can wrap around another boolean for if the grand exchange is open on this :)

 

 Sleep.sleepUntil(() -> (geClerk.interact("Exchange")), 5000);

Here u do a interact in a sleep, i dont think that is possible (or would be accepted as a good way of making scripts)

U dont need this code either:

 Sleep.sleepUntil(() -> !getBank().contains("Kebab"),5000);

OSBot's api will handle the wait with only the withdraw function  

 getBank().withdraw("Kebab"); is all u need

:)


Best of luck buddy! :)

-Rare.

Edited by Rare scripts
  • Heart 1
Link to comment
Share on other sites

9 minutes ago, Rare scripts said:

if (!getInventory().contains("Kebab")) {
	if (getBank().isOpen()) {
		getBank().enableMode(Bank.BankMode.WITHDRAW_NOTE);
			if (getBank().contains("Kebab")) {
				getBank().withdrawAll("Kebab");
					if (getBank().close()) {
						Sleep.sleepUntil(() -> !getBank().isOpen(), 9000);
					}
			}
		} else {
			if (getBank().open()) {
				Sleep.sleepUntil(() -> getBank().isOpen(), 9000);
			}
		}
		} else {
			NPC n = npcs.closest("Grand Exchange Clerk");
				if (n != null) {
					if (n.interact("Exchange")) {
						Sleep.sleepUntil(() -> getGrandExchange().isOpen(), 9000);
					}
			}
	}

I'm sorry if its messy, dont got a IDE here to make it look clean 😛 CTRL + SHIFT + F on eclipse would clean this for u.

U can wrap around another boolean for if the grand exchange is open on this :)

 


 Sleep.sleepUntil(() -> (geClerk.interact("Exchange")), 5000);

Here u do a interact in a sleep, i dont think that is possible (or would be accepted as a good way of making scripts)

Best of luck buddy! :)

-Rare.

I did something sort of like this, and that worked and i finally figured out how to work the GE too, so my script is fully working right now. Dont know if i should release it or whatever, its still lacking stuff that could be improved, but it works. Buys kebabs untill out of cash in inventory then sells it on the GE

This is what i ended up doing. Else-ifs were causing some errors, due to later statements would be executed out of order

if (!getBank().isOpen()) {
    getBank().open();
    if(!getInventory().isEmpty()) getBank().depositAll();
    getBank().enableMode(Bank.BankMode.WITHDRAW_NOTE);
}
if (getBank().contains("Kebab")) {
    getBank().withdrawAll("Kebab");
    Sleep.sleepUntil(() -> !getBank().contains("Kebab"),5000);
}
if(getInventory().contains("Kebab")){
        getBank().close();
}

instasell("Kebab");

 

 

private void instasell(String item){
    NPC geClerk = npcs.closest("Grand Exchange Clerk");

    if (getInventory().contains(item) && geClerk != null && geClerk.interact("Exchange")) {
        Sleep.sleepUntil(() -> (getGrandExchange().isOpen()), 5000);
    }

    if (getInventory().contains(item) && getGrandExchange().isOpen()){
        Sleep.sleepUntil(() -> getInventory().getItem(item).interact("Offer"), 5000);
 .....
Edited by xVirtus
  • Like 1
Link to comment
Share on other sites

3 minutes ago, xVirtus said:

I did something sort of like this, and that worked and i finally figured out how to work the GE too, so my script is fully working right now. Dont know if i should release it or whatever, its still lacking stuff that could be improved, but it works. Buys kebabs untill out of cash in inventory then sells it on the GE

This is what i ended up doing. Else-ifs were causing some errors, due to later statements would be executed out of order


if (!getBank().isOpen()) {
    getBank().open();
    if(!getInventory().isEmpty()) getBank().depositAll();
    getBank().enableMode(Bank.BankMode.WITHDRAW_NOTE);
}
if (getBank().contains("Kebab")) {
    getBank().withdrawAll("Kebab");
    Sleep.sleepUntil(() -> !getBank().contains("Kebab"),5000);
}
if(getInventory().contains("Kebab")){
        getBank().close();
}

instasell("Kebab");

 

 


private void instasell(String item){
    NPC geClerk = npcs.closest("Grand Exchange Clerk");

    if (getInventory().contains(item) && geClerk != null && geClerk.interact("Exchange")) {
        Sleep.sleepUntil(() -> (getGrandExchange().isOpen()), 5000);
    }

    if (getInventory().contains(item) && getGrandExchange().isOpen()){
        Sleep.sleepUntil(() -> getInventory().getItem(item).interact("Offer"), 5000);
 .....

U should always use else if statements, 

If i can help with anything else feel free to shoot me a PM on discord.

Link to comment
Share on other sites

Just now, Rare scripts said:

I had to read this over twice 😂
Can u try with my snippet? This never failed for me personally.

-Rare.

haha, basically i figured out that it would enter the last else if statement, before running the previous one when using else if, rather than if. I will try using your snippet later and see if it works the same. Then probrably keep using that later. Only been messing with this since last night, and already made a functioning kebab buyer with GE selling 😛 

  • Like 1
Link to comment
Share on other sites

1 minute ago, xVirtus said:

haha, basically i figured out that it would enter the last else if statement, before running the previous one when using else if, rather than if. I will try using your snippet later and see if it works the same. Then probrably keep using that later. Only been messing with this since last night, and already made a functioning kebab buyer with GE selling 😛 

Thats a great start buddy!! :D
Wish u all the best!


-Rare.

  • Heart 1
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...