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
  • Staying in a area


    Kirito

    Recommended Posts

    So i'm working on a power miner but everytime it is picking a rock it randomly starts walking by clicking the map and then it keeps running back and ford i have created area tiles but how do i make it so that it dosn't run off?

     

    script code

     

     

    package PowerMiner;
     
     
    import org.dreambot.api.script.AbstractScript;
    import org.dreambot.api.methods.Calculations;
    import org.dreambot.api.methods.map.Area;
    import org.dreambot.api.methods.map.Tile;
    import org.dreambot.api.methods.skills.Skill;
    import org.dreambot.api.script.Category;
    import org.dreambot.api.script.ScriptManifest;
    import org.dreambot.api.script.listener.PaintListener;
    import org.dreambot.api.utilities.Timer;
    import org.dreambot.api.wrappers.interactive.GameObject;
    import java.awt.Color;
    import java.awt.Font;
    import java.awt.Graphics;
    import java.awt.Graphics2D;
    import java.awt.Image;
    import java.io.IOException;
    import java.net.URL;
     
    import javax.imageio.ImageIO;
     
     
    @ScriptManifest(author = "Kirito", name = "Simple Power Miner", version = 0.01, description = "Simply mines in Varrock East.", category = Category.MINING)
    public class PowerMiner extends AbstractScript implements PaintListener {
     
    private long startTime = System.currentTimeMillis();
        private int oremined = 0;
        public State State;
        Area myArea = new Area(new Tile(3281, 3370), new Tile(3290, 3370), new Tile(3290, 3361), new Tile(3282, 3361));
     
    public void onStart() {
    getCamera().rotateToPitch(383);
            getSkillTracker().start(Skill.MINING);
            startTime = System.currentTimeMillis();
    }
     
    private enum State {
    WELCOME, MINE, DROP, NO_STATE
    };
     
    private State getState() {
    GameObject rock = getGameObjects().closest(ore -> ore.getID() == 7484 || ore.getID() == 7453);
    if (rock != null && rock.isOnScreen() && !getInventory().isFull() && getInventory().contains(item -> item != null && item.getName() != null && item.getName().contains("pickaxe"))) {
            {
                return State.MINE;
            } 
    }
            else if (rock != null && rock.isOnScreen() && !getInventory().isFull() && getInventory().contains(item -> item != null && item.getName() != null && item.getName().contains("pickaxe")))
            {
                return State.DROP;
            }
            return State.NO_STATE;
        }
    private String stateParser() {
             if (State == State.MINE) {
                return "Mining";
            } else if (State == State.DROP) {
                return "Dropping";
            } else if (State == State.NO_STATE) {
                return "No idea";
            }
           else return "Waiting";
        }
     
     
    public void onExit() {
    }
     
        private Image getImage(String url) {
            try {
                return ImageIO.read(new URL(url));
            } catch(IOException e) {
                return null;
            }
        }
     
        private final Color color1 = new Color(255, 255, 255);
     
        private final Font font1 = new Font("Arial", 0, 14);
     
        private final Image img1 = getImage("http://i64.tinypic.com/2hcohuu.png");
     
        public void onRepaint(Graphics g1) {
            Graphics2D g = (Graphics2D)g1;
            g.drawImage(img1, -5, -1, null);
            g.setFont(font1);
            g.setColor(color1);
            g.drawString("Simple Power Miner V0.01", 546, 461);
        }
     
     
     
     
     
    @Override
       public int onLoop() {
    GameObject rock = getGameObjects().closest(ore -> ore.getID() == 7484 || ore.getID() == 7453);
           State = getState();
           switch(State){
               case MINE:
                   mine(rock);
                   break;
               case DROP:
                   drop();
                   break;
               case NO_STATE:
                   break;
           }
           return 500;
       }
     
     
     
       private double progressBar()
       {
           return ((double) (getSkills().getExperience(Skill.MINING) - getSkills().getExperienceForLevel(getSkills().getRealLevel(Skill.MINING)))
                   / (getSkills().getExperienceForLevel(getSkills().getRealLevel(Skill.MINING) + 1) - getSkills().getExperienceForLevel(getSkills().getRealLevel(Skill.MINING)))) * 100;
       }
       
       
       
       
       
       
       @Override
       public void onPaint(Graphics g)
       {
     
           g.setColor(new Color(48, 48, 48, 180));
           //g.fillRect(5, 240, 370, 99);
           g.setFont(new Font(Font.MONOSPACED, Font.ROMAN_BASELINE, 14));
           g.setColor(Color.BLUE);
           //g.drawString("Simple Power MINEper V0.01   -", 10, 260);
           g.drawString("Runtime: " + Timer.formatTime(System.currentTimeMillis() - startTime), 10, 260);
           g.drawString("Exp/hr: " + getSkillTracker().getGainedExperiencePerHour(Skill.MINING) , 10, 280);
           g.drawString("Exp gained: " + getSkillTracker().getGainedExperience(Skill.MINING), 10, 300);
           g.drawString("Levels gained: " + getSkillTracker().getGainedLevels(Skill.MINING) , 220, 320);
          // g.drawRect(10, 310, 100, 15);
           g.fillRect(10, 310, (int) progressBar(), 15);
           g.drawString("Ores Mined: " + oremined, 220, 300);
           g.drawString("State: " + stateParser(), 220, 280);
           g.drawImage(img1, -5, -1, null);
           g.setFont(font1);
           g.setColor(color1);
           g.drawString("Simple Power Miner V0.01", 546, 461);
       }
       
       
       
       
       
       public void mine(GameObject rock) {
           int oreID = 436;
               if (getInventory().contains(i -> i.getName().contains("pickaxe"))  && !getInventory().isFull()) {
                   if (getLocalPlayer().distance(rock) >3) {
                    getWalking().walk(rock);
                       sleepUntil(() ->!getLocalPlayer().isMoving(), 300);
                   }else if (!getLocalPlayer().isAnimating() && !getLocalPlayer().isMoving() && rock.exists() && rock.isOnScreen()) { //&& myORE != null
                       int oreCount = getInventory().count(438);
                       rock.interact("Mine");
                           if(getLocalPlayer().isAnimating()) {
                               sleepUntil(() -> getInventory().count(oreID) > oreCount, Calculations.random(10000, 15000));
                               oremined++;
                           }
                   }else getCamera().rotateToEntity(getGameObjects().closest("rock"));
               }else if (getInventory().isFull()) {
                   State = State.DROP;
               }
           }
       
       private void drop() {
        if (getInventory().isFull()) {
    //getInventory().dropAll("ore");
    getInventory().dropAllExcept(f -> f != null &&f.getName().contains("pickaxe"));
        }else if (getInventory().isFull()) {
                    State = State.MINE;
                }
            }
       
    

    Solved myself ^^ can be deleted

    Link to comment
    Share on other sites

    Archived

    This topic is now archived and is closed to further replies.

    ×
    ×
    • 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.