Jump to content
Frequently Asked Questions
  • Are you not able to open the client? Try following our getting started guide
  • Still not working? Try downloading and running JarFix
  • Help! My bot doesn't do anything! Enable fresh start in client settings and restart the client
  • How to purchase with PayPal/OSRS/Crypto gold? You can purchase vouchers from other users
  • Try asking for help in the chatbox
  • Bronze Bar Smelter (Deepslayer)


    Deep Slayer
     Share

    Recommended Posts

    This is my first script upload to the community. Any and all feedback are welcome as I don't have any background in scripting or programming! I also hope this can help someone else that is just getting started too!

    All you have to do is make sure that you have more than 14 Copper ore and  14 Tin ore in the bank and you're good to go.

    Jar file for download https://github.com/deepslayer/Dreambot/blob/main/BronzeBarSmelter.jar

    Source code below:

     

    import org.dreambot.api.input.Mouse;
    import org.dreambot.api.input.event.impl.mouse.impl.click.ClickMode;
    import org.dreambot.api.input.mouse.destination.impl.EntityDestination;
    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.interactive.GameObjects;
    import org.dreambot.api.methods.interactive.Players;
    import org.dreambot.api.methods.map.Area;
    import org.dreambot.api.methods.tabs.Tab;
    import org.dreambot.api.methods.tabs.Tabs;
    import org.dreambot.api.methods.walking.impl.Walking;
    import org.dreambot.api.methods.widget.Widgets;
    import org.dreambot.api.script.AbstractScript;
    import org.dreambot.api.script.Category;
    import org.dreambot.api.script.ScriptManifest;
    import org.dreambot.api.wrappers.interactive.GameObject;
    import org.dreambot.api.wrappers.interactive.Player;
    import org.dreambot.api.wrappers.widgets.WidgetChild;
    
    import java.util.List;
    
    @ScriptManifest(name = "Bronze Bar Smelter", description = "Smelts Bronze Bars at Edgeville", author = "Deepslayer",
            version = 1.0, category = Category.SMITHING, image = "")
    
    
    
    
    public class BronzeBarSmelter extends AbstractScript {
    
        //Areas
        Area EDGE_BANK = new Area(3095, 3496, 3098, 3494, 0);
        Area FURNACE = new Area(3108, 3500, 3109, 3498, 0);
    
        @Override
        public int onLoop() {
    
    
            WalkToBank();
    
            grabBronzeBarsToSmelt();
    
            WalkToFurnace();
    
            InteractWithFurnace();
    
            return Calculations.random(450,850);
    
        }
    
        //---------------------METHOD DEFINITIONS.......................//
    
        public void grabBronzeBarsToSmelt() {
    
            while (!Bank.isOpen()) {
                Bank.openClosest();
                sleep(2000, 3000);
            }
    
    
            if (Bank.isOpen()) {
                AFK();
    
                Bank.depositAllItems();
            }
    
            //checking if there are enough ores in the bank, if not, then stopping the script
            if (Bank.count("Copper ore") < 14 || Bank.count("Tin ore") < 14) {
                log("not enough ore");
                stop();
            }
    
    
            while (!Bank.isOpen()) {
                Bank.openClosest();
                Mouse.move();
                sleep(1500,3000);
            }
    
            if(Bank.isOpen()) {
                Bank.withdraw("Tin ore", 14);
                Mouse.move();
                sleep(100, 500);
                Bank.withdraw("Copper ore", 14);
                Mouse.move();
                sleep(300, 1000);
            }
    
            while (Bank.isOpen()) {
    
                Bank.close();
                Mouse.move();
                sleep(100, 500);
    
            }
    
    
        }
    
        public void WalkToBank() {
            log("While im not in bank, walking to bank...");
    
    
            while (!EDGE_BANK.contains(getLocalPlayer())) {
                Walking.walk(EDGE_BANK.getRandomTile());
                sleep(1000, 1500);
                sleepUntil(() -> Walking.getDestinationDistance() < 4, 5000);
    
    
    
    
            }
        }
    
        public void WalkToFurnace() {
            log("while im not at furnace.. walking to furnace...");
    
            while (!FURNACE.contains(getLocalPlayer())) {
                Walking.walk(FURNACE.getRandomTile());
                sleep(1000, 1500);
                sleepUntil(() -> Walking.getDestinationDistance() < 4, 5000);
            }
    
        }
    
        public void InteractWithFurnace() {
    
    
            while (Inventory.contains("Copper ore") && Inventory.contains("Tin ore")) { //while loop is needed incase player levels up while smelting
    
    
                GameObject Furnace = GameObjects.closest("Furnace");
                if (Furnace != null && Furnace.hasAction("Smelt")) {
                    Furnace.interact("Smelt");
                    Mouse.move();
                }
                sleep(2000, 3000);
    
    
                WidgetChild ClickBronzeBar = Widgets.getWidget(270).getChild(14);//gets the bronze bar widget
                sleep(500, 1500);
                if (ClickBronzeBar != null) {
                    log("Clicking Bronze bar to smelt all");
                    ClickBronzeBar.interact();
    
                }
    
                AntiPattern();
    
                Mouse.moveMouseOutsideScreen();
                log("Moving mouse off screen while smelting");
    
                sleepUntil(() -> Inventory.count("Bronze bar") == 14 || Dialogues.canContinue(), 60000);
                while (Dialogues.canContinue()) {
                    Dialogues.spaceToContinue();
                    sleep(2000, 3000);
                }//this is called to get past the level up message and begin smelting bronze bars again
    
    
            }
    
        }
    
        private Tab RandomTab() {
            //this gets method called to select a random tab in the AntiPattern method.
    
            int randNumber = Calculations.random(1, 7);
    
            if (randNumber == 1) {
                return Tab.COMBAT;
            }
            if (randNumber == 2) {
                return Tab.SKILLS;
            }
            if (randNumber == 3) {
                return Tab.QUEST;
            }
            if (randNumber == 4) {
                return Tab.EQUIPMENT;
            }
            if (randNumber == 5) {
                return Tab.PRAYER;
            }
            if (randNumber == 6) {
                return Tab.MAGIC;
            }
            else return null;
    
        }
    
        private void AntiPattern(){
            int random = Calculations.random(1,15);
    
            if(random == 5){
    
                log("Right clicking random player if there are any nearby");
    
                List<Player> allNearbyPlayers = Players.all(); // gets all nearby players and stores it into a list
                allNearbyPlayers.remove(getLocalPlayer()); //removes local player from list
    
                if (allNearbyPlayers.size() > 0) // checks if the list contains more than 0 players
                {
                    Player randomPlayer = allNearbyPlayers.get(Calculations.random(allNearbyPlayers.size())); // get one name out of the list at random and put it into another variable called randomPlayer
                    EntityDestination playerDestination = new EntityDestination(randomPlayer); //creates a destination in game for randomPlayer
                    Mouse.move(playerDestination); //moves mouse over the randomplayer
                    Mouse.click(ClickMode.RIGHT_CLICK); //right clicks to open menu
                    sleep(3000, 6000);
    
                }
    
            }
            if(random == 12){
                log("Going AFK for 60-90 seconds");
                Mouse.moveMouseOutsideScreen();
                sleep(Calculations.random(60000,90000)); // afk for 60-90 seconds
    
    
            }
            if(random == 9){
    
                log("Opening random tab and then back to inventory tab a random amount of times between 1 and 5 times");
                int randLoop = Calculations.random(0,5);
                int x = 0;
    
                while(x <= randLoop) {
                    x++;
    
    
                    Tabs.openWithMouse(RandomTab());
                    sleep(100, 300);
                    Tabs.openWithMouse(Tab.INVENTORY);
                    sleep(100, 300);
                }
    
            }
    
        }
    
        private void AFK(){
    
            int random = Calculations.random(1,20);
    
            if(random == 10) {
                log("Going AFK for 60-90 seconds");
                Mouse.moveMouseOutsideScreen();
                sleep(Calculations.random(60000, 90000)); // afk for 60-90 seconds
            }
        }
    
    
    }
    
    Edited by deepslayer
    Link to comment
    Share on other sites

    Nice contribution! Keep up the good work :)

    A few tips:

    • Generally functions and variables should be standard camel case (afk() instead of AFK(), antiPattern() instead of AntiPattern(), etc.), they could also be named something a bit clearer to try and describe what they do (performAFKActions() tells me a bit more at a glance than just AFK())
    • When you have many (usually more than two) if/else if about a value like you have in RandomTab and AntiPattern for example, you should use a switch case as it's a bit easier to read: https://docs.oracle.com/javase/tutorial/java/nutsandbolts/switch.html
    • You use a few while loops in the script, and generally that's a bad idea for scripts in case of a network issue that logs you out, or the character dies, or something else unexpected happens. It's better to try and limit each onLoop call to as few actions as necessary and allowing the client to do it's background work in between.

    Hope that helps :) 

    Link to comment
    Share on other sites

    Thanks for the feedback Pandemic,

    In regards to your third point about looping through onLoop as often to let the other pieces of code work outside of onLoop. 

    How would I go about achieving things like walking as I often code them to run through their own loop? will I have to find ways to make the rest of the code return false until a certain condition? is there a general technique that you apply or is there a different structure I should be going about my programming?

    Thanks mate

    Link to comment
    Share on other sites

    30 minutes ago, deepslayer said:

    How would I go about achieving things like walking as I often code them to run through their own loop? will I have to find ways to make the rest of the code return false until a certain condition? is there a general technique that you apply or is there a different structure I should be going about my programming?

    Well right now your script's onLoop is basically the full "loop" of your script's cycle, which is how might program other things, but with scripts in particular there's a lot of things that can happen outside of your script's control (like I said above with network issues, random event handler starting, breaks, etc.).

    So in your onLoop instead of trying to do everything in order, it would ideally be robust enough to start at any possible starting state (bank open and needing more supplies, have bars and ready to smith, etc.) and perform some action. So in your onLoop you'd need various state checks (if/else if) to see what action you should perform in that one onLoop call.

    For example:

    if (Inventory.contains("Bronze bars")) {
      if (Players.localPlayer().isAnimating() || Players.localPlayer().isMoving()) {
        // Probably smithing, let's just wait for another loop
        return Calculations.random(1000, 2000);
      }
      // If we've reached here, that means our player probably isn't smithing but should be.
      // If we are smithing, it will return out of the onLoop above, so it won't run anything after like this:
      smeltStuff();
    } else {
      // We don't have bronze bars, let's check if the bank is open yet
      if (Bank.isOpen()) {
        Bank.withdrawAll("Bronze bars");
      } else {
        Bank.openClosest();
      }
    }
    
    return Calculations.random(600, 1200);

    That's a super rough idea, and I'm sure it's not actually right for this task, but you should be able to see what I was going for. Basically you want each run of onLoop to be able to progress no matter where your player is starting at. It helps in the robustness of the overall script.

    Let me know if that wasn't clear enough, or if you have any questions about it :) 

    Link to comment
    Share on other sites

    It makes sense, I think I have to think about what current state the player is in, regards to the whole task. which can be tricky because certain states can be similar and will have to be distinct from one another

    Link to comment
    Share on other sites

    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 account

    Sign in

    Already have an account? Sign in here.

    Sign In Now
     Share

    ×
    ×
    • Create New...

    Important Information

    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.