Jump to content

Bank Closing Help


Rumb

Recommended Posts

Hello everyone :D

So I was working on a new script of mine and I was literally 30m into coding when I ran into the weirdest problem, for some reason the bank closes every single time I open it even though I don't call it:

94c4c13564fb1f76e6bcfaf72b5e3cb3.gif

 

 

Here is my code, notice that it is extreemly messy and the fact that I am not using bank.open() and bank.close() purely because I was trying to eliminate them because it just kept closing, also I have been working on this project for 30m when I got stuck by this.

package OreSmelter;

import org.osbot.rs07.api.filter.Filter;
import org.osbot.rs07.api.model.Item;
import org.osbot.rs07.api.model.RS2Object;
import org.osbot.rs07.api.ui.Tab;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;
import org.osbot.rs07.utility.ConditionalSleep;

import OreSmelter.Util;

@ScriptManifest(author = "Rumble", info = "Smelts Ores", logo = "", name = "OreSmelter", version = 1.01)
public class OreSmelter extends Script{
	
	private String iron = "Iron ore";
	
	public void tabCheck() throws InterruptedException {
		Tab currentTab = tabs.getOpen();
		if(currentTab == Tab.MAGIC) {
			click();
		} else {
			tabs.open(Tab.MAGIC);
			return;
		}
	}
	
	public void click() throws InterruptedException {
		int rand = Util.randomNumb(1,100);
		if(rand <= 70) {
			mouse.move(random(663,671), random(304,307));
		} else if(rand > 70) {
			mouse.move(random(658,675), random(295,311));
		}
		
		while(inventory.getAmount(iron) > 1) {
			mouse.click(false);
			sleep(random(50,150));
		}
		int amount = random(3,6);
		for(int x = 0; x < amount; x++) {
			mouse.click(false);
		}
		while(inventory.contains(iron) && myPlayer().getAnimation() != -1) {
			sleep(random(100,200));
		}
		
		clickBank();
	}
	
	public void clickBank() throws InterruptedException {
		Filter<RS2Object> boothFilter = new Filter<RS2Object>()
				{
					public boolean match(RS2Object o) 
					{
						if (!o.getName().equals("Bank booth"))
							return false;
						return true;
					}
				};
				
				RS2Object booth = objects.closest(boothFilter);
				booth.hover();
				int amount = random(2,4);
				for(int x = 0; x < amount; x++) {
					mouse.click(false);
					sleep(random(20,50));
				}
				sleep(random(1500,2000));
				if(bank.isOpen()){
					log("bank()");
					bank();
				} else {
					log("Reclick clickBank()");
					clickBank();
				}
	}

	public void bank() throws InterruptedException {
		if(inventory.contains("Steel bar")) {
			log("Deposit Steel Bar: 9");
			bank.deposit("Steel bar", 9);
		} else {
			if(!inventory.contains("Coal") && !inventory.contains("Iron ore")) {
				log("Withdrawing Coal and Ore");
				bank.withdraw("Coal", 1);
				bank.withdraw("Iron ore", 9);
				sleep(random(200,400));
				bank.withdraw("Coal", 10);
				sleep(random(100,200));
				bank.withdraw("Coal", 10);
				sleep(random(200,400));
			} else if(inventory.isFull() && bank.isOpen()) {
				log("Closing Bank");
				sleep(random(500,1000));
				mouse.move(random(485,495),random(18,26));
				mouse.click(false);
				sleep(random(1000,2000));
			} else if(inventory.contains("Coal") && inventory.contains("Iron ore") && !inventory.isFull()) {
				log("Secondary Withdraw: Coal");
				bank.withdraw("Coal", 10);
			} else if(inventory.contains("Coal") && !inventory.contains("Iron ore")) {
				log("Secondary Withdraw: Iron");
				bank.withdraw("Iron ore", 9);
			}
		}
	}
	
	@Override
	public int onLoop() throws InterruptedException {
				
		if (Util.ins == null)
		{
			log("Init utils");
			Util.initUtils(this);
		}
				
		if(inventory.getAmount(iron) > 2 && !bank.isOpen()) {
			if(getInventory().getItemInSlot(10).getName().equals(iron)) {
				tabCheck();
			}
		} 
		
		return 5;
	}

}

As you can see bank.open() and bank.close() are never called in this but every time I open the bank it automatically goes to close it, any suggestions why and thanks guys ahead of time :D

Link to comment
Share on other sites

There is a 150 millisecond delay before items in the bank are cached properly. Add a sleep for when the bank is opened.

I just added a 4-5 second delay just to kinda see if that was the problem and it stood there doing nothing for 4-5 seconds in the bank, then immediately after the 4-5 seconds went for the close button

sleep(random(4500,5000));

Doesnt seem to be the problem

Link to comment
Share on other sites

I feel like you know java, but not so much the osbot api.

if(!inventory.contains("Coal") && !inventory.contains("Iron ore"))
{
			if (bank.isOpen()) {
				bank.depositAll("Steel bar");
				sleep(random(500, 1000));
				widgets.getBank().withdraw("Coal", 14);
                                sleep(random(500, 1000));
                                widgets.getBank().withdraw("Iron ore", 7);				
                                bank.close();
				break;
			} else {
				bank.open();
			}
}

No need for all those else if statements. This pretty much covers it in one.

Edited by twin 763
Link to comment
Share on other sites

I feel like you know java, but not so much the osbot api.

if(!inventory.contains("Coal") && !inventory.contains("Iron ore"))
{
			if (bank.isOpen()) {
				bank.depositAll("Steel bar");
				sleep(random(500, 1000));
				widgets.getBank().withdraw("Coal", 14);
                                sleep(random(500, 1000));
                                widgets.getBank().withdraw("Iron ore", 7);				
                                bank.close();
				break;
			} else {
				bank.open();
			}
}

No need for all those else if statements. This pretty much covers it in one.

 

This has no conditional checks. If one of the deposits/withdraws fails this will fail miserably and end up with a wonky inventory of items. 

 

I strongly suggest creating conditional that check what needs to be withdrawn and deposited specifically instead of just doing it all consecutively in one conditional. 

Link to comment
Share on other sites

This has no conditional checks. If one of the deposits/withdraws fails this will fail miserably and end up with a wonky inventory of items. 

 

I strongly suggest creating conditional that check what needs to be withdrawn and deposited specifically instead of just doing it all consecutively in one conditional. 

 

I just stole that from something  in my script and changed it around, didn't even think of that lol.

 

But yeah, he's right. If this messes up and doesn't get iron, it's going to withdraw coal and iron again, then it won't bank because it will have an over abundance of one of the two ores.

Edited by twin 763
Link to comment
Share on other sites

I feel like you know java, but not so much the osbot api.

if(!inventory.contains("Coal") && !inventory.contains("Iron ore"))
{
			if (bank.isOpen()) {
				bank.depositAll("Steel bar");
				sleep(random(500, 1000));
				widgets.getBank().withdraw("Coal", 14);
                                sleep(random(500, 1000));
                                widgets.getBank().withdraw("Iron ore", 7);				
                                bank.close();
				break;
			} else {
				bank.open();
			}
}

No need for all those else if statements. This pretty much covers it in one.

nah, I got it all down, I used to code for p****bot like 4 years ago, p****bot is where I first learned java. Just when I code I like to "get it working", once I get the script working and it is doing it's job properly I will then go in and edit it all up, make it actual code and slowly improve the script till it is at full potential. This script I wrote was only 30m of sitting down and creating the working script, the problem is I am stuck at this bank problem which has caused me to dumb up my code even more to the basics to find the problem. Still no solution though, I don't get it.

Link to comment
Share on other sites

if(inventory.contains("Steel bar") && !inventory.contains("Iron Ore") && !inventory.contains("Coal")) {
			log("Deposit Steel Bar: 9");
			bank.deposit("Steel bar", 9);
		} else {
			if(!inventory.contains("Coal") && !inventory.contains("Iron ore") && !inventory.contains("Steel Bar")) {
				log("Withdrawing Coal and Ore");
				bank.withdraw("Coal", 1);
				bank.withdraw("Iron ore", 9);
				sleep(random(200,400));
				bank.withdraw("Coal", 10);
				sleep(random(100,200));
				bank.withdraw("Coal", 10);
				sleep(random(200,400));
			} else if(inventory.isFull() && bank.isOpen()) {
				log("Closing Bank");
				sleep(random(500,1000));
				mouse.move(random(485,495),random(18,26));
				mouse.click(false);
				sleep(random(1000,2000));
			} else if(inventory.contains("Coal") && inventory.contains("Iron ore") && !inventory.isFull()) {
				log("Secondary Withdraw: Coal");
				bank.withdraw("Coal", 10);
			} else if(inventory.contains("Coal") && !inventory.contains("Iron ore")) {
				log("Secondary Withdraw: Iron");
				bank.withdraw("Iron ore", 9);
			}
		}

I don't have time to fix the entire thing but I've had a similar problem with other scripts, with OSBot, when you use IF statements, you need to declare the same rules for ea statement e.g.

 

if(inv.contain(ore) && inv.contain(coal) && !inv.contain(steel bar)) {

 

} else if(!inv.contain(ore) && !inv.contain(coal) && inv.contain(steel bar)) {

 

}else if(!inv.contain(ore) && inv.contain(coal) && !inv.contain(steel bar)) {

 

}

 

Not sure if you get the point, but I recommend you use getState() method, as this script is a little more complex than a simple Loop() through.

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