Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.Color;
- import java.awt.Graphics;
- import java.util.Map;
- import com.speljohan.rsbot.bot.Bot;
- import com.speljohan.rsbot.event.events.ServerMessageEvent;
- import com.speljohan.rsbot.event.listeners.PaintListener;
- import com.speljohan.rsbot.event.listeners.ServerMessageListener;
- import com.speljohan.rsbot.script.Script;
- import com.speljohan.rsbot.script.wrappers.RSInterface;
- import com.speljohan.rsbot.script.wrappers.RSObject;
- import com.speljohan.rsbot.script.wrappers.RSTile;
- public class YanilleironMiner extends Script implements ServerMessageListener,
- PaintListener {
- private long startTime = System.currentTimeMillis();
- private RSTile[] path = { new RSTile(2611, 3092), new RSTile(2606, 3096),
- new RSTile(2614, 3104), new RSTile(2620, 3114),
- new RSTile(2624, 3127), new RSTile(2626, 3138) };
- private int mined = 0, loads = 0;
- private int[] rocks = { 2093, 2093, 2093 }, picks = { 1265, 1267, 1269,
- 1273, 1271, 1275 }, empty = { 452, 452, 452 };
- private RSTile bankTile = path[0], ironTile = path[path.length - 1],
- currentTile;
- private final int wait1 = 300, wait2 = 500, bankID = 2213;
- private String doing;
- private boolean isMining, power;
- private int currentRock = rocks[0];
- public String getName() {
- return "Yanille Iron Miner";
- }
- public String getAuthor() {
- return "Nokeo and Fusion89k (For his Barb Coal Miner)";
- }
- public double getVersion() {
- return 1.2;
- }
- public String getScriptCategory() {
- return "Mining";
- }
- public String getScriptDescription() {
- return "<html>\n"
- + "<head></head>\n"
- + "<body bgcolor=\"black\" text=\"white\">\n"
- + "<center>"
- + "<h2>"
- + getName()
- + "</h2>"
- + "</center>\n"
- + "<b>Author:</b> "
- + getAuthor()
- + "<br />"
- + "<b>Version:</b> "
- + getVersion()
- + "<BR>Pickaxe may be equipped or in FIRST inventory slot"
- + "<BR><input type='checkbox' name='power' value='true'> Check to drop Iron Ore"
- + "</body>\n" + "</html>";
- }
- public boolean onStart(Map<String, String> args) {
- power = args.get("power") != null;
- Bot.getEventManager().addListener(PaintListener.class, this);
- return true;
- }
- public boolean dropAllExcept(int... items) { //Djbeng
- int inventoryCount = getInventoryCount();
- int[] inventoryArray = getInventoryArray();
- outer: for (int off = 0; off < inventoryArray.length; off++) {
- if (inventoryArray[off] == -1) continue;
- for (int item : items) {
- if (inventoryArray[off] == item) {
- continue outer;
- }
- }
- for (int tries = 0; tries < 5; tries++) {
- atInventoryItem(inventoryArray[off], "Drop");
- wait(random(100, 300));
- if (getInventoryCount() < inventoryCount) {
- break;
- }
- }
- if (getInventoryCount() >= inventoryCount) {
- // equally, otherwise
- // something really weird
- // happend :P
- return false;
- }
- inventoryArray = getInventoryArray();
- inventoryCount = getInventoryCount();
- }
- return true;
- }
- public void onFinish() {
- Bot.getEventManager().removeListener(PaintListener.class, this);
- }
- public int loop() {
- setCompass('w');
- setCameraAltitude(true);
- if (!isCarryingItemCustom(picks) && isLoggedIn()) {
- log("No PickAxe");
- stopAllScripts();
- }
- if (isMoving())
- return random(wait1, wait2);
- if (isMining && getMyPlayer().getAnimation() == -1)
- isMining = false;
- if (!isInventoryFull()) {
- if (isMining) {// Smoking rocks got some help from: Tenac
- try {
- int curID = getObjectAt(currentTile).getID();
- if (curID != currentRock) {
- isMining = false;
- mine();
- }
- } catch (Exception e) {
- log("Smoking detection error");
- }
- return random(wait1, wait2);
- }
- if (distanceTo(ironTile) > 4) {
- doing = "Walking to Iron";
- return walk(false);
- }
- doing = "Finding Iron";
- RSObject rock = findObject(rocks);
- if (rock == null) {
- doing = "Waiting for Iron";
- randomStuff();
- return random(wait1, wait2);
- }
- mine();
- } else {
- if (power) {
- dropAllExcept(picks);
- } else {
- if (distanceTo(bankTile) > 4) {
- doing = "Walking to Bank";
- return walk(true);
- }
- if (!RSInterface.getInterface(INTERFACE_BANK).isValid()) {
- doing = "Finding Bank";
- RSObject booth = findObject(bankID);
- if (booth == null)
- return random(wait1, wait2);
- if (!tileOnScreen(booth.getLocation())) {
- turnToObject(booth, random(-5, 5));
- RSTile boothtile = new RSTile(booth.getLocation()
- .getX(), booth.getLocation().getY()
- + random(1, 3));
- walkTileMM(boothtile);
- return random(wait1, wait2);
- }
- if (!getMyPlayer().isMoving()
- && getMyPlayer().getAnimation() == -1) {
- atObject(booth, "Use-Quickly");
- }
- return random(wait1, wait2);
- }
- if (RSInterface.getInterface(INTERFACE_BANK).isValid()) {
- doing = "Depositing";
- bank.depositAllExcept(picks);
- loads++;
- bank.close();
- }
- }
- }
- if (getEnergy() > random(50, 100))
- setRun(true);
- return random(wait1, wait2);
- }
- private void mine() {
- RSObject rock = findObject(rocks);
- if (rock == null && !findAllEmpty()) {
- atTile(randomTile(getMyPlayer().getLocation()), "walk");
- isMining = false;
- return;
- }
- doing = "Mining Iron";
- atObject(rock, "Mine");
- isMining = true;
- currentTile = rock.getLocation();
- currentRock = rock.getID();
- openTab(TAB_INVENTORY);
- }
- private boolean findAllEmpty() {
- for (int id : empty) {
- if (findObject(id) == null)
- return false;
- }
- return true;
- }
- private int walk(boolean toBank) {
- RSTile start = locate();
- int loc = 0;
- for (int i = 0; i < path.length; i++) {
- if (start.equals(path[i])) {
- loc = i;
- break;
- }
- }
- if (toBank) {
- if (loc == 0)
- return random(wait1, wait2);
- walkTileMM(randomTile(path[loc - 1]));
- } else {
- if (loc == path.length - 1)
- walkTileMM(ironTile);
- else
- walkTileMM(randomTile(path[loc + 1]));
- }
- return random(wait1, wait2);
- }
- private RSTile randomTile(RSTile tile) {
- return new RSTile(random(tile.getX() - 2, tile.getX() + 2), random(tile
- .getY() - 2, tile.getY() + 2));
- }
- private RSTile locate() {
- RSTile min = path[0];
- for (int i = 1; i < path.length; i++) {
- if (distanceTo(path[i]) < distanceTo(min))
- min = path[i];
- }
- return min;
- }
- private boolean isCarryingItemCustom(int... items) {
- for (int i : items) {
- if (getInventoryCount(i) > 0)
- return true;
- }
- for (int item : items) {
- if (getEquipmentInterface().getInventoryItemCount(item) > 0)
- return true;
- }
- return false;
- }
- private void randomStuff() {
- int temp = random(1, 50);
- switch (temp) {
- case 3:
- case 4:
- moveMouse(random(150, 450), random(100, 300));
- break;
- case 2:
- openTab(TAB_STATS);
- RSTile mining = randomTile(new RSTile(680, 230));
- moveMouse(mining.getX(), mining.getY());
- break;
- case 6:
- openTab(random(0, 13));
- break;
- }
- }
- private boolean isMoving() {
- if (!getMyPlayer().isMoving())
- return false;
- if (!locate().equals(path[0]) || !locate().equals(path[1])
- || !locate().equals(path[path.length - 1])
- || !locate().equals(path[path.length - 2])) {
- if (distanceTo(getDestination()) < 5)
- return false;
- }
- return true;
- }
- public void serverMessageRecieved(ServerMessageEvent e) {
- String word = e.getMessage().toLowerCase();
- if (word.contains("iron")) {
- mined++;
- isMining = false;
- }
- }
- public void onRepaint(Graphics g) {
- if (isLoggedIn()) {
- long millis = System.currentTimeMillis() - startTime;
- long hours = millis / (1000 * 60 * 60);
- millis -= hours * (1000 * 60 * 60);
- long minutes = millis / (1000 * 60);
- millis -= minutes * (1000 * 60);
- long seconds = millis / 1000;
- int topX = 515 - 173, topY = 337 - 80, x = topX + 5, y = topY + 5;
- g.setColor(new Color(0, 50, 100, 100));
- g.fill3DRect(topX, topY, 515 - topX, 337 - topY, true);
- g.setColor(Color.white);
- g.drawString("Runtime: " + hours + "h " + minutes + "min "
- + seconds + "sec.", x, y += 15);
- g.drawString("Iron Mined: " + Integer.toString(mined), x, y += 15);
- g.drawString("Loads Done: " + loads, x, y += 15);
- g.drawString("Status: " + doing, x, y += 15);
- }
- }
- }
Add Comment
Please, Sign In to add comment