/** Made by Doyley and Guy 2005 (c) cuts any tree and banks magics */ public class PowerChopper extends Script implements ServerMessageListener { public static String[] commands = { "powerChopper" }; private long startTime = System.currentTimeMillis(); private static final String[] AXES = { "BRONZE:1351,508", "IRON:1351,510", "STEEL:1353,512", "MITHRIL:1355,516", "ADAMANT:1357,518", "RUNE:1359,520" }; private static final String[] TREES = { "TREE:1276,1278", "OAK:1281", "WILLOW:1308,5551,5552,5553", "YEW:1309", "MAGIC:1306" }; private static final Tile[] TREES_TO_BANK = new Tile[] { new Tile(2698,3422), new Tile(2699,3427), new Tile(2704,3438), new Tile(2704,3447), new Tile(2708,3449), new Tile(2713,3451), new Tile(2721,3460), new Tile(2720,3468), new Tile(2724,2477), new Tile(2755,3484), new Tile(2725,2490) }; private static final Tile[] TILE_BANK = new Tile[] { new Tile(2725,2490) }; private static final int OBJECT_BANK_BOOTH = 2213; private static final int[] LOGS = { 1511, 1513, 1515, 1517, 1519, 1521, 2511 }; private static final int ITEM_AXE_HANDLE = 492; private String treeName; private int[] treeType; private int[] axeType; private int[] bankingarg; private int treeCount; private int reAttachCount; private Item lostHead; private Tile treePos; private int attachStep; private boolean dropping; private boolean banking; private int[] banking4; public int bankCount; public boolean start(String cmd, String[] args) { if (args.length < 3) { log("Usage: powerChopper([Tree Type], [Axe Type], [Bank yes/no]"); return false; } treeType = getTreesForName(args[0]); axeType = getAxeForName(args[1]); bankingarg = banking4(args[2]); if (treeType == null || axeType == null) { log("Tree/Axe type was invalid (" + args[0] + ", " + args[1] + args[2]+ ")"); return false; } init(); return true; } private void init() { EventManager.addServerMessageListener(this); } public void serverMessage(String message) { if (message.indexOf("you are dead") != -1) { log("You died, quitting!"); shutdown(); } else if (message.indexOf("carefully re") != -1) { reAttachCount++; } else if (message.indexOf("some logs") != -1) { treePos = null; treeCount++; } } public long run(long lastExecuted) { runProgress(); long ticks = runCombat(); if (ticks != 0) return ticks; ticks = runDrop(); if (ticks != 0) return ticks; return runChop(); } private void runProgress() { if (treeCount % 100 == 0 && treeCount != 0) { log("you have banked" + bankCount); log("You have cut " + treeCount + " trees!"); log("You have reattached axe head " + reAttachCount + " times!"); log("Since " + ((System.currentTimeMillis() - startTime) / 60000) + " minutes ago"); treeCount++; // Meh } } private long banking5() { if (inventoryCount() == 28 && getInterface() != Constants.INTERFACE_BANK) { walk(TREES_TO_BANK); int booth = findObject(OBJECT_BANK_BOOTH); if (booth != -1) { log("Opening bank..."); atObject(booth, 2); return random(3000, 4000); } } if (getInterface() == Constants.INTERFACE_BANK) { long rez = banking5(); if (rez != 0) return rez; bankCount++; closeInterface(); log("Finished Banking"); reversePath(TREES_TO_BANK); runProgress(); return random(500,1000); } return 0; } private long runCombat() { if (!inCombat(myPlayer())) return 0; else { log("Running away from combat... "); Tile pos = getPosition(myPlayer()); pos.x += 10; pos.y += 10; walk(pos); return 2500 + random(500, 1000); } } private long runDrop() { if (inventoryCount() == inventoryCount(axeType[0]) && banking) { dropping = false; banking = true; return 0; } if (dropping) return dropLogs(); if (inventoryCount() == 28) { log("Time to bank"); dropping = false; banking = true; return 1; } return 0; } private long runChop() { if (myPlayer().anim == -1) { int treeID = findObject(treeType); if (treeID != -1) { Tile pos = objectPos(treeID); if (distanceTo(pos) > 5) { walk(pos); return 2500 + random(2000, 4000); } else { treePos = pos; atObject(treeID, 1); return 2500 + random(500, 1000); } } else { log("Could not find tree, waiting"); return 2500 + random(500, 1000); } } else if (treePos != null && myPlayer().anim != -1) { NPC ent = findNearestNPCByName(treeName); if (ent == null) return 200; if (getPosition(ent).distanceTo(treePos) < 3) { log("Ent appeared near us, stop chopping."); walk(getPosition(myPlayer())); treePos = null; } return 2500 + random(500, 1000); } return 200; } private long dropLogs() { int[] inv = getInventory(); for (int i = 0; i < inv.length; i++) { if (inv[i] != -1 && inv[i] != axeType[0]) { dropItem(inv[i], i); return 500 + random(500, 1000); } } return 0; } private final int[] banking4(String name) { banking5(); return null; } private final int[] getTreesForName(String name) { for (String log : TREES) { if (log.startsWith(name.toUpperCase())) { treeName = new String(log.split(":")[0].substring(0, 1).toUpperCase() + log.split(":")[0].substring(1).toLowerCase()); String[] trees = log.split(":")[1].split(","); int[] rez = new int[trees.length]; for (int i = 0; i < rez.length; i++) rez[i] = Integer.parseInt(trees[i]); return rez; } } return null; } private final int[] getAxeForName(String name) { for (String axe : AXES) { if (axe.startsWith(name.toUpperCase())) { String[] axes = axe.split(":")[1].split(","); int[] rez = new int[axes.length]; for (int i = 0; i < rez.length; i++) rez[i] = Integer.parseInt(axes[i]); return rez; } } return null; } }