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
Features:
Begs for items anywhere in the world, preferably near a bank.
Types a random begging phrase and appreciation phrase from the list (appreciation phrases are optional).
Does a random begging emote and appreciation emote from the list (emotes are optional).
You can choose how often the bot should beg for items.
Banks all items after each successful trade.
Declines the trade if the trading window has been open for too long.
Runs back to the initial location if someone is trying to lure the bot.
You can save the settings to a text file and load them quickly.
Displays the total value of received items and profit per hour.
Mule support: when the mule (you) trade the bot, the bot will retrieve the received items from the bank and give them to you (one inventory at a time).
Supports QuickStart.
Requirements:
None.
Instructions:
Use a low-level account to increase the chances of receiving free items.
Use noob-looking equipment to increase the chances of receiving free items.
Gallery:
Proggies:
Feedback:
QuickStart:
Type how long to wait between actions inside quotation marks, for example, 15 to 20 seconds would be "15;20".
Type the begging phrases separated by the ; sign inside quotation marks.
Type the appreciation phrases separated by the ; sign inside quotation marks.
Type the begging emotes separated by the ; sign inside quotation marks.
Type the appreciation emotes separated by the ; sign inside quotation marks.
Type the name of the mule inside quotation marks.
Example: -params "15;20" "Dancing for money!;Dancing for money" "Thank you;Tysm;Ty;Cheers" "Dance" "Bow;Clap;Blow Kiss" null
Example: -params "12;16" "Accepting any unwanted items" "Appreciate it;Thanks man;Thx;Thanks!" null null "Zezima"
Click here to leave a review for the script
Welcome!
This script can do the blast mine mini game and the requirements for it.
Join the Dreamy Scripts Discord and get notified on updates/new releases!
Features:
Account building
Restocking
Task system
Automatically pickaxe upgrade (If pickaxe is not in the bank it will purchase it from the G.E)
GE support
Dragon pickaxe special attack
Pulling rewards
Custom food
Stop settings after X mining level
Anti-crash
Multiple walls
Account builder features:
Train mining to X level.
Automatically detects best ore for best experience.
Instructions:
To use the script you need atleast 20 HP.
Please have the following items in the bank or enable restocking
Dynamite
Tinderbox
Chisel
Food (You do get hit so you need food)
Optional: Stamina potion(1)
Tip:
If you have VIP enable "Menu manipulation" and "No click walk". You can find those in the client settings under the Injections tab.
We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.