tot67 8 Posted July 8, 2024 Hello guys! I am here to share one of my scripts with the community. I felt good while doing this work because I had to learn a lot about how the DreamBot works. Will post the source code so everyone can see, discuss, use it as it will. DreamBot has so many cool things and it's working so smoothly that I feel the need to share and help anyone. This script is not the best you will see out there, but I am running it for 100h now without major issues (with DreamBot breaks). I will keep running it in my local and keep doing improvements, but probably won't keep updating here, because the idea is not only to simply share a working bot, it's to encourage other people to help/get info/discuss/share scripts/etc. Some logics like my antiban strategies were not added here because it doesn't make sense to everyone have the same antiban logics, right? 😅 import org.dreambot.api.input.Keyboard; import org.dreambot.api.input.event.impl.keyboard.awt.Key; import org.dreambot.api.methods.Calculations; import org.dreambot.api.methods.container.impl.Inventory; import org.dreambot.api.methods.container.impl.bank.Bank; import org.dreambot.api.methods.dialogues.Dialogues; import org.dreambot.api.methods.input.Camera; import org.dreambot.api.methods.interactive.GameObjects; import org.dreambot.api.methods.interactive.Players; import org.dreambot.api.methods.map.Tile; import org.dreambot.api.methods.walking.impl.Walking; import org.dreambot.api.methods.widget.Widgets; import org.dreambot.api.methods.world.Worlds; import org.dreambot.api.methods.worldhopper.WorldHopper; import org.dreambot.api.script.AbstractScript; import org.dreambot.api.script.Category; import org.dreambot.api.script.ScriptManifest; import org.dreambot.api.utilities.Logger; import org.dreambot.api.utilities.Sleep; import org.dreambot.api.wrappers.interactive.GameObject; import org.dreambot.api.wrappers.items.Item; @ScriptManifest(name = "Blast Furnace Steel Bars", description = "Uses Blast Furnace for making steel bars", author = "Tot67", version = 1.03, category = Category.SMITHING) public class Main extends AbstractScript { /** * Instructions: start this bot inside the Blast Furnace. It will NOT move to the Blast Furnace by itself and it will NOT buy any of the needed items * Make sure you have the Ice Gloves already equipped. * Requirements: * - Coal * - Iron ore * - Ice gloves * - Coal bag * - Smithing lvl 30 * - Mining lvl 50 for getting the Ice Gloves * - At least 100000 coins * <p> * Known issues: * - In the first run there is a chance it will create some iron bars instead of steel bars * - It has happened to me that it lost completely its mind after returning from a break. Still couldn't reproduce again or debug :( * <p> * For more information: https://oldschool.runescape.wiki/w/Money_making_guide/Smelting_steel_bars_at_Blast_Furnace */ private Tile DISPENSER_TILE = new Tile(1940, 4962); private final int CONVEYOR_BELT_ID = 9100; private final String IRON_ORE = "Iron ore"; private final String COAL = "Coal"; private final String COINS = "Coins"; private boolean first_run = true; private enum State { CHECK_WORLD, ENABLE_RUN, CHECK_COFFER, DEPOSIT_COAL_FIRST_RUN, DEPOSIT_ALL_AND_RETRIEVE_BARS, DO_IRON_ORE_AND_COAL_TRIP, RETRIEVE_BARS, DEPOSIT_BARS, DEBUG } private State state = State.CHECK_WORLD; @Override public void onStart() { Logger.log("Starting Blast Furnace Steel Bars script..."); } @Override public int onLoop() { switch (state) { case CHECK_WORLD: Logger.log("State: CHECK_WORLD"); checkWorld(); state = State.ENABLE_RUN; break; case ENABLE_RUN: Logger.log("State: ENABLE_RUN"); enableRun(); state = State.CHECK_COFFER; break; case CHECK_COFFER: Logger.log("State: CHECK_COFFER"); checkCoffer(); state = State.DEPOSIT_COAL_FIRST_RUN; break; case DEPOSIT_COAL_FIRST_RUN: Logger.log("State: DEPOSIT_COAL_FIRST_RUN"); depositCoalFirstRun(); state = State.DO_IRON_ORE_AND_COAL_TRIP; break; case DO_IRON_ORE_AND_COAL_TRIP: Logger.log("State: DO_IRON_ORE_AND_COAL_TRIP"); if (doIronOreAndCoalTrip()) { state = State.RETRIEVE_BARS; } else { state = State.DEPOSIT_ALL_AND_RETRIEVE_BARS; } checkCamera(); break; case RETRIEVE_BARS: Logger.log("State: RETRIEVE_BARS"); retrieveBars(); state = State.DEPOSIT_BARS; break; case DEPOSIT_BARS: Logger.log("State: DEPOSIT_BARS"); depositBars(); state = State.CHECK_WORLD; break; case DEPOSIT_ALL_AND_RETRIEVE_BARS: Logger.log("State: DEPOSIT_ALL_AND_RETRIEVE_BARS"); openBank(); Bank.depositAll(item -> !item.getName().contains("oal bag")); retrieveBars(); state = State.CHECK_WORLD; break; case DEBUG: Logger.log("State: DEBUG"); return 2000; } return Calculations.random(100, 200); } @Override public void onExit() { Logger.log("Stopping Blast Furnace Steel Bars script..."); } private void checkWorld() { if (Worlds.getCurrentWorld() != 386 && Worlds.getCurrentWorld() != 357 && Worlds.getCurrentWorld() != 356) { WorldHopper.hopWorld(386); } } private void enableRun() { if (!Walking.isRunEnabled()) { Logger.log("Enabling run."); Walking.toggleRun(); } } private void checkCoffer() { // Coffer widget if (Widgets.getWidget(474) != null && Widgets.getWidget(474).getChild(2).getChild(3).getItemStack() < 5000) { manageCoffer(); } } private void openBank() { for (int i = 0; i < 3; i++) { if (Bank.isOpen()) break; GameObject bankChest = GameObjects.closest("Bank chest"); if (bankChest == null || !bankChest.exists()) { Logger.log("Bank chest not found"); continue; } bankChest.interact("Use"); Sleep.sleepUntil(() -> Bank.isOpen(), 5000); } } private void manageCoffer() { Logger.log("Managing coffer."); openBank(); if (Bank.isOpen()) { Sleep.sleep(300); Logger.log("Depositing all items except coal bag."); Bank.depositAll(item -> !item.getName().contains("oal bag")); Sleep.sleep(1000); if (Bank.get(COINS).getAmount() < 100000) { Logger.error("Not enough money to put in coffer. Stopping bot"); stop(); return; } Logger.log("Withdrawing 100,000 coins."); Bank.withdraw(COINS, 100000); Sleep.sleep(1000); Bank.close(); } Logger.log("Checking and managing coffer."); GameObject coffer = GameObjects.closest("Coffer"); if (coffer != null && coffer.exists()) { Logger.log("Interacting with coffer."); coffer.interact("Use"); Sleep.sleepUntil(() -> Dialogues.inDialogue(), 4000); if (Dialogues.inDialogue()) { Sleep.sleep(1000); depositCofferMoney(); } Sleep.sleep(500); } } private void depositCofferMoney() { Logger.log("Depositing money in the coffer."); GameObject coffer = GameObjects.closest("Coffer"); if (coffer != null && coffer.exists()) { coffer.interact("Use"); Sleep.sleep(1200); Dialogues.chooseOption("Deposit coins."); Sleep.sleep(1200); Keyboard.type("100000"); Sleep.sleep(1200); Keyboard.holdKey(Key.ENTER, () -> !Dialogues.inDialogue(), 100); if (Dialogues.inDialogue()) { Dialogues.clickContinue(); } } } private void depositCoalFirstRun() { if (!first_run) return; Logger.log("Depositing coal for the first run."); openBank(); Bank.depositAll(item -> !item.getName().contains("oal bag")); Sleep.sleep(500); if (!Bank.contains("Coal") || !Bank.contains("Iron ore")) { Logger.error("No coal or iron ores available. Stopping the bot"); stop(); } Logger.log("Withdrawing all coal."); Bank.withdrawAll("Coal"); Sleep.sleep(500); Logger.log("Filling coal bag."); Inventory.get(item -> item.getName().contains("oal bag")).interact("Fill"); Sleep.sleep(500); Bank.close(); Sleep.sleep(100); GameObject conveyorBelt = GameObjects.closest(CONVEYOR_BELT_ID); if (conveyorBelt != null && conveyorBelt.exists()) { Logger.log("Interacting with conveyor belt to deposit coal."); conveyorBelt.interact("Put-ore-on"); Sleep.sleepUntil(() -> !Inventory.contains(COAL), 8000); if (Dialogues.inDialogue()) { if (Widgets.getWidget(229) != null && Widgets.getWidget(229).getChild(1).getText().contains("You should collect your bars before making any more.")) { return; } else if (Widgets.getWidget(193) != null && Widgets.getWidget(193).getChild(2).getText().contains("You must put money in the coffer to pay the workers.")) { manageCoffer(); } } Inventory.get(item -> item.getName().contains("oal bag")).interact("Empty"); conveyorBelt.interact("Put-ore-on"); Sleep.sleep(300); if (Inventory.contains(COAL)) { Inventory.get(item -> item.getName().contains("oal bag")).interact("Fill"); Sleep.sleep(300); } } first_run = false; } private boolean doIronOreAndCoalTrip() { Logger.log("Doing an iron ore and coal trip."); openBank(); if (Bank.isOpen()) { Logger.log("Depositing all items except coal bag."); Bank.depositAll(item -> !item.getName().contains("oal bag")); if (Walking.getRunEnergy() < 70 && !Walking.isStaminaActive() && Bank.contains(item -> item.getName().contains("Stamina potion"))) { Logger.log("Drinking stamina potion."); Bank.withdraw(item -> item.getName().contains("Stamina potion")); Sleep.sleepUntil(() -> Inventory.get(item -> item.getName().contains("Stamina potion")) != null, 5000); Item stamPot = Inventory.get(item -> item.getName().contains("Stamina potion")); stamPot.interact("Drink"); Sleep.sleep(500); Bank.depositAll(item -> !item.getName().contains("oal bag")); } if (!Bank.contains("Coal")) stop(); if (!Bank.contains("Iron ore")) stop(); Sleep.sleep(200); Logger.log("Withdrawing iron ore and coal from bank."); Bank.withdrawAll(IRON_ORE); Sleep.sleep(400); Inventory.get(item -> item.getName().contains("oal bag")).interact("Fill"); Sleep.sleep(400); Bank.close(); } Logger.log("Depositing ores on the conveyor belt."); GameObject conveyorBelt = GameObjects.closest(CONVEYOR_BELT_ID); if (conveyorBelt != null && conveyorBelt.exists()) { Logger.log("Interacting with conveyor belt to deposit ores."); conveyorBelt.interact("Put-ore-on"); Sleep.sleepUntil(() -> !Inventory.contains(IRON_ORE) && !Inventory.contains(COAL), 12000); if (Dialogues.inDialogue()) { if (Widgets.getWidget(229) != null && Widgets.getWidget(229).getChild(1).getText().contains("You should collect your bars before making any more.")) { return false; } else if (Widgets.getWidget(193) != null && Widgets.getWidget(193).getChild(2).getText().contains("You must put money in the coffer to pay the workers.")) { manageCoffer(); } } Logger.log("Inventory.contains(IRON_ORE): " + Inventory.contains(IRON_ORE)); if (Inventory.contains(IRON_ORE)) { return false; } Sleep.sleep(300); Inventory.get(item -> item.getName().contains("oal bag")).interact("Empty"); Sleep.sleep(100); conveyorBelt.interact("Put-ore-on"); Sleep.sleep(300); if (Inventory.contains(COAL)) { Inventory.get(item -> item.getName().contains("oal bag")).interact("Fill"); Sleep.sleep(300); } } return true; } private void retrieveBars() { Logger.log("Retrieving bars from the dispenser."); Sleep.sleep(1000); while (DISPENSER_TILE.distance() != 0) { if (!Players.getLocal().isMoving()) { Logger.log("Walking to dispenser tile."); Walking.walkExact(DISPENSER_TILE); } Sleep.sleep(400); } GameObject barDispenser = GameObjects.closest("Bar dispenser"); Sleep.sleep(600); barDispenser.interact("Take"); Sleep.sleepUntil(() -> Dialogues.inDialogue(), 5000); Keyboard.holdKey(Key.SPACE, () -> !Dialogues.inDialogue(), 60); Sleep.sleep(300); } private void depositBars() { Logger.log("Depositing bars."); openBank(); if (Bank.isOpen()) { Sleep.sleep(500); Logger.log("Depositing all bars except coal bag."); Bank.depositAll(item -> !item.getName().contains("oal bag")); } } private void checkCamera() { int currentPitch = Camera.getPitch(); int currentYaw = Camera.getYaw(); if (currentYaw < 1600 || currentYaw > 1630 || currentPitch < 380 || currentPitch > 386) { Camera.setZoom(Camera.getMaxZoom()); Camera.mouseRotateTo(1618, 383); } } } Thank you! YUNGTHUGFATGP, Idontplayrob and Luxe 3
Hashtag 8931 Posted July 10, 2024 Thanks for contributing. However, I would like to point a couple of things out: Do not use while loops in a script like that. The script is already looping and you really shouldn't make another loop in it that is possibly never going to break. Refrain from executing multiple actions per loop. Again, the script is looping and you will end up with a lot more reliable script if you only executed one action per loop with proper game state validation. You're starting a sleep regardless of what API methods like interact return. Those methods have a boolean return value type and you should check if an interaction was successful in order to begin a sleep. Otherwise the script will end up being slow because it's sleeping when it's not supposed to. tot67 1
tot67 8 Author Posted July 10, 2024 Thank you very much for these ideas, @Hashtag! I appreciate it a lot. That is exactly why I wanted to post here. I can see a lot of improvements based on your comments and having used it a bit more. I will surely keep improving and I hope to bring new posts/scripts here with better logics Hashtag 1
tot67 8 Author Posted July 11, 2024 46 minutes ago, iqballashari9 said: how to use thes script To use the script you will need to build it with your own Java IDE. Take a look at this page I will link here, it explains how to start creating scripts. In this case you will only need to configure a project and build it, because the code is "done". https://dreambot.org/guides/scripter-guide/starting/
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now