S3R0 Posted March 14, 2016 Share Posted March 14, 2016 Hello, I have been working on a script and it seems as though onLoop doesn't want to function. Maybe it's just me, but I think this works just fine? @Override public int onLoop() throws InterruptedException { //SCRIPT CODE HERE } I know it's not much, but could there be other factors affecting how the script is running? I can post the rest of the code, if needed. 1 Quote Link to comment Share on other sites More sharing options...
Keven Posted March 14, 2016 Share Posted March 14, 2016 Please post the rest of the code. Quote Link to comment Share on other sites More sharing options...
S3R0 Posted March 14, 2016 Author Share Posted March 14, 2016 package zulFisher; import java.awt.*; import java.awt.geom.AffineTransform; import java.awt.geom.Arc2D; import javax.imageio.ImageIO; import java.io.IOException; import java.net.URL; import java.util.LinkedList; //import java.util.List; //import org.osbot.rs07.api.NPCS; //import org.osbot.rs07.api.Players; import org.osbot.rs07.api.model.Entity; import org.osbot.rs07.api.ui.Skill; //import org.osbot.rs07.api.model.NPC; //import org.osbot.rs07.api.model.Player; //import org.osbot.rs07.api.ui.Option; import org.osbot.rs07.api.ui.Tab; //import org.osbot.rs07.input.mouse.EntityDestination; //import org.osbot.rs07.input.mouse.MouseDestination; import org.osbot.rs07.script.Script; import org.osbot.rs07.script.ScriptManifest; @ScriptManifest(author = "S3R0", info = "A simple bot that fishes for Sacred Eels at Zul-Andra and cuts them for scales.", logo = "", name = "ZulFisher", version = 0.1) public class ZulFisher extends Script { //Enums enum State { CHECKINV, FISHSACREDEELS, GATHERSCALES; } //State State state; //Strings String botStatus = ""; //Ints int eelsCaught = 0; //Time long startTime; //Code to be executed on start public void onStart() { log("Starting ZulFisher by S3R0"); log("Current version is 1.0"); startTime = System.currentTimeMillis(); state = State.CHECKINV; } //Code to be executed on exit public void onExit() { log("Thank you for using my script!"); } //Stop Script public void exitScript(Boolean StopScript) { if(StopScript == true) { try { getBot().getScriptExecutor().stop(); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } //Code for Main Loop @Override public int onLoop() throws InterruptedException { switch(state) { case CHECKINV: if(!inventory.isFull() & inventory.contains("Bait", "Fishing rod")) { state = State.FISHSACREDEELS; } else if (!inventory.contains("Bait")) { log("Fishing bait missing from inventory. Script shutting down..."); exitScript(true); } else if (!inventory.contains("Fishing rod")) { log("Fishing rod missing from inventory. Script shutting down..."); exitScript(true); } else if (inventory.isFull() & inventory.contains("Sacred eel")) { if(inventory.contains("Knife")) { state = State.GATHERSCALES; } else if (!inventory.contains("Knife")) { log("Knife missing from inventory. Script shutting down..."); exitScript(true); } } else { log("Unable to continue due to not having enough inventory space (too many items!). Script shutting down..."); exitScript(true); } break; case FISHSACREDEELS: Entity fishSpot = objects.closest("Fishing spot"); if(fishSpot != null) { if(fishSpot.isVisible()) { if(!myPlayer().isAnimating()) { fishSpot.interact("Fishing spot"); botStatus = "Fishing for Sacred Eels"; } else { state = State.CHECKINV; } } else { camera.toString().indexOf("Fishing spot"); botStatus = "Moving camera to fishing spot"; } } break; case GATHERSCALES: if(tabs.getOpen() != Tab.INVENTORY) { tabs.open(Tab.INVENTORY); botStatus = "Opening inventory tab"; } while (inventory.contains("Sacred eel")) { if(!myPlayer().isAnimating()) { inventory.interact("Use", "Knife"); botStatus = "Using knife on Sacred Eel"; sleep(random(200, 400)); inventory.interact("Use", "Sacred eel"); botStatus = "Gathering Zulrah Scales"; } } state = State.CHECKINV; break; default: log("Jet fuel can't melt Zulrah scales"); break; } return 100 * (random(50)); } //Code for Paint //Interface private final Color fontColor = new Color(58, 57, 46); private final Font fontInterface = new Font("Arial", 0, 9); private final Image imgInterface = getImage("http://i.imgur.com/IPbEQiw.jpg"); //Mouse private int mX, mY; private long angle; private BasicStroke cursorStroke = new BasicStroke(2); private Color cursorColor = Color.getColor("#8F8F6B"); private AffineTransform oldTransform; //Getting Interface Image private Image getImage(String url) { try { return ImageIO.read(new URL(url)); } catch(IOException e) { log("Error downloading image..."); return null; } } public void onMessage(String message) { if(message.contains("You catch a sacred eel")) { eelsCaught++; } } public void onPaint(Graphics grafix) { long timeElapsed = System.currentTimeMillis() - startTime; long sec = (timeElapsed / 1000) % 60; long min = (timeElapsed / (1000 * 60)) % 60; long hr = (timeElapsed / (1000 * 60 * 60)) % 24; //Code for interface paint Graphics2D g = (Graphics2D) grafix; g.drawImage(imgInterface, 1, 335, null); g.setFont(fontInterface); g.setColor(fontColor); g.drawString("Time Running: " + hr + ":" + min + ":" + sec, 301, 361); g.drawString("Status: " + botStatus, 301, 373); g.drawString("Current Fishing Level: " + getSkills().getStatic(Skill.FISHING), 301, 392); g.drawString("Exp Gained: N/A", 301, 404); g.drawString("Eels Collected: " + eelsCaught , 301, 416); g.drawString("Current Cooking Level: " + getSkills().getStatic(Skill.COOKING), 301, 436); g.drawString("Exp Gained: N/A", 301, 448); g.drawString("Scales Collected: N/A", 301, 460); //Code for mouse paint Point mP = getMouse().getPosition(); g.drawLine(mP.x - 5, mP.y + 5, mP.x + 5, mP.y - 5); g.drawLine(mP.x + 5, mP.y + 5, mP.x - 5, mP.y - 5); //Mouse Rotation oldTransform = g.getTransform(); mX = mouse.getPosition().x; mY = mouse.getPosition().y; LinkedList<MousePathPoint> mousePath = new LinkedList<>(); g.setRenderingHints(new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON)); //MOUSE TRAIL while (!mousePath.isEmpty() && mousePath.peek().isUp()) mousePath.remove(); Point clientCursor = mouse.getPosition(); MousePathPoint mpp = new MousePathPoint(clientCursor.x, clientCursor.y, 300); if (mousePath.isEmpty() || !mousePath.getLast().equals(mpp)) mousePath.add(mpp); MousePathPoint lastPoint = null; for (MousePathPoint a : mousePath) { if (lastPoint != null) { g.setColor(new Color(160, 160, 120, a.getAlpha())); //trail color g.drawLine(a.x, a.y, lastPoint.x, lastPoint.y); } lastPoint = a; } if (mX != -1) { g.setStroke(cursorStroke); g.setColor(cursorColor); g.drawLine(mX-3, mY-3, mX+2, mY+2); g.drawLine(mX-3, mY+2, mX+2, mY-3); g.rotate(Math.toRadians(angle+=6), mX, mY); g.draw(new Arc2D.Double(mX-12, mY-12, 24, 24, 330, 60, Arc2D.OPEN)); g.draw(new Arc2D.Double(mX-12, mY-12, 24, 24, 151, 60, Arc2D.OPEN)); g.setTransform(oldTransform); } } /*private boolean hoverEntityOption(Entity entity, String option) throws InterruptedException { if(entity == null) return false; if(menu.isOpen()) { List<Option> options = menu.getMenu(); if(options != null) { Rectangle optionRec = null; for(int index = 0; index < options.size(); index++) { if(options.get(index).action.equals(option)) { optionRec = menu.getOptionRectangle(index); if(optionRec != null) { if(!optionRec.contains(mouse.getPosition())) { int x = menu.getX() + Script.random(10, 160); int y = menu.getY() + 23 + index * 15; Script.sleep(Script.random(200, 400)); return mouse.move(x, y); } } } } } } else { EntityDestination ed = new EntityDestination(bot, entity); mouse.click(ed, true); } return false; }*/ //AntiBan //@SuppressWarnings("unchecked") /*public void AntiBan() throws InterruptedException{ int rand = random(0,random(5000,10000)); if(rand == random(0,random(0,100))){ log("Rotating camera."); switch(random(0,4)%2){ case 0: getCamera().moveYaw(random(0, 3000)); break; case 1: getCamera().movePitch(random(60,400)); break; } } else if(rand == random(random(0,300), random(300,400))){ log("Varied sleep."); sleep(random(0,5000)); } else if(rand == 10000){ log("Idling to log out!"); sleep(random(310000,380000)); } }*/ } Sure thing. Before you say anything, the code may be bad? Might be okay? I don't know. I don't plan on releasing this. It's just for my own personal use, since no one has created a Sacred Eels bot, other than part of an AIO Fishing. That, and I'm learning some parts of the API as I go. Please be gentle... 1 Quote Link to comment Share on other sites More sharing options...
Token Posted March 14, 2016 Share Posted March 14, 2016 Is the script spamming "Jet fuel can't melt Zulrah scales" or does it exit with an error onStart message? Quote Link to comment Share on other sites More sharing options...
Isolate Posted March 14, 2016 Share Posted March 14, 2016 (edited) switch(state) seems legit (maybe I should provide more context) Maybe just a neaten up would help see what's going on here. package Private; import org.osbot.rs07.script.Script; /** * Created by Jordan on 14/03/2016. */ public class States extends Script { @Override public int onLoop() throws InterruptedException { switch (getState()){ case DROP: //drop break; case CHOP: //chop break; } return random(500, 900); } private State getState(){ if(!getInventory().isEmpty()) return State.DROP; else return State.CHOP; } private enum State{ DROP, CHOP } } what's the actual error/output you're getting Edited March 14, 2016 by Isolate Quote Link to comment Share on other sites More sharing options...
S3R0 Posted March 14, 2016 Author Share Posted March 14, 2016 (edited) switch(state) seems legit (maybe I should provide more context) Maybe just a neaten up would help see what's going on here. package Private; import org.osbot.rs07.script.Script; /** * Created by Jordan on 14/03/2016. */ public class States extends Script { @Override public int onLoop() throws InterruptedException { switch (getState()){ case DROP: //drop break; case CHOP: //chop break; } return random(500, 900); } private State getState(){ if(!getInventory().isEmpty()) return State.DROP; else return State.CHOP; } private enum State{ DROP, CHOP } } what's the actual error/output you're getting It literally does nothing. It won't interact with anything, paint won't load. The only thing that does load is getStart. Code has been updated to use getState instead of just state. UPDATE: It's starting to work now, I've found a huge issue that's been resolved. My only problem now really is getting the paint to show.. Edited March 14, 2016 by S3R0 1 Quote Link to comment Share on other sites More sharing options...
Isolate Posted March 14, 2016 Share Posted March 14, 2016 It literally does nothing. It won't interact with anything, paint won't load. The only thing that does load is getStart. Code has been updated to use getState instead of just state. UPDATE: It's starting to work now, I've found a huge issue that's been resolved. My only problem now really is getting the paint to show.. @Override public void onPaint(Graphics2D g) { super.onPaint(g); } Quote Link to comment Share on other sites More sharing options...
S3R0 Posted March 14, 2016 Author Share Posted March 14, 2016 (edited) @Override public void onPaint(Graphics2D g) { super.onPaint(g); } That seemed to kinda work. Paint doesn't seem to overlay over anything though (inventory, minimap, chatbox, etc). Is there like a Z index that needs to be edited for that to happen? Or is it something different? EDIT: Script is working and paint is working as well. Please close topic. Edited March 15, 2016 by S3R0 Quote Link to comment Share on other sites More sharing options...