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
  • HELP!!!!


    KhalDrogonerr

    Recommended Posts

    hi, I need help, I've been going crazy for hours, I used AI and everything that could help me but I can't figure it out.....I made this simple script to mine and I wanted to implement delivery to the mule with the socket .....the problem that does not change state after 5 minutes does not activate the DELIVER _TO_GE state I don't understand why!

    import org.dreambot.api.methods.container.impl.Inventory;
    import org.dreambot.api.methods.container.impl.bank.Bank;
    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.utilities.Sleep;
    import org.dreambot.api.methods.map.Tile;
    import java.io.*;
    import java.net.Socket;
    import java.io.OutputStream;
    import java.io.Serializable;
    import org.dreambot.api.methods.container.impl.bank.BankMode;
    import org.dreambot.api.methods.trade.Trade;
    import org.dreambot.api.wrappers.interactive.Player;
    import java.net.InetAddress;
    import java.net.UnknownHostException;
    import java.util.List;
    import java.util.stream.Collectors;
    @ScriptManifest(author = "KhalDrogonerr", name = "Iron", version = 1.0, description = "Simple Iron Miner", category = Category.MINING)
    public class Worker extends AbstractScript {
        private static final String MULE_IP = "localhost";
        private static final int MULE_PORT =  55555;
        private long lastDeliveryTime=0;
    
        public static class DeliveryData implements Serializable {
            private int ironOreCount;
            private String playerName;
            private String muleName;
    
            public DeliveryData(int ironOreCount, String playerName, String muleName) {
                this.ironOreCount = ironOreCount;
                this.playerName = playerName;
                this.muleName = muleName;
            }
    
            public int getIronOreCount() {
                return ironOreCount;
            }
    
            public String getPlayerName() {
                return playerName;
            }
    
            public String getMuleName() {
                return muleName;
            }
        }
        State state;
    
        Area bankArea = new Area(3009, 3355, 3018, 3354);
        Area ironOre = new Area(2977, 3231, 2967, 3243);
        Area GE = new Area(3155, 3499, 3174, 3480);
    
        public enum State {
            WALKING_TO_BANK, USE_BANK, BANKING, TAKE_PICKAXE, FINDING_ORE, MINING_ORE, DELIVER_TO_GE, DELIVER_TO_MULE
        }
    
        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:
                    if (bankArea.distance(Players.getLocal().getTile()) > 1)
                        Walking.walk(bankArea.getCenter().getRandomized());
                    break;
    
                case USE_BANK:
                    if (!Bank.isOpen() || !Players.getLocal().isMoving()) {
                        GameObject bankBooth = GameObjects.closest("Bank booth");
                        bankBooth.interact("Bank");
                        Sleep.sleepUntil(Bank::isOpen, 1000);
                        return 1000;
                    }
                    break;
    
                case BANKING:
                    if (Bank.isOpen()) {
                        if (Inventory.isFull()) {
                            Sleep.sleep(2000, 5000);
                            Bank.depositAllExcept(item -> item.getName().equals("Bronze pickaxe"));
                            if (!Inventory.contains("Iron ore")) {
                                Bank.close();
                            }
                        }
                    }
                    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:
                    if (ironOre.distance(Players.getLocal().getTile()) > 1)
                        Walking.walk(ironOre.getCenter().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;
    
                case DELIVER_TO_GE:
                    log("Sto entrando nello stato DELIVER_TO_GE");
                    // Verifica se il bot è già arrivato al Grand Exchange
                    if (!GE.contains(Players.getLocal().getTile())) {
                        // Se il bot non è al GE, muovilo verso il GE
                        Walking.walk(GE.getCenter().getRandomized());
                        break; // Esce dallo switch e attende il prossimo ciclo onLoop
                    }
    
                    // Se il bot è arrivato al GE, controlla se il mulo è presente
                    if (muleIsAtGE()) {
                        // Se il mulo è presente, passa allo stato di consegna al mulo
                        state = State.DELIVER_TO_MULE;
                    } else {
                        // Se il mulo non è presente, rimane nello stato di consegna al GE
                        log("Mulo non trovato al GE, rimango in attesa...");
                    }
                    break;
    
    
    
                case DELIVER_TO_MULE:
                    long currentTime = System.currentTimeMillis();
                    if (lastDeliveryTime == 0 ||currentTime - lastDeliveryTime >= 300000) {
                        try (Socket socket = new Socket(MULE_IP, MULE_PORT)) {
                            OutputStream outputStream = socket.getOutputStream();
                            ObjectOutputStream objectOutputStream = new ObjectOutputStream(outputStream);
    
                            Bank.setWithdrawMode(BankMode.NOTE);
                            Bank.withdrawAll("Iron ore");
    
                            int ironOreCount = getIronOreCount();
                            Player mule = getMuleName();
                            if (mule != null) {
                                DeliveryData deliveryData = new DeliveryData(ironOreCount, Players.getLocal().getName(), mule.getName());
                                objectOutputStream.writeObject(deliveryData);
                                objectOutputStream.close();
                                outputStream.close();
                                lastDeliveryTime = currentTime;
    
                                mule.interact("Trade with");
                                Sleep.sleepUntil(() -> Trade.isOpen(), 5000);
                                Trade.acceptTrade();
                            } else {
    
                                state = State.DELIVER_TO_GE;
                            }
                        } catch (IOException e) {
                            e.printStackTrace();
    
                        }
    
                    }
                    break;
            }
            return 500;
    
        }
    
        private State getState() {
            long currentTime = System.currentTimeMillis();
            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;
    
            } else if (lastDeliveryTime == 0 ||currentTime - lastDeliveryTime >= 300000) {
                if (muleIsAtGE()) {
                    return State.DELIVER_TO_MULE;
                } else {
                    return State.DELIVER_TO_GE;
                }
            }
            return state;
        }
        private int getIronOreCount() {
            return Inventory.count("Iron ore") + Bank.count("Iron ore");
        }
    
        private boolean muleIsAtGE() {
            Tile botPosition = Players.getLocal().getTile();
            return GE.contains(botPosition);
        }
    
        private String getLocalHostIPAddress() {
            try {
                InetAddress localHost = InetAddress.getLocalHost();
                return localHost.getHostAddress();
            } catch (UnknownHostException e) {
                log("Errore durante la ricerca dell'indirizzo IP locale: " + e.getMessage());
                return null;
            }
        }
    
        private List<Player> getPlayers() {
            return Players.all().stream()
                    .filter(p -> p != null && p.exists() && p.isOnScreen() && p.getTile().distance(Players.getLocal().getTile()) < 20)
                    .collect(Collectors.toList());
        }
        private Player getMuleName() {
            List<Player> players = getPlayers();
            if (players != null) {
                for (Player player : players) {
                    if (player.getName() != null && !player.getName().equals(Players.getLocal().getName())) {
                        return player;
                    }
                }
            }
            return null;
        }
    }
    Link to comment
    Share on other sites

    Just from looking at  your getState() method, it would never get past your MINING ORE STATE as atleast one of these are always true.

    private State getState() {
        long currentTime = System.currentTimeMillis();
        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;
        }
    
    this part below will never get executed 
    
    
    else if (lastDeliveryTime == 0 ||currentTime - lastDeliveryTime >= 300000) {
            if (muleIsAtGE()) {
                return State.DELIVER_TO_MULE;
            } else {
                return State.DELIVER_TO_GE;
            }
        }
        return state;
    }
    
    because your always returning before you even get there
    

     

    you need to put it first in the list and make sure your logic is correct

    Edited by Deep Slayer
    Link to comment
    Share on other sites

    Back then, at the beginning, I also had such logical errors. Perhaps you can make it a bit easier for yourself, for example, by setting mining = true, then reset to false when it is reset, just as an example. At that point, it would be more like when the number or time is reached, set the boolean xxx to true, then switch it back to false once the cycle is complete. You can then represent and switch this more easily through encapsulation..

    bsp.

    public class RuneCraftTasks {
        private boolean inFerox;

    .....

    while(!task.isComplete()){
        if (!inFerox && !ignoreFerox) {
            if (!Bank.isOpen()) {
                Walking.walk(Bank_Area);

    .......

    if (runesCraftet) {
        Equipment.interact(EquipmentSlot.RING, "Ferox Enclave");
        Sleep.sleep(2200, 3200);
        inFerox = false;

    ..........

    ps: If you plan on writing larger scripts in the future, your current method will "kill" you. I once wrote over 50 logics this way, so much effort for nothing, because something will always overlap (in your case, it already does) ;)

    Edited by Dexter Bots
    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.