-
Posts
27 -
Joined
-
Last visited
-
Days Won
2
Reputation Activity
-
Realistic reacted to holic in Random Event Handler - a collection of 8 complete random event solvers!
RandomHandler
One of the great things of the old days of OSRS cheating, especially when SCAR was popular, was the sharing and co-development of things like random event solvers so I'm bringing it back.
Here you'll find a collect of random solvers that work out of the box, save for adding the package to these files. More will be added as I encounter them and have the time to solve them.
Supported Random Events: Genie, Mysterious Old Man, Drunken Dwarf, Ricky Turpentine, Freaky Forester, Frog, Beekeeper, and a generic Dismiss handler
Usage
Add the files to your script, ideally in a folder named randoms. Add RandomHandler.loadRandoms(); to onStart. Add RandomHandler.clearRandoms(); to onExit. Use RandomHandler.loadRandom(Event.DRUNKEN_DWARF) and RandomHandler.unloadRandom(Event.DRUNKEN_DWARF) respectively to only load your desired solver. Lamp will automatically be used by GenieSolver, to take care of it manually, remove the line from GenieSolver and use RandomHandler.useLamp(); where desired. Watch the magic happen! I will be adding more options for loading and unloading specific random events
Issues
Currently, the onPaint doesn't seem to work but that's all.
GitHub
https://github.com/blakeaholics/DreamBot-RandomHandler
-
Realistic reacted to Pandemic in DreamBot 3 Miner Tutorial, Part 2
Hello everyone, it has been a couple years since I released the first part of this so I thought it was about time to write the next part.
Anywho, this will directly build off of what we had in Part 1, which you can find here:
Prerequisites
You should have already have a project with everything we added in Part 1.
Project Layout
This will be the final layout of the project once we're finished:
The Script
Just as in Part 1, let's define what our goals are for the end of this part:
We want to show a GUI to let the user choose if they want to power mine or bank at the nearest bank Since all great scripts support QuickStart, we also want to support QuickStart parameters to avoid needing manual input from the GUI We need to add a new task to handling banking, and extend our mining task to let it walk back once it's done banking src/gui/GUI.java, the script's GUI
Here's the simple GUI that we'll be using:
The final GUI once we add the modes will look like this, just as we designed it above:
Points of Interest:
JFrame: Our GUI class extends JFrame, which is provided by Java's Swing Constructor: Our constructor takes one parameter, our main script instance, so that we can let it know what mode to start the script in MigLayout: You can see we set our frame's layout to use MigLayout, this is mostly just preference however I would highly recommend using it as it's pretty easy to learn and extremely powerful JLabel/JComboBox/JButton: These are all Swing components that make up our GUI, see the link above for more examples of these and how to use them JComboBox<Miner.Mode> modeComboBox: This is the dropdown that will let the users select which mode they want to use. It's provided all of Miner.Mode's possible values, which we'll add below. I prefer using enums instead of String's or anything else here simply because it's much harder to mess up and it allows us to add more (or change) modes in the future without ever worrying about the GUI class. src/Miner.java, the script's main class
Show the GUI
We have a few changes we have to make to our main class to show the new GUI and use the mode it sends over, so let's remove this line from our onStart:
addNodes(new MiningTask(), new DropTask()); and add this line in its place:
SwingUtilities.invokeLater(() -> new GUI(this)); This will create and pass in the script instance so the GUI can let the know script once the users chooses a mode. You should always perform any Swing component creation or modification on the AWT thread, which you can do just by wrapping it in that invokeLater.
Add the Mode Enum
Now we'll need to provide the script modes we want the GUI to show, so we add this at the bottom of our script class (but still before the final closing curly brace):
public enum Mode { POWER_MINE, BANK; @Override public String toString() { // We override the toString so the GUI can show friendlier options than POWER_MINE to the user switch (this) { case POWER_MINE: return "Power mine"; case BANK: return "Bank at the nearest bank"; default: return "Blame Yeeter"; } } } Add the setMode Method
Now we have the mode enum which the GUI will use to show available options, but we still need to create the setMode method we used in the GUI class, which you can add after your onPaint:
/** * This adds the tasks necessary to run the script in the provided {@link Mode} * @param mode the script mode to use */ public void setMode(Mode mode) { addNodes(new MiningTask()); // We always want to mine switch (mode) { case POWER_MINE: addNodes(new DropTask()); // Add the drop task if the user selected power mining break; case BANK: addNodes(new BankTask()); // Add the bank task if they chose banking break; } } QuickStart Support
So now the GUI can set the script's mode, but what if you want to support QuickStart so you don't have to use a GUI every time?
Supporting QuickStart script parameters is pretty easy, as the client will call onStart(String...) instead of the normal onStart we have now, so we can support it by adding in this new onStart after our current one:
/** * This onStart is called only if the user starts the script using QuickStart with parameters. * * We check the parameters to see how to set the script up without needing to show a GUI that would require user * input. * * @param params the QuickStart parameters passed in from the command line */ @Override public void onStart(String... params) { // Start DreamBot's skill tracker for the mining skill, so we can later see how much experience we've gained SkillTracker.start(Skill.MINING); if (params != null && params.length > 0) { String modeParameter = params[0]; // Grab the first parameter passed via QuickStart if ("powermine".equalsIgnoreCase(modeParameter)) { setMode(Mode.POWER_MINE); } else if ("bank".equalsIgnoreCase(modeParameter)) { setMode(Mode.BANK); } else { Logger.error("Unknown script mode: '" + modeParameter + "', try 'bank' or 'powermine' instead."); stop(); } } } That's it!
If you followed along above, our Miner.java class should look like this now:
src/tasks/BankTask.java, the banking task
Now that the GUI (and QuickStart) can set the script mode, we need to add the final missing piece which is banking support:
So just like the DropTask class, the BankTask class will execute if the inventory is full. It's a fairly simple class that just walks towards the nearest bank and deposits everything (except your pickaxe). DreamBot knows about most of the banks in the game, and our web walker is capable of walking to a vast majority of the map without needing more information from the scripter. This is why you're able to just call Bank#open (or Walking#walk) from anywhere and it knows where to go, regardless of where you start this script.
src/tasks/MiningTask.java, the mining task
Back to our MiningTask class, we now need to add a couple things since now after banking we'll be lost and have no clue how to get back to the rocks we were mining earlier.
First we'll add a new class member which is a Tile where we'll store the last mined rock location, just add this right after the first opening curly brace:
public class MiningTask extends TaskNode { private Tile lastMinedRockTile = null; // the rest of the script Now we need to set this tile whenever we interact with a rock, so we can add that right after interacting with a rock:
if (rock.interact("Mine")) { // If we successfully click on the rock lastMinedRockTile = rock.getTile(); // Set the last rock tile in case we need to walk back at some point Sleep.sleepUntil(this::isMining, 2500); // Wait until we're mining, with a max wait time of 2,500ms (2.5 seconds) } So now that tile is set after we interact with any rocks, so let's let the script walk us back here if we're too far away (most likely from banking) which we can do inside of our null check of the rock:
if (rock == null) { // If there aren't any available rocks near us if (lastMinedRockTile != null && lastMinedRockTile.distance() > 8) { // and we're far from the last mined rock Walking.walk(lastMinedRockTile); // we should walk towards that rock Sleep.sleepUntil(Walking::shouldWalk, () -> Players.getLocal().isMoving(), 1000, 100); return 100; } // We should just wait until one's available return Calculations.random(500, 1000); } Finally, let's add one more check to our getClosestRock method to make sure we're close enough to it:
/** * Finds the closest acceptable rock that we can mine * * @return The closest GameObject that has the name 'Rocks', with the action 'Mine', and non-null model colors * within 10 tiles */ private GameObject getClosestRock() { return GameObjects.closest(object -> object.getName().equalsIgnoreCase("Rocks") && object.hasAction("Mine") && object.distance() < 10 && // new distance check here object.getModelColors() != null); } That's it!
If you followed along above, our MiningTask.java class should look like this now:
We're Done!
Now just as before, just compile and build the artifact and try out the script.
Attached below is the entire project source that you can use in case you got lost anywhere.
If you have any questions or have anything you'd like to see included for the end result, please post it below.
Thanks for reading!
Miner-Part-2.zip
-
Realistic reacted to lolwat in BotBuddy, Open Source Dreambot Manager [Jagex account support, True automation]
I have been upgrading the panel a little lately.
automatically replace banned accounts, on a per-script level automatically replace finished accounts on AB's, if they report their success to logfile staggering launching of instances is now possible
Small example of the handiwork:
if config.BannedAction != 0 { Helpers.KillBot(id, customer) if config.BannedAction == -1 { _, err = Storage.GetDb().Exec("DELETE FROM accounts WHERE id = ?", id) if err != nil { fmt.Println("Daemon:", err) } } else if config.BannedAction == -2 { // something but i forgot } else if config.BannedAction > 0 { _, err = Storage.GetDb().Exec("UPDATE accounts SET schedule = 0, proxy_id = 0, group_id = ? WHERE id = ?", config.BannedAction, id) if err != nil { fmt.Println("Daemon:", err) } } fmt.Println("Daemon:", name, "has been tagged as banned") botsClosed++ } if Helpers.Replenish(scriptId, groupId, schedule, customer) { botsStarted++ }
-
Realistic got a reaction from BillBurry in DreamBot Guides: Help Needed!
I actually started doing this in a private git repo. I didn't get very far... I would love to convert my open source tutorial island script into a tutorial that includes how to walk, interact with NPCs/ GameObjects/Items/widgets, combat,TaskScripts, ect... I would start by making short tutorials about each concept, then rolling it all up and use the tut island script as a final product.
I have a decent amount of Markdown experience.
-
Realistic reacted to Pandemic in DreamBot Guides: Help Needed!
Hello everyone,
As we push towards making DreamBot easier to use, we've started a new guides section for user and scripter guides. We think it's a good idea to have up to date guides all centralized in one place, instead of making people search the forums and hope the content is still relevant.
You can find the start of the docs here: https://dreambot.org/guides.
What I'd like to know from you guys is what kind of guides or information you'd like to see added here. We don't want to overflow it with too much stuff, but still would like to have all of the essentials covered. Stuff where people can learn best botting practices, troubleshoot script issues without needing to make (yet another) post on the forums, etc.
Interested in Contributing?
We have a private Github repo for the docs, if you'd be interested in contributing please PM me directly with your Github name or email and I can invite you ASAP
There is a ton of great content on our forums already, if you think it'd be fitting please let us know by posting below. These docs are built using Markdown, so if that's something you're familiar with, and would like to help us expand these docs, feel free to let us know which posts you'd like to help convert. If we agree that it'd be a nice addition, you could then convert it and send it to me directly. Once we've done whatever editing is necessary I'll have it added to the docs with you credited as the author / convertor. We may add a forum rank for regular contributors, or offer store credit per page, I'm not really sure yet.
---
Thanks!
The Dream Team
-
Realistic got a reaction from Pandemic in DreamBot Guides: Help Needed!
I actually started doing this in a private git repo. I didn't get very far... I would love to convert my open source tutorial island script into a tutorial that includes how to walk, interact with NPCs/ GameObjects/Items/widgets, combat,TaskScripts, ect... I would start by making short tutorials about each concept, then rolling it all up and use the tut island script as a final product.
I have a decent amount of Markdown experience.
-
Realistic reacted to holic in WindMouse - Custom Mouse Movement Algorithm
Hey all,
Since DB3 officially supports custom mouse algorithms I thought I would port over a classic one: WindMouse.
WindMouse was written by BenLand100 for SCAR some years back (maybe 10 years?) and has been used on so many damn bots throughout the years because it functions really well so it only seemed right to bring it here.
In the source code below, there are two implementations of WindMouse:
Point windMouse(int x, int y) Which comes directly from the SMART github with minor adjustments to work with DB3.
Better in fixed mode.
void windMouse2(Point point) My tweaked version from years back that supports all screen sizes.
I've added a random point between the original and the destination point if the distance between them is large to feel more human but has a 50% chance of happening. By default my implementation is the active algorithm (as it handles all sizes), swap the comments in handleMovement to change to the original.
To use it, simply add the file WindMouse.java to your project and add the following to your onStart method:
Client.getInstance().setMouseMovementAlgorithm(new WindMouse());
All credits go to Benjamin J. Land a.k.a. BenLand100
WindMouse.java:
/** * WindMouse from SMART by Benland100 * Copyright to Benland100, (Benjamin J. Land) * * Prepped for DreamBot 3 **/ import org.dreambot.api.Client; import org.dreambot.api.input.Mouse; import org.dreambot.api.input.mouse.algorithm.MouseMovementAlgorithm; import org.dreambot.api.input.mouse.destination.AbstractMouseDestination; import org.dreambot.api.methods.Calculations; import org.dreambot.api.methods.input.mouse.MouseSettings; import java.awt.*; import static java.lang.Thread.sleep; public class WindMouse implements MouseMovementAlgorithm { private int _mouseSpeed = MouseSettings.getSpeed() > 15 ? MouseSettings.getSpeed() - 10 : 15; private int _mouseSpeedLow = Math.round(_mouseSpeed / 2); private int _mouseGravity = Calculations.random(4, 20); private int _mouseWind = Calculations.random(1, 10); @Override public boolean handleMovement(AbstractMouseDestination abstractMouseDestination) { //Get a suitable point for the mouse's destination Point suitPos = abstractMouseDestination.getSuitablePoint(); // Select which implementation of WindMouse you'd like to use // by uncommenting out the line you want to use below: //windMouse(suitPos.x, suitPos.y); //Original implementation windMouse2(suitPos); //Tweaked implementation return distance(Client.getMousePosition(), suitPos) < 2; } public static void sleep(int min, int max) { try { Thread.sleep(Calculations.random(min,max)); } catch (InterruptedException e) { log(e.getMessage()); } } public static void sleep(int ms) { try { Thread.sleep(ms); } catch (InterruptedException e) { log(e.getMessage()); } } /** * Tweaked implementation of WindMouse * Moves to a mid point on longer moves to seem a little more human-like * Remove the if statement below if you'd rather straighter movement * @param point The destination point */ public void windMouse2(Point point) { Point curPos = Client.getMousePosition(); if (distance(point, curPos) > 250 && Calculations.random(1) == 2) { Point rp = randomPoint(point, curPos); windMouse2(curPos.x, curPos.y, rp.x, rp.y, _mouseGravity, _mouseWind, _mouseSpeed, Calculations.random(5, 25)); sleep(1, 150); } windMouse2(curPos.x, curPos.y, point.x, point.y, _mouseGravity, _mouseWind, _mouseSpeed, Calculations.random(5, 25)); _mouseGravity = Calculations.random(4, 20); _mouseWind = Calculations.random(1, 10); _mouseSpeed = Calculations.random(_mouseSpeedLow, MouseSettings.getSpeed()); } /** * Tweaked implementation of WindMouse by holic * All credit to Benjamin J. Land for the original. (see below) * * @param xs The x start * @param ys The y start * @param xe The x destination * @param ye The y destination * @param gravity Strength pulling the position towards the destination * @param wind Strength pulling the position in random directions * @param targetArea Radius of area around the destination that should * trigger slowing, prevents spiraling */ private void windMouse2(double xs, double ys, double xe, double ye, double gravity, double wind, double speed, double targetArea) { double dist, veloX = 0, veloY = 0, windX = 0, windY = 0; double sqrt2 = Math.sqrt(2); double sqrt3 = Math.sqrt(3); double sqrt5 = Math.sqrt(5); int tDist = (int) distance(xs, ys, xe, ye); long t = System.currentTimeMillis() + 10000; while (!(Math.hypot((xs - xe), (ys - ye)) < 1)) { if (System.currentTimeMillis() > t) break; dist = Math.hypot((xs - xe), (ys - ye)); wind = Math.min(wind, dist); if ((dist < 1)) { dist = 1; } long d = (Math.round((Math.round(((double) (tDist))) * 0.3)) / 7); if ((d > 25)) { d = 25; } if ((d < 5)) { d = 5; } double rCnc = Calculations.random(6); if ((rCnc == 1)) { d = 2; } double maxStep = (Math.min(d, Math.round(dist))) * 1.5; if ((dist >= targetArea)) { windX = (windX / sqrt3) + ((Calculations.random((int) ((Math.round(wind) * 2) + 1)) - wind) / sqrt5); windY = (windY / sqrt3) + ((Calculations.random((int) ((Math.round(wind) * 2) + 1)) - wind) / sqrt5); } else { windX = (windX / sqrt2); windY = (windY / sqrt2); } veloX += windX + gravity * (xe - xs) / dist; veloY += windY + gravity * (ye - ys) / dist; if ((Math.hypot(veloX, veloY) > maxStep)) { maxStep = ((maxStep / 2) < 1) ? 2 : maxStep; double randomDist = (maxStep / 2) + Calculations.random((int) (Math.round(maxStep) / 2)); double veloMag = Math.sqrt(((veloX * veloX) + (veloY * veloY))); veloX = (veloX / veloMag) * randomDist; veloY = (veloY / veloMag) * randomDist; } int lastX = ((int) (Math.round(xs))); int lastY = ((int) (Math.round(ys))); xs += veloX; ys += veloY; if ((lastX != Math.round(xs)) || (lastY != Math.round(ys))) { Mouse.hop(new Point((int) Math.round(xs), (int) Math.round(ys))); } int w = Calculations.random((int) (Math.round(100 / speed))) * 6; if ((w < 5)) { w = 5; } w = (int) Math.round(w * 0.9); sleep(w); } if (((Math.round(xe) != Math.round(xs)) || (Math.round(ye) != Math.round(ys)))) { Mouse.hop(new Point(((int) (Math.round(xe))), ((int) (Math.round(ye))))); } } /** * Internal mouse movement algorithm from SMART. Do not use this without credit to either * Benjamin J. Land or BenLand100. This was originally synchronized to prevent multiple * motions and bannage but functions poorly with DB3. * * BEST USED IN FIXED MODE * * @param xs The x start * @param ys The y start * @param xe The x destination * @param ye The y destination * @param gravity Strength pulling the position towards the destination * @param wind Strength pulling the position in random directions * @param minWait Minimum relative time per step * @param maxWait Maximum relative time per step * @param maxStep Maximum size of a step, prevents out of control motion * @param targetArea Radius of area around the destination that should * trigger slowing, prevents spiraling * @result The actual end point */ private Point windMouseImpl(double xs, double ys, double xe, double ye, double gravity, double wind, double minWait, double maxWait, double maxStep, double targetArea) { final double sqrt3 = Math.sqrt(3); final double sqrt5 = Math.sqrt(5); double dist, veloX = 0, veloY = 0, windX = 0, windY = 0; while ((dist = Math.hypot(xs - xe, ys - ye)) >= 1) { wind = Math.min(wind, dist); if (dist >= targetArea) { windX = windX / sqrt3 + (2D * Math.random() - 1D) * wind / sqrt5; windY = windY / sqrt3 + (2D * Math.random() - 1D) * wind / sqrt5; } else { windX /= sqrt3; windY /= sqrt3; if (maxStep < 3) { maxStep = Math.random() * 3D + 3D; } else { maxStep /= sqrt5; } } veloX += windX + gravity * (xe - xs) / dist; veloY += windY + gravity * (ye - ys) / dist; double veloMag = Math.hypot(veloX, veloY); if (veloMag > maxStep) { double randomDist = maxStep / 2D + Math.random() * maxStep / 2D; veloX = (veloX / veloMag) * randomDist; veloY = (veloY / veloMag) * randomDist; } int lastX = ((int) (Math.round(xs))); int lastY = ((int) (Math.round(ys))); xs += veloX; ys += veloY; if ((lastX != Math.round(xs)) || (lastY != Math.round(ys))) { setMousePosition(new Point((int) Math.round(xs), (int) Math.round(ys))); } double step = Math.hypot(xs - lastX, ys - lastY); sleep((int) Math.round((maxWait - minWait) * (step / maxStep) + minWait)); } return new Point((int) xs, (int) ys); } /** * Moves the mouse from the current position to the specified position. * Approximates human movement in a way where smoothness and accuracy are * relative to speed, as it should be. * * @param x The x destination * @param y The y destination * @result The actual end point */ public Point windMouse(int x, int y) { Point c = Client.getMousePosition(); double speed = (Math.random() * 15D + 15D) / 10D; return windMouseImpl(c.x, c.y, x, y, 9D, 3D, 5D / speed, 10D / speed, 10D * speed, 8D * speed); } private void setMousePosition(Point p) { Mouse.hop(p.x, p.y); } private static double distance(double x1, double y1, double x2, double y2) { return Math.sqrt((Math.pow((Math.round(x2) - Math.round(x1)), 2) + Math.pow((Math.round(y2) - Math.round(y1)), 2))); } public double distance(Point p1, Point p2) { return Math.sqrt((p2.y - p1.y) * (p2.y - p1.y) + (p2.x - p1.x) * (p2.x - p1.x)); } public static float randomPointBetween(float corner1, float corner2) { if (corner1 == corner2) { return corner1; } float delta = corner2 - corner1; float offset = Calculations.getRandom().nextFloat() * delta; return corner1 + offset; } public Point randomPoint(Point p1, Point p2) { int randomX = (int) randomPointBetween(p1.x, p2.x); int randomY = (int) randomPointBetween(p1.y, p2.y); return new Point(randomX, randomY); } }
Happy botting!