Booleans YAY Posted January 7, 2017 Share Posted January 7, 2017 So this is going to be a beginners guide into utilizing a walking function. This is by all means a standard walker and doesn't support any objects blocking path, different types of objects could be in your way so for sake of simplicity i'll leave it out and if you'd like just request me to do a snippet on walking with object interacts, etc.. Suggest me any script and I can probably do it (still learning some small stuff, but majority is pretty ez pz). Firstly, i'd like you to just read the bullet points below, then read the code and understand the functions, and not get overwhelmed by something that you may not understand at first okay; take your time to understand the functions and ways around the OSB API. If you have any questions feel free to PM me or post on my profile wall, etc.. always willing to help with my current knowledge. For coordinations I just use: https://explv.github.io/ (source code Javascript: https://github.com/Explv/Explv.github.io) credits: Explv Position (this is our destination in where we're trying to head towards automatically for us instead of that long grind in walking. Includes a script run time length Supports the Run function for the player (set Run on startup, also comes with a random chance for run checking) Dismisses the pesky random events that pop up sometimes, also stores an integer value that increments every time we dismiss one For sake of a anti ban like method moving our Mouse to -1,-1 coordinates will make it look like a human like AFK (TODO: Test) If the player is under attack, the player will activate Run mode and will continue to run to destination regardless Standard String drawing for paint (displays any info we collect through variables(example: run time, events dismissed)) package main.script.Bot_Walker; import java.awt.BasicStroke; import java.awt.Color; import java.awt.Font; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.Point; import java.awt.RenderingHints; import java.text.NumberFormat; import org.osbot.rs07.api.map.Position; import org.osbot.rs07.api.model.NPC; import org.osbot.rs07.script.Script; public class AutoWalker extends Script { private long timeStarting = System.currentTimeMillis(); private int randomsDismissed; private Position destination = new Position(3222, 3222, 0); @[member=Override] public void onStart() throws InterruptedException { log("Starting up the bot walking"); timeStarting = System.currentTimeMillis(); getSettings().setRunning(true); } private boolean dismissRandom() { for (NPC randomEvent : npcs.getAll()) { if (randomEvent == null || randomEvent.getInteracting() == null || randomEvent.getInteracting() != myPlayer()) { continue; } if (randomEvent.hasAction("Dismiss")) { randomEvent.interact("Dismiss"); randomsDismissed++; return true; } } return false; } @[member=Override] public int onLoop() throws InterruptedException { int randomRun = random(5); if (randomRun == 1) { getSettings().setRunning(getSettings().getRunEnergy() < 25 ? false : true); } if (dismissRandom()) { while (myPlayer().isMoving()) { sleep(random(600, 800)); } } while (myPlayer().isAnimating()) { mouse.move(-1, -1); } if (myPlayer().isUnderAttack()) { getSettings().setRunning(true); getWalking().webWalk(destination); } getWalking().webWalk(destination); return random(200, 300); } @[member=Override] public void onPaint(Graphics2D graphics) { drawMouse(graphics); Font font = new Font("TimesRoman", Font.PLAIN, 12); graphics.setFont(font); graphics.setColor(Color.WHITE); graphics.drawString("Auto Walker script created by: Booleans Yay", 140, 325); graphics.drawString("Randoms Dismissed: " + formatIntegers(randomsDismissed), 5, 55); long runTime = System.currentTimeMillis() - timeStarting; graphics.drawString("Script Runtime: " + formatTime(runTime), 5, 85); } private void drawMouse(Graphics graphics) { ((Graphics2D) graphics).setRenderingHints( new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON)); Point pointer = mouse.getPosition(); Graphics2D spinG = (Graphics2D) graphics.create(); Graphics2D spinGRev = (Graphics2D) graphics.create(); spinG.setColor(new Color(255, 255, 255)); spinGRev.setColor(Color.cyan); spinG.rotate(System.currentTimeMillis() % 2000d / 2000d * (360d) * 2 * Math.PI / 180.0, pointer.x, pointer.y); spinGRev.rotate(System.currentTimeMillis() % 2000d / 2000d * (-360d) * 2 * Math.PI / 180.0, pointer.x, pointer.y); final int outerSize = 20; final int innerSize = 12; spinG.setStroke(new BasicStroke(1.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND)); spinGRev.setStroke(new BasicStroke(1.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND)); spinG.drawArc(pointer.x - (outerSize / 2), pointer.y - (outerSize / 2), outerSize, outerSize, 100, 75); spinG.drawArc(pointer.x - (outerSize / 2), pointer.y - (outerSize / 2), outerSize, outerSize, -100, 75); spinGRev.drawArc(pointer.x - (innerSize / 2), pointer.y - (innerSize / 2), innerSize, innerSize, 100, 75); spinGRev.drawArc(pointer.x - (innerSize / 2), pointer.y - (innerSize / 2), innerSize, innerSize, -100, 75); } public static String formatIntegers(int number) { return NumberFormat.getInstance().format(number); } public final String formatTime(final long milisecond) { long s = milisecond / 1000, m = s / 60, h = m / 60, d = h / 24; s %= 60; m %= 60; h %= 24; return d > 0 ? String.format("%02d:%02d:%02d:%02d", d, h, m, s) : h > 0 ? String.format("%02d:%02d:%02d", h, m, s) : String.format("%02d:%02d", m, s); } } Quote Link to comment Share on other sites More sharing options...
Team Cape Posted January 7, 2017 Share Posted January 7, 2017 A couple of things: The RandomEventHandler generally handles/dismisses randoms. No need to have your own method for it. Also, never compare objects using == or != unless they are enum values (static and final, specific values). If you've already null checked them, there's no reason to compare them without .equals() like right here: randomEvent.getInteracting() != myPlayer() This line: getSettings().setRunning(getSettings().getRunEnergy() < 25 ? false : true); can be more succinctly stated as: getSettings().setRunning(getSettings().getRunEnergy() >= 25); because it returns a boolean. There's no reason to restate something you already know. while (myPlayer().isAnimating()) { mouse.move(-1, -1); } ^ Essentially the same thing, but please just say getMouse().moveOutsideScreen(). Also, the webwalker executes completely in one-go. This means that your code will probably only be utilized once before the walker is used and takes you to the correct destination. In the onPaint() method, please don't define a new font each time. Create one font at the very beginning (because note that onPaint() is restored multiple times and very quickly - this takes up resources), and set the font at the beginning. No need for a new font object on each run. (Graphics2D) graphics).setRenderingHints... There is no need to pass in a type Graphics to this method because you know you're going to be passing in a Graphics2D. This means that there's also no need to cast. spinG.setColor(new Color(255, 255, 255)); Same as the font thing. Quote Link to comment Share on other sites More sharing options...
Saiyan Posted January 7, 2017 Share Posted January 7, 2017 private boolean dismissRandom() { for (NPC randomEvent : npcs.getAll()) { if (randomEvent == null || randomEvent.getInteracting() == null || randomEvent.getInteracting() != myPlayer()) { continue; } if (randomEvent.hasAction("Dismiss")) { randomEvent.interact("Dismiss"); randomsDismissed++; return true; } } return false; } As imate said, i think the randoms event dismisser will override this method anyway so you're basically getting counts of it being dismissed based on the random event doing it. (I could be wrong though in how I just said this though) and yeah like he also said for the mouse thing, you could look around in the api and you'd see methods such as getMouse().isOnScreen() getMouse().moveOutsideScreen() and use cond sleeps etc to deduce if the action has been complete For a first attempt though I think this is good Quote Link to comment Share on other sites More sharing options...