Jump to content
View in the app

A better way to browse. Learn more.

OSBot :: 2007 OSRS Botting

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Trying to get a decent walking file...

Featured Replies

Alright i need some help fellas. My walking file seems to be very inconsistent. webWalk usually does not work that well for example. Anyone see what I'm doing wrong? 

 

import org.osbot.rs07.api.map.Position;
import org.osbot.rs07.api.map.Area;
import java.util.List;
import org.osbot.rs07.script.MethodProvider;

public class MasterWalker extends MethodProvider {

    private static final int WEB_WALK_TIMEOUT = 5000; // Increased timeout for longer paths
    private static final int INTERACT_DISTANCE_THRESHOLD = 10; // Proximity threshold for target position
    private static final int MAX_REGULAR_WALK_ATTEMPTS = 3; // Max attempts for regular walking before using webWalk
    private static final int STEP_DIVISION_UNIT = 5; // Smaller step distances for finer control

    // Overloaded walkTo method that accepts a list of waypoints
    public boolean walkTo(Position destination, List<Position> waypoints, CheckInterrupt interrupt) throws InterruptedException {
        // Check if the player is already at the destination
        if (myPosition().equals(destination)) {
            log("Player is already at the destination: " + destination);
            return true;
        }

        for (Position waypoint : waypoints) {
            if (divideAndWalk(waypoint, interrupt)) {
                if (getWalking().webWalk(destination)) {
                    return true;
                }
            }
        }
        log("Fallback to direct webWalk to final destination.");
        return webWalkWithTimeout(destination); // Fallback if waypoints don’t work
    }

    public boolean walkTo(Object destination, CheckInterrupt interrupt) throws InterruptedException {
        checkRunEnergy();

        if (destination instanceof Position) {
            Position position = (Position) destination;
            // Check if the player is already at the position
            if (myPosition().equals(position)) {
                log("Player is already at the target position: " + position);
                return true;
            }
            if (canReach(position)) {
                log("Position is reachable via regular walk.");
                return divideAndWalk(position, interrupt);
            } else {
                log("Position appears unreachable via regular walk, attempting web walk as fallback.");
                return webWalkWithTimeout(position);
            }
        } else if (destination instanceof Area) {
            Area area = (Area) destination;
            // Check if the player is already within the area
            if (area.contains(myPosition())) {
                log("Player is already within the target area: " + area);
                return true;
            }
            Position randomPosition = area.getRandomPosition();
            if (canReach(randomPosition)) {
                log("Area is reachable via regular walk.");
                return divideAndWalk(randomPosition, interrupt);
            } else {
                log("Area appears unreachable via regular walk, attempting web walk as fallback.");
                return webWalkWithTimeout(randomPosition);
            }
        } else if (destination instanceof List) {
            return handlePath((List<Position>) destination, interrupt);
        }
        return false; // Invalid input
    }

    private boolean divideAndWalk(Position target, CheckInterrupt interrupt) throws InterruptedException {
        double distance = myPosition().distance(target);
        int steps = (int) Math.ceil(distance / STEP_DIVISION_UNIT);
        log("Calculated steps to target: " + steps);

        Position currentPosition = myPosition();
        for (int i = 0; i < steps; i++) {
            checkRunEnergy();

            if (interrupt.shouldInterrupt()) {
                log("Interrupt condition met; stopping walk.");
                return false;
            }

            Position stepTarget = getIntermediatePosition(currentPosition, target, STEP_DIVISION_UNIT);
            log("Attempting regular walk to intermediate point: " + stepTarget);
            if (!walkToPosition(stepTarget)) {
                log("Failed to reach intermediate point: " + stepTarget);
                return false;
            }
            currentPosition = stepTarget;
            waitUntilStopped(3000);
        }
        log("Successfully divided and reached target position: " + target);
        return true;
    }

    private Position getIntermediatePosition(Position from, Position to, int stepDistance) {
        double distance = from.distance(to);
        double ratio = stepDistance / distance;
        int x = (int) (from.getX() + (to.getX() - from.getX()) * ratio);
        int y = (int) (from.getY() + (to.getY() - from.getY()) * ratio);
        return new Position(x, y, from.getZ());
    }

    private boolean walkToPosition(Position position) throws InterruptedException {
        checkRunEnergy();
        log("Attempting regular walk to: " + position);
        if (getWalking().walk(position)) {
            customSleep(5000);
            return true;
        }
        log("Regular walking to " + position + " failed.");
        return false;
    }

    private boolean webWalkWithTimeout(Position position) throws InterruptedException {
        long startTime = System.currentTimeMillis();
        log("Attempting webWalk to position: " + position);

        while (System.currentTimeMillis() - startTime < WEB_WALK_TIMEOUT) {
            if (getWalking().webWalk(position)) {
                customSleep(10000);
                return true;
            }
            log("Attempting to reach position: " + position + " - Time elapsed: " + (System.currentTimeMillis() - startTime) + "ms");
            sleep(200);
        }
        log("Web walk to position timed out after " + WEB_WALK_TIMEOUT + "ms.");
        return false;
    }

    private void checkRunEnergy() {
        if (!getSettings().isRunning() && getSettings().getRunEnergy() > 15) {
            getSettings().setRunning(true);
            log("Run energy above 15%; enabling run mode.");
        }
    }

    private void waitUntilStopped(int timeout) throws InterruptedException {
        int timeWaited = 0;
        while (myPlayer().isMoving() && timeWaited < timeout) {
            sleep(100);
            timeWaited += 100;
        }
    }

    // Utility method to simulate custom sleep
    private void customSleep(int timeout) throws InterruptedException {
        int timeWaited = 0;
        while (myPlayer().isMoving() && timeWaited < timeout) {
            sleep(100);
            timeWaited += 100;
        }
    }

    private boolean handlePath(List<Position> path, CheckInterrupt interrupt) throws InterruptedException {
        for (Position position : path) {
            checkRunEnergy();
            if (interrupt.shouldInterrupt()) {
                log("Interrupt condition met; stopping path.");
                return false;
            }
            if (!walkToPosition(position)) {
                log("Failed to walk to position in path: " + position);
                return false;
            }
            waitUntilStopped(3000);
        }
        return true;
    }

    public interface CheckInterrupt {
        boolean shouldInterrupt();
    }

    private boolean canReach(Position position) {
        return getMap().canReach(position);
    }

    private boolean canReach(Area area) {
        for (Position pos : area.getPositions()) {
            if (getMap().canReach(pos)) {
                return true;
            }
        }
        return false;
    }
}


Hard to tell by reading the code, but seems quiet the overkill as most of it is already done by the API

you can simply make WalkingEvent and webWalkEvent and set all of these settings you need :)
https://osbot.org/api/org/osbot/rs07/event/WalkingEvent.html

For WebwalkEvent you can even create a PathPreference profile to determine what telewports to use etc.
https://osbot.org/api/org/osbot/rs07/event/WebWalkEvent.html

What is going wrong exactly?

I made a similar one a while ago that still works today:
 

Spoiler
package scripts;

import org.osbot.rs07.api.map.Area;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.HashMap;
import java.util.Map;

@ScriptManifest(name = "Walker", author = "Dubai", version = 0.3, info = "common locations", logo = "")
public class Walker extends Script {

    private Map<String, Area> locations;
    private Area selectedLocation;

    @Override
    public void onStart() {
        // Initialize common locations
        locations = new HashMap<>();
        locations.put("Grand Exchange", new Area(3164, 3485, 3168, 3489));
        locations.put("Varrock Bank", new Area(3180, 3445, 3185, 3433));
        locations.put("Lumbridge Castle", new Area(3210, 3216, 3214, 3220));
        locations.put("Fally East Bank", new Area(3009, 3355, 3017, 3358));;
        locations.put("Fally SW Cows", new Area(3022, 3298, 3042, 3312));

        // Show RockCrabsGUI to select location
        SwingUtilities.invokeLater(this::showGUI);
    }

    private void showGUI() {
        JFrame frame = new JFrame("Select Location");
        frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        frame.setSize(300, 150);

        JComboBox<String> locationComboBox = new JComboBox<>(locations.keySet().toArray(new String[0]));
        JButton startButton = new JButton("Start");

        startButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                String selected = (String) locationComboBox.getSelectedItem();
                selectedLocation = locations.get(selected);
                frame.dispose();
            }
        });

        frame.setLayout(new FlowLayout());
        frame.add(new JLabel("Select a location:"));
        frame.add(locationComboBox);
        frame.add(startButton);

        frame.setVisible(true);
    }

    @Override
    public void onExit() {
        log("Stopping walk wherever script...");
    }

    @Override
    public int onLoop() {
        if (selectedLocation != null) {
            getWalking().webWalk(selectedLocation);
            selectedLocation = null; // Reset after walking to the location
        }
        return 100; // The amount of time in milliseconds before the loop starts over
    }

    @Override
    public void onPaint(Graphics2D g) {
        g.drawString("Walk Wherever", 10, 40);
    }
}

 

 

  • Author

Dang, I didn't realize all of that was handled. You're 100% right. I simplied it all down and no longer am having trouble walking. Thanks!!!

Webwalk is actually overpowered as f. Definitely a lot of time taken to make it this good you can tell.

Create an account or sign in to comment

Recently Browsing 0

  • No registered users viewing this page.

Account

Navigation

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.