March 18, 201510 yr Hey guys I'm new to java, trying to create a Yew Cutter & bank in seers , any ways of improving or any mistakes in code please point out. I am eager to learn and improve I am using Oracle and this script was written on one 'Class' page in IDE. Do i need to create other pakages,enum or class pages to support this code? will this layout even work? Thanks Guys -NightChillz import org.osbot.rs07.api.model.Entity;import org.osbot.rs07.script.Script;import org.osbot.rs07.script.ScriptManifest;import java.awt.*;@ScriptManifest(author = "NightChillz", info = "WC", name = "WC", version = 0, logo = "")public class WC extends Script { private Position[] path = { new Position(2710, 3462, 0), new Position(2717, 3463, 0), new Position(2719, 3469, 0), new Position(2719, 3476, 0), new Position(2718, 3483, 0), new Position(2725, 3488, 0), new Position(2724, 3493, 0), }; private static final Area TREE_AREA = new Area(2716, 3458, 2704, 3464); private static final Area BANK_AREA = new Area(2721, 3493, 2729, 3490); @Override public void onStart() { "script under development" } private enum State { CHOP, WALK_TO_BANK, BANK, WALK_TO_TREES, }; private State getState() { if (inventory.isFull() && TREE_AREA.contains(myPlayer())) return State.WALK_TO_BANK; if (!inventory.isFull() && BANK_AREA.contains(myPlayer())) return State.WALK_TO_TREES; if (inventory.isFull() && BANK_AREA.contains(myPlayer())) return State.BANK; return State.CHOP; } private boolean walkTile(Position p) throws InterruptedException { client.moveMouse(new MinimapTileDestination(bot, p), false); sleep(random(150, 250)); client.pressMouse(); int failsafe = 0; while (failsafe < 10 && myPlayer().getPosition().distance(p) > 2) { sleep(200); failsafe++; if (myPlayer().isMoving()) failsafe = 0; } if (failsafe == 10) return false; return true; } } @Override public boolean execute() throws java.lang.InterruptedException { switch (getState()) { case CHOP: if (!myPlayer().isAnimating()) { RS2Object tree = objects.closest(YEW); if (tree != null) { if (tree.interact("Chop-Down")) sleep(random(1000, 1500)); } } break; case WALK_TO_BANK: traversePath(path, false); sleep(random(1500, 2500)); break; case WALK_TO_TREES: traversePath(path, true); sleep(random(1500, 2500)); break; case BANK: RS2Object bankBooth = objects.closest("Bank booth"); if (bankBooth != null) { if (bankBooth.interact("Bank")) { while (!bank.isOpen()) sleep(250); bank.depositAll(); } } break; } return random(200, 700);} @Override public void onExit() { } @Override public void onPaint(Graphics2D g) { }} Edited March 18, 201510 yr by Nightchillz
March 18, 201510 yr import org.osbot.rs07.api.model.Entity; import org.osbot.rs07.script.Script; import org.osbot.rs07.script.ScriptManifest; import java.awt.*; @ScriptManifest(author = "NightChillz", info = "WC", name = "WC", version = 0, logo = "") public class WC extends Script { private Position[] path = { new Position(2710, 3462, 0), new Position(2717, 3463, 0), new Position(2719, 3469, 0), new Position(2719, 3476, 0), new Position(2718, 3483, 0), new Position(2725, 3488, 0), new Position(2724, 3493, 0), }; private static final Area TREE_AREA = new Area(2716, 3458, 2704, 3464); private static final Area BANK_AREA = new Area(2721, 3493, 2729, 3490); @Override public void onStart() { "script under development" } private enum State { CHOP, WALK_TO_BANK, BANK, WALK_TO_TREES, WAIT, }; private State getState() { if (inventory.isFull() && TREE_AREA.contains(myPlayer())) return State.WALK_TO_BANK; if (!inventory.isFull() && BANK_AREA.contains(myPlayer())) return State.WALK_TO_TREES; if (inventory.isFull() && BANK_AREA.contains(myPlayer())) return State.BANK; return State.CHOP; } private boolean walkTile(Position p) throws InterruptedException { client.moveMouse(new MinimapTileDestination(bot, p), false); sleep(random(150, 250)); client.pressMouse(); int failsafe = 0; while (failsafe < 10 && myPlayer().getPosition().distance(p) > 2) { sleep(200); failsafe++; if (myPlayer().isMoving()) failsafe = 0; } if (failsafe == 10) return false; return true; } return State.CHOP; } @Override public boolean execute() throws java.lang.InterruptedException { switch (getState()) { case CHOP: if (!myPlayer().isAnimating()) { RS2Object tree = objects.closest(YEW); if (tree != null) { if (tree.interact("Chop-Down")) sleep(random(1000, 1500)); } } break; case WALK_TO_BANK: traversePath(path, false); sleep(random(1500, 2500)); break; case WALK_TO_TREES: traversePath(path, true); sleep(random(1500, 2500)); break; case BANK: RS2Object bankBooth = objects.closest("Bank booth"); if (bankBooth != null) { if (bankBooth.interact("Bank")) { while (!bank.isOpen()) sleep(250); bank.depositAll(); } } break; } return random(200, 700); } @Override public void onExit() { } @Override public void onPaint(Graphics2D g) { } } Formatted so its readable Umm you should make it try open the bank if its not open only otheriwse it'll keep trying even if open. and use bank.open(); Also i dunno if interact method supports camera turning does it? if it doesn't you might want to check if the object is on the screen before interacting with it waaiiiiiit a minute -.- How old is the jar you're using as a library? execute isnt an inherent method of script, you should have onLoop()
March 18, 201510 yr Execute IS a method inheritable from Script; but it should never be overridden, since it's what we use to execute events. Altho the method signature seems wrong. The main issues I see with your code, though, is that you seem to cut off your class early, and attempt to return a value outside of a method. here: return State.CHOP; } ^ these should probably be removed. But I can't really tell if the indentation is correct; so I'm not entirely certain. In any case, you cannot return a value outside of methods. Also you should not override execute(), like Isolate said. The main script loop method should be called onLoop, and return an integer value indicating the number of milliseconds to sleep for, until the next loop cycle begins. Edited March 18, 201510 yr by FrostBug
March 18, 201510 yr Author @ Isolate Formatted so its readableUmm you should make it try open the bank if its not open only otheriwse it'll keep trying even if open.and use bank.open();Also i dunno if interact method supports camera turning does it?if it doesn't you might want to check if the object is on the screen before interacting with it waaiiiiiit a minute -.-How old is the jar you're using as a library? execute isnt an inherent method of script, you should have onLoop() yo Iso, Soz about format I'm using java SE 1.7 Thanks for help again dude ill keep tweaking it will post a revised version tomorrow.
March 18, 201510 yr @ Isolate yo Iso, Soz about format I'm using java SE 1.7 Thanks for help again dude ill keep tweaking it will post a revised version tomorrow. He didn't ask your java version, how old is the OSBot.jar your using? Hes saying its probably ancient and ya need to update.
March 18, 201510 yr 2.3.44 ? I thought older versions are unsupported? I was thrown off by you using execute instead of onLoop is all Edited March 18, 201510 yr by Isolate