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
  • My First Script!


    KhalDrogonerr

    Recommended Posts

    Hi everyone, today I wanted to try to write a mining script....but everything went well until I had to deposit...the bot approaches and makes many attempts before managing to deposit...how can I avoid it this and have it deposited on the first try?I tried to get some pieces from gpt chat for the solution but nothing has changed....I think the problem is in BANKING and USE_BANK

    import org.dreambot.api.methods.container.impl.bank.Bank;
    import org.dreambot.api.methods.container.impl.Inventory;
    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.walking.impl.Walking;
    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.methods.map.Tile;
    import org.dreambot.api.utilities.Sleep;
    import org.dreambot.api.methods.input.Camera;
    @ScriptManifest(author = "KhalDrogonerr", name = "Iron", version = 1.0, description = "Simple Iron Miner", category = Category.MINING)
    
    public class Main extends AbstractScript {
    
    
    
        State state;
        Area bankArea = new Area(
                new Tile(3012, 3359, 0), new Tile(3012, 3353, 0),
                new Tile(3011, 3356, 0), new Tile(3009, 3353, 0),
                new Tile(3012, 3356, 0), new Tile(3016, 3353, 0)
        );
    
        Area ironOre = new Area(2977, 3231, 2967, 3243);
    
        Area muleZone= new Area(3175, 3501, 3154, 3477);
        public enum State {
    
            WALKING_TO_BANK,USE_BANK,BANKING,TAKE_PICKAXE,FINDING_ORE,MINING_ORE};
    
    
        public void onStart() {
            log("Welcome to Simple Mining Script.");
            log("If you experience any issues while running this script please report them to me on the forums.");
            log("Enjoy the script!.");}
    
    
    
    
            @Override
            public int onLoop() {
                switch (getState()) {
                    case WALKING_TO_BANK:
                        Tile destination = bankArea.getRandomTile();
                        if (!Players.getLocal().isMoving() && !Players.getLocal().getTile().equals(destination)) {
                            Walking.walk(destination.getRandomized());
                        }
                        break;
    
                    case USE_BANK:
                        if (!Bank.isOpen() || !Players.getLocal().isMoving()) {
                            GameObject bankBooth = GameObjects.closest("Bank booth");
                            if (bankBooth != null) {
                                if (!bankBooth.isOnScreen()) {
                                    Walking.walkOnScreen(bankBooth.getTile());
                                    Camera.rotateToEntity(bankBooth);
                                } else {
                                    bankBooth.interact("Bank");
                                    Sleep.sleepUntil(() -> Bank.isOpen(), 6000);
                                    
                                    Sleep.sleep(1000, 2000);
                                    
                                    if (bankArea.contains(Players.getLocal().getTile())) {
                                        
                                        break;
                                    }
                                }
                            }
                        }
                        break;
    
    
                    case BANKING:
    
                        if (!Bank.isOpen()) {
                            Bank.open();
                            Sleep.sleepUntil(Bank::isOpen, 6000);
                        } else {
                            if (!Inventory.isEmpty()) {
                                Bank.depositAll("Iron ore");
                                
                                Sleep.sleepUntil(() -> Inventory.isEmpty(), 6000);
                            } else {
                                Bank.close();
                                Sleep.sleepUntil(() -> !Bank.isOpen(), 6000);
                            }
                        }
                        break;
    
    
                    case TAKE_PICKAXE:
                        if (!Inventory.contains("Bronze pickaxe")) {
                            if (Bank.open()) {
                                if (Bank.contains("Bronze pickaxe")) {
                                    Bank.withdraw("Bronze pickaxe", 1);
                                    Sleep.sleepUntil(() -> Inventory.contains("Bronze pickaxe"), 6000);
                                } else {
                                    log("Bronze pickaxe not found in bank!");
                                }
                                Bank.close();
                            }
                        }
                        break;
    
                    case FINDING_ORE:
                        destination = ironOre.getRandomTile();
                        if (!Players.getLocal().isMoving() && !Players.getLocal().getTile().equals(destination)) {
                            Walking.walk(destination.getRandomized());
                        }
                        break;
    
                    case MINING_ORE:
                        if (!Players.getLocal().isAnimating() && !Players.getLocal().isMoving()) {
                            GameObject ironRocks = GameObjects.closest(t -> t.getName().equalsIgnoreCase("iron rocks") && ironOre.contains(t.getTile()));
                            if (ironRocks != null && ironRocks.interact("Mine")) {
                                Sleep.sleepUntil(() -> Players.getLocal().isAnimating(), 4000);
                            }
                        }
                        break;
                }
                        return 1000;
    
    
            }
        private State getState() {
            if (Inventory.isFull() && !bankArea.contains(Players.getLocal().getTile())) {
                return State.WALKING_TO_BANK;
            } else if (Inventory.isFull() && bankArea.contains(Players.getLocal().getTile()) && !Bank.isOpen()) {
                return State.USE_BANK;
            } else if (Bank.isOpen() && Inventory.isFull()) {
                return State.BANKING;
            } else if (!Inventory.contains("Bronze pickaxe")) {
                return State.TAKE_PICKAXE;
            } else if (!Inventory.isFull() && !ironOre.contains(Players.getLocal().getTile())) {
                return State.FINDING_ORE;
            } else if (!Inventory.isFull() && ironOre.contains(Players.getLocal().getTile())) {
                return State.MINING_ORE;
            }
            return state;
        }
                }
    
    Link to comment
    Share on other sites

    if(!Bank.isOpen() && Inventory.isFull()){
    
        if(Walking.shouldWalk()){
            Bank.open();
        }
        return;
    }
    
    just do this if you want to open the closest bank from anywhere in the game. this will combine your WALKING_TO_BANK and USE_BANK case into one
    Edited by Deep Slayer
    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
    ×
    ×
    • 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.