Swhit Posted May 14, 2015 Share Posted May 14, 2015 (edited) Hello all, I am trying to make a simple script that will walk to a rockfall, mine it, then walk back to the bank chest in motherlode mining. My code so far is as follows: import org.osbot.rs07.api.map.Position;import org.osbot.rs07.api.model.Entity;import org.osbot.rs07.script.Script;import org.osbot.rs07.script.ScriptManifest;import org.osbot.rs07.api.model.RS2Object;import org.osbot.rs07.utility.Area;import org.osbot.rs07.api.Map;import org.osbot.rs07.input.mouse.MiniMapTileDestination;import org.osbot.rs07.api.Mouse;import java.awt.*;@ScriptManifest(author = "Swhit", info = "Runs to rockfall, mines it, then runs back to bank",name = "Rock Runner", version = 0.1, logo = "")@SuppressWarnings("unused")/*Runs to rockfall, mines it, then runs back to bank */public class main extends Script {private enum State {MINE, WALK_TO_ROCK, WALK_TO_BANK, BANK};// private static final int[] VEIN_ID = {// //mine these!// 26661, 26664, 26662, 26663// }; //these are the vein IDsprivate static final int[] ROCKFALL_ID = {//rockfall ID nums26679, 26680};boolean deposited;boolean mined;//rectangle in front of motherlode mining bankprivate static final Area BANK_AREA = new Area(3757, 5670, 3760, 5664);private static final Area MINE_AREA = new Area(3759, 5653, 3763, 5651);private Position[] path = {new Position(3760, 5666, 0), //banknew Position(3762, 5653, 0), //near rockfallnew Position(3761, 5653, 0) //testing purposes only};@Overridepublic void onStart() {log("Let's get started!"); //logs to console below window//This loop is only one once when starting code.//use to initialize timers, variables, etc.deposited = false;mined = false;}private State getState() {// if (inventory.isFull() && MINE_AREA.contains(myPlayer() ) )//example of working if ^if (BANK_AREA.contains(myPlayer() ) && !deposited) {return State.BANK;}else if (BANK_AREA.contains(myPlayer() ) && deposited) {return State.WALK_TO_ROCK;}else if (MINE_AREA.contains(myPlayer() ) && !mined) {return State.MINE;}return State.WALK_TO_BANK;}private void traversePath(Position[] path, boolean reversed) throws InterruptedException {if (!reversed) {for (int i = 1; i < path.length; i++) {if (!walkTile(path)) {i--;}}} else {//reversed = truefor (int i = path.length-2; i > 0; i--) {if (!walkTile(path)) {i++;}}}}private boolean walkTile(Position p) throws InterruptedException {Mouse clicker = new Mouse();clicker.move(new MiniMapTileDestination(bot, p));sleep(random(200,300));clicker.click(false); //false = left clickint failsafe = 0;while (failsafe < 10 && myPlayer().getPosition().distance(p) > 3) {sleep (300);failsafe++;if (myPlayer().isMoving() )failsafe = 0;} //whileif (failsafe == 10)return false;return true;}@Overridepublic int onLoop() throws InterruptedException {switch (getState() ) {case MINE:log("case: MINE");if (!myPlayer().isAnimating() ) {RS2Object rFall = objects.closest(ROCKFALL_ID);if (rFall != null) {rFall.interact("Mine");sleep( random( 1000, 1500 ) );log("rock was mined");//check if the rock was mined??mined = true;}// rFall = objects.closest(ROCKFALL_ID);// if (rFall != null) {// mined = true;// }}break;case WALK_TO_BANK:log("case: WALK_TO_BANK");traversePath(path, true);sleep( random( 1500, 2500 ) );//resetting mined variableif (!MINE_AREA.contains(myPlayer() ) && mined) {log("MINE AREA DOES NOT CONTAIN PLAYER");mined = false;}//inventory.dropAll();break;case WALK_TO_ROCK:log("case: WALK TO ROCK");traversePath(path, false);sleep( random( 1500, 2500) );//resetting deposited to falseif (!BANK_AREA.contains(myPlayer() ) && deposited) {log("BANK AREA DOES NOT CONTAIN PLAYER");deposited = false;}break;case BANK:log("case: BANK");//bankingRS2Object bankBooth = objects.closest("Bank chest");if (bankBooth != null) {if (bankBooth.interact("Use")) {log("banking");while(!bank.isOpen() ) {sleep(250);}bank.depositAllExcept("Dragon pickaxe");deposited = true;}}break;} //switchreturn random(200, 300); //delay}@Overridepublic void onExit() {log("Thanks for running my script, ya hobo.");//only one once, when user ends script. Used commonly to//log details of how script went. For example, how many//teas you stole... etc.}@Overridepublic void onPaint(Graphics2D g) {//used to display writing and info to screen.}} The error I am getting occurs while banking and gives the following print out: [iNFO][bot #1][05/13 08:13:41 PM]: case: WALK TO ROCK [ERROR][bot #1][05/13 08:13:41 PM]: Error in script executor! java.lang.NullPointerException at org.osbot.rs07.script.MethodProvider.execute(kc:642) at org.osbot.rs07.api.Mouse.move(no:14) at org.osbot.rs07.api.Mouse.move(no) at main.walkTile(main.java:96) at main.traversePath(main.java:79) at main.onLoop(main.java:150) at org.osbot.rs07.event.ScriptExecutor$InternalExecutor.run(qj:191) at java.lang.Thread.run(Unknown Source) Any ideas? Edited May 14, 2015 by Swhit Quote Link to comment Share on other sites More sharing options...
Mysteryy Posted May 14, 2015 Share Posted May 14, 2015 Please repost it in a readable format. Its hurting my eyes. :p Quote Link to comment Share on other sites More sharing options...
Swhit Posted May 14, 2015 Author Share Posted May 14, 2015 Well, now the indentation is messed up but at least the alternating background line colors are gone. What the heck. I think the error is in here: private boolean walkTile(Position p) throws InterruptedException {Mouse clicker = new Mouse();clicker.move(new MiniMapTileDestination(bot, p));sleep(random(200,300));clicker.click(false); //false = left clickint failsafe = 0;while (failsafe < 10 && myPlayer().getPosition().distance(p) > 3) {sleep (300);failsafe++;if (myPlayer().isMoving() )failsafe = 0;} //whileif (failsafe == 10)return false;return true;} Also, I made this script based off a tutorial by /user/Pandemic: LINK The confusion came when trying to implement his movement methods, because I couldn't find some of the functions or entities that he used. Quote Link to comment Share on other sites More sharing options...
FrostBug Posted May 14, 2015 Share Posted May 14, 2015 The problem is here: Mouse clicker = new Mouse(); clicker.move(new MiniMapTileDestination(bot, p)); sleep(random(200,300)); clicker.click(false); //false = left click You cannot instantiate your own instances of API classes like that without exchanging bot contexts with it. What you simply need to do (in the context of the Script class, like in your case here) is use getMouse() instead, as Script already inherits from MethodProvider and has pre-initialized instances of all the API classes. so it should just be: getMouse().move(new MiniMapTileDestination(bot, p)); sleep(random(200,300)); getMouse().click(false); //false = left click 1 Quote Link to comment Share on other sites More sharing options...
Swhit Posted May 14, 2015 Author Share Posted May 14, 2015 The problem is here: Mouse clicker = new Mouse(); clicker.move(new MiniMapTileDestination(bot, p)); sleep(random(200,300)); clicker.click(false); //false = left click You cannot instantiate your own instances of API classes like that without exchanging bot contexts with it. What you simply need to do (in the context of the Script class, like in your case here) is use getMouse() instead, as Script already inherits from MethodProvider and has pre-initialized instances of all the API classes. so it should just be: getMouse().move(new MiniMapTileDestination(bot, p)); sleep(random(200,300)); getMouse().click(false); //false = left click Ahh, very cool. Thanks! Quote Link to comment Share on other sites More sharing options...