TheScrub Posted January 20, 2014 Posted January 20, 2014 (edited) Class import java.awt.Point; import java.awt.Rectangle; import org.osbot.script.Script; import org.osbot.script.mouse.RectangleDestination; import org.osbot.script.rs2.model.Item; import org.osbot.script.rs2.ui.RS2InterfaceChild; /* *Written by TheScrub ~ OSBOT */ public class DepositBox { private final int START_WIDTH = 135; private final int START_HEIGHT = 82; // width+ height includes spacing lengths private final int WIDTH = 41; private final int HEIGHT = 44; private Script script; private final int PARENTID = 11; private final int CHILDID = 61; private final int INFOID = 60; public DepositBox(Script script) { this.script = script; } public Item[] getItems() { if (boxIsOpen()) { if (script.client.getInterface(PARENTID) != null) { RS2InterfaceChild rc = script.client.getInterface(PARENTID) .getChild(CHILDID); if (rc != null && rc.isVisible()) { return script.client.getInterface(PARENTID).getItems( CHILDID); } } } return null; } public int getItemSlot(Item item) { Item[] array = getItems(); if (array != null && array.length > 0) { for (int i = 0; i < array.length; i++) { if (array[i] != null) { if (array[i].equals(item)) { return i; } } } } return -1; } public int getItemSlot(String item) { Item[] array = getItems(); if (array != null && array.length > 0) { for (int i = 0; i < array.length; i++) { if (array[i] != null) { if (array[i].getName() != null) { if (array[i].getName().equalsIgnoreCase(item)) { return i; } } } } } return -1; } public int getItemSlot(int item) { Item[] array = getItems(); if (array != null && array.length > 0) { for (int i = 0; i < array.length; i++) { if (array[i] != null) { if (array[i].getName() != null) { if (array[i].getId() == item) { return i; } } } } } return -1; } public boolean contains(String item) { if (boxIsOpen()) { Item[] array = getItems(); if (array.length > 0) { for (Item i : array) { if (i != null) { if (i.getName() != null) { if (i.getName().equalsIgnoreCase(item)) { return true; } } } } } } return false; } public boolean contains(int item) { if (boxIsOpen()) { Item[] array = getItems(); if (array.length > 0) { for (Item i : array) { if (i != null) { if (i.getId() == item) { return true; } } } } } return false; } public boolean contains(Item item) { if (boxIsOpen()) { Item[] array = getItems(); if (array.length > 0) { for (Item i : array) { if (i != null) { if (i.equals(item)) { return true; } } } } } return false; } private Point getPoint(int slot) { int column = slot / 7; int row = slot % 7; int x = (int) (START_WIDTH + (row * WIDTH)); int y = START_HEIGHT + (column * HEIGHT); return new Point(x, y); } public Rectangle getRectangle(int slot) { Point p = getPoint(slot); return new Rectangle(p.x, p.y, 18, 18); } public boolean boxIsOpen() { if (script.client.getInterface(PARENTID) != null) { RS2InterfaceChild rc = script.client.getInterface(PARENTID) .getChild(CHILDID); if (rc != null && rc.isVisible()) { return true; } } return false; } public String getBoxInfo() { if (boxIsOpen()) { if (script.client.getInterface(PARENTID).getChild(INFOID) .getMessage() != null) { return script.client.getInterface(PARENTID).getChild(INFOID) .getMessage(); } } return null; } public boolean interact(Rectangle rec, String action) throws InterruptedException { if (rec != null && action != null && !action.isEmpty()) { return script.selectOption(null, new RectangleDestination(rec), action); } return false; } } rectangles are abit off but they work fine as it counts as the item still Edited January 20, 2014 by TheScrub 1
Sex Posted January 20, 2014 Posted January 20, 2014 So how long did it take you to get the squares right?
TheScrub Posted January 21, 2014 Author Posted January 21, 2014 So how long did it take you to get the squares right? 5 mins l
Sigma Posted January 23, 2014 Posted January 23, 2014 Combine some of your if statements, there's no reason not to.
YinZ Posted February 26, 2014 Posted February 26, 2014 You Legend! Was just about to make one of these, since I'm short on time, ill use this for now. Much love 1