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
  • Rate my first script


    Prankpatrol

    Recommended Posts

    It uses obstacle actions, selects the next usable obstacle and once its gained exp adds the obstacle to a list of obstacles to not try to click.. first time with Java if you cant tell lmao

     

    import org.dreambot.api.Client;
    import org.dreambot.api.input.Mouse;
    import org.dreambot.api.methods.container.impl.bank.BankLocation;
    import org.dreambot.api.methods.event.CameraEvent;
    import org.dreambot.api.methods.event.CameraEvent$CameraType;
    import org.dreambot.api.methods.input.Camera;
    import org.dreambot.api.methods.input.CameraMode;
    import org.dreambot.api.methods.item.GroundItems;
    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.methods.skills.Skills;
    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.widgets.Menu;
    import org.dreambot.api.methods.interactive.Players;
    import org.dreambot.api.utilities.Logger;
    import org.dreambot.api.wrappers.interactive.GameObject;
    import org.dreambot.api.wrappers.interactive.Locatable;
    import org.dreambot.api.methods.interactive.GameObjects;
    import org.dreambot.api.wrappers.interactive.GameObject;
    import org.dreambot.api.wrappers.items.GroundItem;
    
    import javax.imageio.ImageIO;
    
    import javax.swing.*;
    import java.io.IOException;
    import java.net.URL;
    import java.util.Arrays;
    import java.util.LinkedList;
    import java.util.List;
    import java.util.ArrayList;
    import java.awt.*;
    import java.awt.Graphics;
    import java.util.concurrent.ThreadLocalRandom;
    import java.util.concurrent.locks.Condition;
    
    import java.util.concurrent.TimeUnit;
    import static org.dreambot.api.methods.input.Camera.*;
    import static org.dreambot.api.methods.map.Map.*;
    import static org.dreambot.api.methods.skills.Skills.getExperience;
    import static org.dreambot.api.methods.walking.impl.Walking.*;
    
    
    @ScriptManifest(name = "KnobbiesAgility", description = "Runs the agility courses", author = "Knob Twister",
            version = 1.0, category = Category.AGILITY, image = "Ra7CRyp.jpg")
    
    
    
    public class Agility extends AbstractScript {
        private long timeBegan;
        private long timeRan;
        int beginningXP = 0;
        int currentXp;
        private int xpGained;
        private int currentLevel;
        private int beginningLevel;
        private int levelsGained;
        final Image bg = getImage("https://i.imgur.com/3iEmCnR.png");
        private LinkedList<Integer> PreviousObstacles = new LinkedList<Integer>();
        int EXP = 0;
        int animation;
        GameObject gameObject;
        State currentState;
        Area vStart = new Area(new Tile(3497,3492, 0), new Tile(3510, 3476, 0));
        public enum State {
            ON_ROOF,
            ON_GROUND,
            AT_STARTZONE,
            USING_OBSTACLE
        }
    
        public void onStart() {
            timeBegan = System.currentTimeMillis();
            beginningXP = Skills.getExperience(Skill.AGILITY);
            Logger.log(Skills.getExperience(Skill.AGILITY));
            beginningLevel = Skills.getRealLevel(Skill.AGILITY);
            int playerZ = Players.getLocal().getZ();
            if (playerZ==0) {
                State currentState = State.ON_GROUND;
                Logger.log("Walking to Start");
            } else {
                State currentState = State.ON_ROOF;
            }
        }
    
        public void onExit() {
    
        }
    
        private Image getImage(String url)
        {
            try
            {
                return ImageIO.read(new URL(url));
            }
            catch (IOException e) { Logger.log("no image downloaded:" + e); }
            return null;
        }
    
        public void RandomInteract(GameObject obstacle, String Action){
            Logger.log("Zoom LeveL"+ getZoom());
            int randomNum = ThreadLocalRandom.current().nextInt(1, 3 + 1);
            Logger.log("random number" + randomNum);
            if(randomNum==1){
                if(!Menu.isVisible() && obstacle.isOnScreen()){
                    Mouse.click(obstacle.getClickablePoint());
                    Menu.mouseOverAction(Action);
                    sleep(50,200);
                    Menu.clickAction(Action);
                } else {
                    mouseRotateToTile(obstacle.getTile());
                    if(!Menu.isVisible() && obstacle.isOnScreen()) {
                        Mouse.click(obstacle.getClickablePoint());
                        Menu.mouseOverAction(Action);
                        sleep(50, 200);
                        Menu.clickAction(Action);
                    } else {
                        obstacle.interact(Action);
                    }
                }
            }
            if(randomNum==2) {
                obstacle.interact(Action);
            }
            if(randomNum==3) {
                while(Players.getLocal().distance(getWalkable(obstacle.getTile()))>=3) {
                    mouseRotateToTile(obstacle.getTile());
                    Walking.walk(obstacle.getTile());
                    sleep(500, 700);
                }
                obstacle.interact(Action);
            }
    
        }
    
        private boolean isPlayerNotMoving() {
            return !Players.getLocal().isMoving();
        }
    
    
        private String ft(long duration)
        {
            String res = "";
            long days = TimeUnit.MILLISECONDS.toDays(duration);
            long hours = TimeUnit.MILLISECONDS.toHours(duration)
                    - TimeUnit.DAYS.toHours(TimeUnit.MILLISECONDS.toDays(duration));
            long minutes = TimeUnit.MILLISECONDS.toMinutes(duration)
                    - TimeUnit.HOURS.toMinutes(TimeUnit.MILLISECONDS
                    .toHours(duration));
            long seconds = TimeUnit.MILLISECONDS.toSeconds(duration)
                    - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS
                    .toMinutes(duration));
            if (days == 0) {
                res = (hours + ":" + minutes + ":" + seconds);
            } else {
                res = (days + ":" + hours + ":" + minutes + ":" + seconds);
            }
            return res;
        }
    
    
        public void getNextObstacle() {
            String[] actions = {"Climb", "Cross", "Leap", "Balance", "Hurdle", "Jump-off", "Jump", "Vault"};
            gameObject = GameObjects.closest(go -> go != null &&
                    (Arrays.stream(actions).anyMatch(go::hasAction)) && go.canReach() && !PreviousObstacles.contains(go.getID()));
            Logger.log(gameObject.getActions()[0]);
        }
    
    
    
        public void useObstacle() {
            if (gameObject != null && !Players.getLocal().isMoving() && currentState != State.USING_OBSTACLE) {
                Logger.log(gameObject.getActions()[0] + gameObject.getID());
                switch (gameObject.getActions()[0]) {
                    case "Climb":
                        RandomInteract(gameObject, "Climb");
                        sleepUntil(() -> animation!=-1, 2000,20);
                        break;
                    case "Cross":
                        RandomInteract(gameObject, "Cross");
                        sleepUntil(() -> animation!=-1, 2000,20);
                        break;
                    case "Leap":
                        RandomInteract(gameObject, "Leap");
                        sleepUntil(() -> animation!=-1, 2000,20);
                        break;
                    case "Balance":
                        RandomInteract(gameObject, "Balance");
                        sleepUntil(() -> animation!=-1, 2000,20);
                        break;
                    case "Hurdle":
                        RandomInteract(gameObject, "Hurdle");
                        sleepUntil(() -> animation!=-1, 2000,20);
                        break;
                    case "Jump-off":
                        RandomInteract(gameObject, "Jump-off");
                        sleepUntil(() -> animation!=-1, 2000,20);
                        break;
                    case "Jump":
                        Logger.log("is it on screen:" + gameObject.isOnScreen());
                        RandomInteract(gameObject, "Jump");
                        sleepUntil(() -> animation!=-1, 2000,50);
                        break;
                    case "Vault":
                        int randomZoomIn = ThreadLocalRandom.current().nextInt(280, 320);
                        setZoom(randomZoomIn);
                        RandomInteract(gameObject, "Vault");
                        sleepUntil(() -> animation!=-1, 200,50);
                        break;
                    default:
                        Logger.log("Action not found.." + gameObject.getActions()[0]);
                        // This should never happen if we've already checked for the actions
                        break;
                }
            }
            if( gameObject == null ){
                getNextObstacle();
            }
        }
    
        @Override
        public void onPaint(Graphics g) {
            g.drawImage(bg, 0, 250, null);
            currentXp = Skills.getExperience(Skill.AGILITY);
            xpGained = currentXp - beginningXP;
            timeRan = System.currentTimeMillis() - this.timeBegan;
            currentLevel = Skills.getRealLevel(Skill.AGILITY);
            levelsGained = currentLevel - beginningLevel;
            Color purple = new Color(50, 14, 41);
            g.setColor(purple);
            int XPPerHour = (int)(xpGained / ((System.currentTimeMillis() - timeBegan) / 3600000.0D));
            g.drawString("Time Spent Rubbing: " + ft(timeRan), 200, 375);
            g.drawString("XP Splooged: " + xpGained, 200, 390);
            g.drawString("Splooges Per Hour: " + XPPerHour, 200, 405);
            g.drawString("Initial Size: " + beginningLevel, 200,420);
            g.drawString("Current Hardness: " + currentLevel, 200,435);
            g.drawString("Girth Obtained: " + levelsGained, 200, 450);
            try{
                if (gameObject != null) {
                    Tile tile = gameObject.getTile();
                    Polygon tilePolygon = tile.getPolygon();
                    g.setColor(Color.RED);
                    g.drawPolygon(tilePolygon);
                }
            } catch (NullPointerException e) {
                e.printStackTrace();
            }
    
        }
    
        @Override
        public int onLoop() {
            if(!isRunEnabled() && (getRunEnergy()>15)){
                toggleRun();
            }
    
            if(gameObject==null){
                getNextObstacle();
            }
    
            GroundItem item = GroundItems.closest(i -> i != null && i.getName().toLowerCase().contains("grace") && i.canReach());
            try{
                if((item != null) && (item.exists())) {
                    if (item.interact("Take")) {
                        sleepUntil(() -> !item.exists(), 200, 50);
                    }
                }
            } catch (NullPointerException e) {
                e.printStackTrace();
            }
            Logger.log(Skills.getExperience(Skill.AGILITY) + " " + EXP);
            if (PreviousObstacles.size() > 3) {
                PreviousObstacles.removeLast();
            }
            Tile playerPosition = Players.getLocal().getTile();
            int playerZ = Players.getLocal().getZ();
            animation = Players.getLocal().getAnimation();
            if (playerZ==0) {
                if (vStart.contains(playerPosition)) {
                    currentState = State.AT_STARTZONE;
    
                } else {
                    currentState = State.ON_GROUND;
                }
            } else {
                if (animation != -1){
                    currentState = State.USING_OBSTACLE;
                } else {
                    currentState = State.ON_ROOF;
                }
            }
            switch (currentState) {
                case ON_GROUND:
                    if(getZoom()>200){
                        int randomZoomOut = ThreadLocalRandom.current().nextInt(181, 195);
                        setZoom(randomZoomOut);
                        rotateToPitch(383);
                    }
                    Logger.log("On the ground..");
                    Tile randomTile = vStart.getRandomTile();
                    mouseRotateToTile(randomTile);
                    Walking.walk(randomTile);
                    break;
                case AT_STARTZONE:
                    Logger.log("At the start...");
                    getNextObstacle();
                    useObstacle();
                case USING_OBSTACLE:
                    sleep(150,300);
                case ON_ROOF:
                    if(EXP != Skills.getExperience(Skill.AGILITY)){
                        ///Logger.log("GameID:" + gameObject.getID());
    //            PreviousObstacles.addFirst(gameObject.getID());
                        EXP = Skills.getExperience(Skill.AGILITY);
                        Logger.log("EXP GAINED, GETTING NEXT OBSTACLE");
                        for (Integer obstacle : PreviousObstacles) {
                            Logger.log("Obstacle ID: " + obstacle);
                        }
                        getNextObstacle();
                    }
                    Logger.log("Using next obstacle.." + gameObject.getID());
                    useObstacle();
                    break;
            }
            sleepUntil(() -> isPlayerNotMoving(), 1000, 50);
            return 20;
        }
    }



     

    Edited by Prankpatrol
    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.