Jump to content

Can't find the problem..


Sebastian

Recommended Posts

Hello everyone, how are you all doing?

 

Since the newest OSRS update last Thursday i have a little problem with my script.

 

The problem: 

 

Since the newest OSRS update last Thursday, my script doesn't run flawless anymore.

When i'm at the bank, it selects a bank, open's the bank and then presses the X button (close bank).

It does this for 2 times (or more) and then banks the willow logs. Kinda an EXP waste.

 

I have been editing a lot of things to my BANK case. But everything i do, it doesn't seem to fix the problem.

Eclipse gives no errors. And as i mentioned earlier: The script runned flawless before the OSRS update.

Now i'm kinda new to this, but i really want to proceed my scripting. Have tried to just ignore this problem, but it irritates me a lot that it doesn't do what i want it to do.

 

Java Version and OSbot version: 

 

* Java jdk1.8.0_65

* OSbot 2.4.5.

 

My CASE Bank:

case BANK:
			if (Willows.contains(myPlayer())) {
				if (inventory.isFull()) {
					walkPath(pathToBank);
				}
			} else {
				if (draynorBank.contains(myPlayer())) {
					Entity bankbooth = objects.closest(BANK_BOOTH_ID);

					if (bankbooth != null) {
							if (inventory.isFull()) {
								camera.toEntity(bankbooth);
								bankbooth.interact("Bank");
								sleep(random(500,700));
							}
					}
					if(bank.isOpen()) {
						sleep(random(500,700));
						bank.depositAll("Willow logs");
					}
				}
				if (draynorBank.contains(myPlayer()) && inventory.isEmpty() || draynorBank.contains(myPlayer()) && inventory.isEmptyExcept(1351, 1355, 1357, 1359, 6739)) {
					Entity Willowtrees = objects.closest(Willowtrees_ID);
					walkPath(pathToWillows);
					camera.toEntity(Willowtrees);
				}
			}
			break;

Hope you can help me with this. Its getting kinda anoying.

 

 

Sincerely your's,

 

 

Sebastian.

Link to comment
Share on other sites

The problem is pretty obvious if you think about it.

 

1. If the bank booth is not null, you interact with it.

 

2. After interacting with it, you immediately try to withdraw from it, in the case that the bank is open.

The bank however is in many cases not going to be open after 500 milliseconds after clicking, especially if there's distance between you and the object (which there will often be, since 'closest' method doesn't use manhattan distance).

 

3. In the case that the bank was not open after the 500 milliseconds, you try to interact with the bank booth again, but since you cannot interact with object while the bank widget is open, the interact method will close the bank before interacting.

 

^this repeats.

 

You should generally avoid doing multiple interactions in 1 loop cycle, and always evaluate the success of your actions (never assume success).

In this particular case tho, I think you can solve it by adding a check to the case for opening the bank

if (bankbooth != null && !getBank().isOpen() && !myPlayer().isMoving()) {
	//interact
}
Edited by FrostBug
  • Like 2
Link to comment
Share on other sites

Hey! It does click the bank 1 time now! Thanks for that. Only problem is. It doesn't deposit the logs anymore. 

 

EDIT: Trying it with the !myPlayer().isMoving()). Will let you know in a sec.

EDIT EDIT: Nope, it doesn't work. My Logs aren't stored in the bank.

		if (bankbooth != null && !getBank().isOpen() && !myPlayer().isMoving()) {
						if (inventory.isFull()) {
							camera.toEntity(bankbooth);
							bankbooth.interact("Bank");
							bank.depositAll("Willow logs");
							sleep(random(500,700));
						}
				}
Edited by OSRS Sebastian
Link to comment
Share on other sites

 

Hey! It does click the bank 1 time now! Thanks for that. Only problem is. It doesn't deposit the logs anymore. 

 

EDIT: Trying it with the !myPlayer().isMoving()). Will let you know in a sec.

			if (bankbooth != null && !getBank().isOpen()) {
						if (inventory.isFull()) {
							camera.toEntity(bankbooth);
							bankbooth.interact("Bank");
							bank.depositAll("Willow logs");
							sleep(random(500,700));
						}
				}

 

There's no sleep time between opening the bank and depositing willow logs. Try adding a conditional sleep after interacting like this:

 

bankbooth.interact("Bank");
new ConditionalSleep(5000) {
                    @Override
                    public boolean condition() throws InterruptedException {
                        return getBank().isOpen();
                    }

                }.sleep();

 

This means that the bot will sleep for 5000 milliseconds or until the bank is open. Whichever comes first.

 

 

 

You should generally avoid doing multiple interactions in 1 loop cycle, and always evaluate the success of your actions (never assume success).

In this particular case tho, I think you can solve it by adding a check to the case for opening the bank

 

 

You can evaluate the success by adding conditional sleeps.

  • Like 1
Link to comment
Share on other sites

There's no sleep time between opening the bank and depositing willow logs. Try adding a conditional sleep after interacting like this:

bankbooth.interact("Bank");
new ConditionalSleep(5000) {
                    @Override
                    public boolean condition() throws InterruptedException {
                        return getBank().isOpen();
                    }

                }.sleep();

This means that the bot will sleep for 5000 milliseconds or until the bank is open. Whichever comes first.

 

 

You can evaluate the success by adding conditional sleeps.

 

Wow! This worked! Thanks! 

 

But, can you explain why using a sleep, fixed this problem? just for my own knowledge.

Link to comment
Share on other sites

 

Hey! It does click the bank 1 time now! Thanks for that. Only problem is. It doesn't deposit the logs anymore. 

 

EDIT: Trying it with the !myPlayer().isMoving()). Will let you know in a sec.

EDIT EDIT: Nope, it doesn't work. My Logs aren't stored in the bank.

		if (bankbooth != null && !getBank().isOpen() && !myPlayer().isMoving()) {
						if (inventory.isFull()) {
							camera.toEntity(bankbooth);
							bankbooth.interact("Bank");
							bank.depositAll("Willow logs");
							sleep(random(500,700));
						}
				}

 

You weren't supposed to move the deposit statement into the open-bank block, would have been fine if left where it was.

 

Glad you solved the problem, tho.

 

  • Like 1
Link to comment
Share on other sites

Wow! This worked! Thanks! 

 

But, can you explain why using a sleep, fixed this problem? just for my own knowledge.

 

Code runs line by line. Let's say you had something like this:

NPC goblin = getNpcs().closest("Goblin");
goblin.interact("Attack");
getBank().open();

This will first attack the goblin and then open the bank. HOWEVER, there is a delay for game actions that isnt there in code. This means that you will click the goblin and then immediately try and open the bank. Sleeping between code essentially means that you're waiting until the next line.

NPC goblin = getNpcs().closest("Goblin");
goblin.interact("Attack");
sleep(600);
getBank().open();

sleep(600) will wait 600ms (also known as 1 tick in OSRS) and then perform the next line of code.

 

EDIT: There is also something known as asynchronous code, which means that the code runs but still allows the next line(s) to run.

Edited by Bobrocket
  • Like 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...