Jump to content
Sign in to follow this  
TheScrub

Search Bank

Recommended Posts

tested search and bankIsOpen

import org.osbot.script.Script;
import org.osbot.script.rs2.ColorPicker;
import org.osbot.script.rs2.ui.RS2InterfaceChild;

public class Bank {
    Script script;

    public boolean bankIsOpen() {
        if (script.client.getInterface(12) != null) {
            RS2InterfaceChild searchbutton = script.client.getInterface(12)
                    .getChild(20);
            if (searchbutton != null && searchbutton.isVisible()) {
                return true;
            }
        }
        return false;
    }

    public static void searchBank(String item) throws InterruptedException {
        RS2InterfaceChild button = Context.script.client.getInterface(12)
                .getChild(20);
        if (button != null) {
            button.interact("Search");
        }
        ColorPicker text = new ColorPicker(Context.script.bot);
        if (text.colorAt(260, 431).getBlue() > 0
                && text.colorAt(294, 403).getBlue() == 0) {
            Context.script.client.typeString(item);
        }
    }

    public static void depositInventory() throws InterruptedException {
        RS2InterfaceChild button = Context.script.client.getInterface(12)
                .getChild(22);
        if (button != null) {
            button.interact("Deposit inventory");
        }
    }

    public static void depositWornItems() throws InterruptedException {
        RS2InterfaceChild button = Context.script.client.getInterface(12)
                .getChild(24);
        if (button != null) {
            button.interact("Deposit worn items");
        }
    }





    private static Rectangle returnRectangle(int minX, int minY, int maxX,
            int maxY) {
        int height = maxY - minY;
        int width = maxX - minX;
        Rectangle r = new Rectangle(minX, minY, width, height);
        return r;
    }

    private static Point centrePointOfRectangle(int minX, int minY, int maxX,
            int maxY) {
        int centreGapY = (maxY - minY) / 2;
        int centreGapX = (maxX - minX) / 2;
        int Y = minY + centreGapY;
        int X = minX + centreGapX;
        Point centre = new Point(X, Y);
        return centre;
    }

    
    /*
     * only works for the first top four slots of the bank
     * you will need the brightness to be on the right colour
     * any other withdrawing can be done using the select option method
     *
     */
    
    public static void withdrawOne(int green, int red, int blue)
            throws InterruptedException {
        ColorPicker bankitem = new ColorPicker(Context.script.bot);

        Point slot1 = (centrePointOfRectangle(74, 73, 102, 97));
        Point slot2 = (centrePointOfRectangle(122, 73, 147, 97));
        Point slot3 = (centrePointOfRectangle(170, 73, 192, 97));
        Point slot4 = (centrePointOfRectangle(218, 73, 237, 97));
        Point row[] = { slot1, slot2, slot3, slot4 };
        for (Point p : row) {
            if (bankitem.colorAt(p.x, p.y).getRed() == red
                    && bankitem.colorAt(p.x, p.y).getBlue() == blue
                    && bankitem.colorAt(p.x, p.y).getGreen() == green) {
                Context.script.client
                        .moveMouse(
                                new RectangleDestination(new Rectangle(
                                        returnRectangle(p.x - 22, p.y - 22,
                                                p.x + 22, p.y + 22))), true);
                if (returnRectangle(p.x - 22, p.y - 22, p.x + 22, p.y + 22)
                        .contains(
                                Context.script.client.getMousePosition()
                                        .getLocation())) {
                    Context.script.client.clickMouse(false);
                }
            }
        }
    }

    public static void logColours() throws InterruptedException {
        ColorPicker bankitem = new ColorPicker(Context.script.bot);
        if (Context.script.client.getInterface(12) != null) {
            RS2InterfaceChild searchbutton = Context.script.client
                    .getInterface(12).getChild(20);
            if (searchbutton != null && searchbutton.isVisible()) {
                Point slot1 = (centrePointOfRectangle(74, 73, 102, 97));
                Point slot2 = (centrePointOfRectangle(122, 73, 147, 97));
                Point slot3 = (centrePointOfRectangle(170, 73, 192, 97));
                Point slot4 = (centrePointOfRectangle(218, 73, 237, 97));
                Point row[] = { slot1, slot2, slot3, slot4 };
                for (Point p : row) {
                    Context.script.log(" " + "Red "
                            + bankitem.colorAt(p.x, p.y).getRed());
                    Context.script.log("Blue: "
                            + bankitem.colorAt(p.x, p.y).getBlue());
                    Context.script.log("Green: "
                            + bankitem.colorAt(p.x, p.y).getGreen());
                }
            }
        }
    }









}



Edited by TheScrub

Share this post


Link to post
Share on other sites

 

 

 

Terrible. You have accounted for any unexpected lag (use sleeps).

i like to use a while loop for sleeps but i don't like to use it in snippets obviously you can add sleeps...

 

While loops are bad...

 

please enlighten me why so?

 

Because they have so many flaws. What if your bot gets stuck in a while loop whilst the evil chicken pwns ur ass?

Share this post


Link to post
Share on other sites

 

 

 

 

Terrible. You have accounted for any unexpected lag (use sleeps).

i like to use a while loop for sleeps but i don't like to use it in snippets obviously you can add sleeps...

 

While loops are bad...

 

please enlighten me why so?

 

Because they have so many flaws. What if your bot gets stuck in a while loop whilst the evil chicken pwns ur ass?

 

having something like that can counter getting stuck in a while loop as it will break out the while loop after 3000ms

long t = System.currentTimeMillis();
            while (boolean x && (System.currentTimeMillis() - t) < 3000) {
                sleep(20);
            }

Share this post


Link to post
Share on other sites

 

 

 

 

Terrible. You have accounted for any unexpected lag (use sleeps).

i like to use a while loop for sleeps but i don't like to use it in snippets obviously you can add sleeps...

 

While loops are bad...

 

please enlighten me why so?

 

Because they have so many flaws. What if your bot gets stuck in a while loop whilst the evil chicken pwns ur ass?

 

 

While loops are the best way to create dynamic sleeps. L2Java before you criticize. 

Share this post


Link to post
Share on other sites

Wrote this up right quick:

import org.osbot.script.MethodProvider;
import org.osbot.script.Script;
import org.osbot.script.rs2.ui.Bank;
import org.osbot.script.rs2.ui.EquipmentSlot;
import org.osbot.script.rs2.ui.RS2Interface;
import org.osbot.script.rs2.ui.RS2InterfaceChild;

//#click() is depricated, if it doesn't work, replace for #interact(...)
public class BankSearch extends Bank {

	public static final int BANK_PARENT = 12;
	public static final int BANK_CHILD = 0;
	public static final int BANK_CHILD_TITLE = 2;
	public static final int BANK_CHILD_SEARCH = 20;
	public static final int BANK_CHILD_DEP_INV = 22;
	public static final int BANK_CHILD_DEP_ARM = 24;
	public static final int BANK_SEARCH_PARENT = 548;
	public static final int BANK_SEARCH_CHILD = 94;
	
	//public static final String BANK_TITLE = "The Bank of RuneScape";
	//public static final String BANK_TITLE_SEARCH = "Showing items: <col=ff0000></col>";
	
	private final Script script;
	
	public BankSearch(Script script) {
		super(script.bot, script.client);
		this.script = script;
	}

	@Override
	public boolean isOpen() {
		return getWidgetChild(BANK_PARENT, BANK_CHILD) != null;
	}
	
	@SuppressWarnings("deprecation")
	public boolean depositInventory() throws InterruptedException {
		RS2InterfaceChild i = getWidgetChild(BANK_PARENT, BANK_CHILD_DEP_INV);
		return i != null && i.click() && script.client.getInventory().isEmpty();
	}
	
	@SuppressWarnings("deprecation")
	public boolean depositEquipment() throws InterruptedException {
		RS2InterfaceChild i = getWidgetChild(BANK_PARENT, BANK_CHILD_DEP_ARM);
		return i != null && i.click() && isNaked();
	}
	
	@SuppressWarnings("deprecation")
	public boolean enterSearchMode() throws InterruptedException {
		RS2InterfaceChild i = getWidgetChild(BANK_PARENT, BANK_CHILD_SEARCH);
		try {
			return i != null && i.click() && isInSearchMode();
		} finally {
			sleep(1000 + MethodProvider.random(1000), new DynamicSleep() {
				
				@Override
				public boolean canAwake() {
					return isInSearchMode();
				}
			});
		}
	}
	
	@Deprecated //Poor fucking coding...tired.
	public boolean invokeSearch(String string) throws InterruptedException {
		if (!isInSearchMode() || !isSearchEngineOpen())
			return false;
		String cur = getCurrentlyEnteredSearchText();
		if (cur.equalsIgnoreCase(string))
			return true;
		else if (isSearchEngineOpen() || enterSearchMode())
			script.type(string);
		return (cur = getCurrentlyEnteredSearchText()).equalsIgnoreCase(string);
	}
	
	public String getCurrentlyEnteredSearchText() {
		RS2InterfaceChild i = getWidgetChild(BANK_SEARCH_PARENT, BANK_SEARCH_CHILD);
		if (i == null)
			return null;
		String s = i.getMessage();
		return s.substring(0, s.length() - 1); // -1 for *
	}
	
	public boolean isSearchEngineOpen() {
		RS2InterfaceChild i = getWidgetChild(BANK_SEARCH_PARENT, BANK_SEARCH_CHILD);
		return i != null && i.isVisible();
	}
	
	public boolean isInSearchMode() {
		RS2InterfaceChild i = getWidgetChild(BANK_PARENT, BANK_CHILD_TITLE);
		return i != null && i.getMessage().startsWith("Showing");
	}
	
	public String getSearchedPhrase() {
		RS2InterfaceChild i = getWidgetChild(BANK_PARENT, BANK_CHILD_TITLE);
		if (!isInSearchMode())
			return null;
		String s = i.getMessage();
		return s.length() - 6 != 27 ? s.substring(27, s.length() - 6) : "";
	}
	
	private boolean isNaked() {
		for (EquipmentSlot next : EquipmentSlot.values())
			if (script.equipmentTab.getItemInSlot(next) != null)
				return false;
		return true;
	}
	
	private RS2InterfaceChild getWidgetChild(int a, int b) {
		RS2Interface p = script.client.getInterface(a);
		return p != null && p.isValid() ? p.getChild(b) : null;
	}
	
	private synchronized void sleep(long timeout, DynamicSleep condition) throws InterruptedException {
		final long old = System.currentTimeMillis();
		while (old + timeout >= System.currentTimeMillis())
			if (condition.canAwake())
				break;
			else
				script.sleep(50 + MethodProvider.random(200));
	}
	
	static interface DynamicSleep {
		
		boolean canAwake();
	}
}

Example of it in use:

import javax.swing.JOptionPane;

import org.osbot.script.Script;
import org.osbot.script.ScriptManifest;

import co.uk.liverare.framework.wrapper2.BankSearch;

@ScriptManifest(name = "Demo", info = "Script designed for testing purposes.", version = 1.0, author = "LiveRare")
public class Demo extends Script {
	
	BankSearch bankSearch;
	
	String search;
	
	@Override
	public void onStart() {
		
		bankSearch = new BankSearch(this);
		search = JOptionPane.showInputDialog("Search:");
	}
	
	@Override
	public int onLoop() throws InterruptedException {
		
		if (bankSearch.isOpen()) {

			if (bankSearch.isSearchEngineOpen())
				bankSearch.invokeSearch(search);
			sleep(2000 + random(1000));
		}
		
		
		return 100;
	}
	
}

#isOpen() overriden to work
#depositInventory() doesn't check if inventory is empty first--you check for that
#depositEquipment() doesn't check if naked first--you do that
#enterSearchMode() enters the search mode
#invokeSearch(String string) enters text into the search engine
#getCurrentlyEnteredSearchText() gets the text in the search engine
#isSearchEngineOpen() <tt>search engine exists, and is valid and visible</tt>
#isInSearchMode() <tt>bank is in "search mode"</tt>
#getSearchedPhrase() returns the searched phrase located in the bank's title

Share this post


Link to post
Share on other sites

 

Wrote this up right quick:

import org.osbot.script.MethodProvider;
import org.osbot.script.Script;
import org.osbot.script.rs2.ui.Bank;
import org.osbot.script.rs2.ui.EquipmentSlot;
import org.osbot.script.rs2.ui.RS2Interface;
import org.osbot.script.rs2.ui.RS2InterfaceChild;

//#click() is depricated, if it doesn't work, replace for #interact(...)
public class BankSearch extends Bank {

	public static final int BANK_PARENT = 12;
	public static final int BANK_CHILD = 0;
	public static final int BANK_CHILD_TITLE = 2;
	public static final int BANK_CHILD_SEARCH = 20;
	public static final int BANK_CHILD_DEP_INV = 22;
	public static final int BANK_CHILD_DEP_ARM = 24;
	public static final int BANK_SEARCH_PARENT = 548;
	public static final int BANK_SEARCH_CHILD = 94;
	
	//public static final String BANK_TITLE = "The Bank of RuneScape";
	//public static final String BANK_TITLE_SEARCH = "Showing items: <col=ff0000></col>";
	
	private final Script script;
	
	public BankSearch(Script script) {
		super(script.bot, script.client);
		this.script = script;
	}

	@Override
	public boolean isOpen() {
		return getWidgetChild(BANK_PARENT, BANK_CHILD) != null;
	}
	
	@SuppressWarnings("deprecation")
	public boolean depositInventory() throws InterruptedException {
		RS2InterfaceChild i = getWidgetChild(BANK_PARENT, BANK_CHILD_DEP_INV);
		return i != null && i.click() && script.client.getInventory().isEmpty();
	}
	
	@SuppressWarnings("deprecation")
	public boolean depositEquipment() throws InterruptedException {
		RS2InterfaceChild i = getWidgetChild(BANK_PARENT, BANK_CHILD_DEP_ARM);
		return i != null && i.click() && isNaked();
	}
	
	@SuppressWarnings("deprecation")
	public boolean enterSearchMode() throws InterruptedException {
		RS2InterfaceChild i = getWidgetChild(BANK_PARENT, BANK_CHILD_SEARCH);
		try {
			return i != null && i.click() && isInSearchMode();
		} finally {
			sleep(1000 + MethodProvider.random(1000), new DynamicSleep() {
				
				@Override
				public boolean canAwake() {
					return isInSearchMode();
				}
			});
		}
	}
	
	@Deprecated //Poor fucking coding...tired.
	public boolean invokeSearch(String string) throws InterruptedException {
		if (!isInSearchMode() || !isSearchEngineOpen())
			return false;
		String cur = getCurrentlyEnteredSearchText();
		if (cur.equalsIgnoreCase(string))
			return true;
		else if (isSearchEngineOpen() || enterSearchMode())
			script.type(string);
		return (cur = getCurrentlyEnteredSearchText()).equalsIgnoreCase(string);
	}
	
	public String getCurrentlyEnteredSearchText() {
		RS2InterfaceChild i = getWidgetChild(BANK_SEARCH_PARENT, BANK_SEARCH_CHILD);
		if (i == null)
			return null;
		String s = i.getMessage();
		return s.substring(0, s.length() - 1); // -1 for *
	}
	
	public boolean isSearchEngineOpen() {
		RS2InterfaceChild i = getWidgetChild(BANK_SEARCH_PARENT, BANK_SEARCH_CHILD);
		return i != null && i.isVisible();
	}
	
	public boolean isInSearchMode() {
		RS2InterfaceChild i = getWidgetChild(BANK_PARENT, BANK_CHILD_TITLE);
		return i != null && i.getMessage().startsWith("Showing");
	}
	
	public String getSearchedPhrase() {
		RS2InterfaceChild i = getWidgetChild(BANK_PARENT, BANK_CHILD_TITLE);
		if (!isInSearchMode())
			return null;
		String s = i.getMessage();
		return s.length() - 6 != 27 ? s.substring(27, s.length() - 6) : "";
	}
	
	private boolean isNaked() {
		for (EquipmentSlot next : EquipmentSlot.values())
			if (script.equipmentTab.getItemInSlot(next) != null)
				return false;
		return true;
	}
	
	private RS2InterfaceChild getWidgetChild(int a, int b) {
		RS2Interface p = script.client.getInterface(a);
		return p != null && p.isValid() ? p.getChild(b) : null;
	}
	
	private synchronized void sleep(long timeout, DynamicSleep condition) throws InterruptedException {
		final long old = System.currentTimeMillis();
		while (old + timeout >= System.currentTimeMillis())
			if (condition.canAwake())
				break;
			else
				script.sleep(50 + MethodProvider.random(200));
	}
	
	static interface DynamicSleep {
		
		boolean canAwake();
	}
}

Example of it in use:

import javax.swing.JOptionPane;

import org.osbot.script.Script;
import org.osbot.script.ScriptManifest;

import co.uk.liverare.framework.wrapper2.BankSearch;

@ScriptManifest(name = "Demo", info = "Script designed for testing purposes.", version = 1.0, author = "LiveRare")
public class Demo extends Script {
	
	BankSearch bankSearch;
	
	String search;
	
	@Override
	public void onStart() {
		
		bankSearch = new BankSearch(this);
		search = JOptionPane.showInputDialog("Search:");
	}
	
	@Override
	public int onLoop() throws InterruptedException {
		
		if (bankSearch.isOpen()) {

			if (bankSearch.isSearchEngineOpen())
				bankSearch.invokeSearch(search);
			sleep(2000 + random(1000));
		}
		
		
		return 100;
	}
	
}

#isOpen() overriden to work
#depositInventory() doesn't check if inventory is empty first--you check for that
#depositEquipment() doesn't check if naked first--you do that
#enterSearchMode() enters the search mode
#invokeSearch(String string) enters text into the search engine
#getCurrentlyEnteredSearchText() gets the text in the search engine
#isSearchEngineOpen() <tt>search engine exists, and is valid and visible</tt>
#isInSearchMode() <tt>bank is in "search mode"</tt>
#getSearchedPhrase() returns the searched phrase located in the bank's title

 

 

thanks for writing some methods sorry i would of wrote some withdrawing but i've been at school

 

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...