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.

Flawless path walking

Featured Replies

import org.osbot.script.Script;
import org.osbot.script.rs2.map.Position;

/**
 * Created by Pain aka Exarticus
 * Credit me if you use
 * Walks path, randomizes path
 */
public class Walk {
    private Script script;

    public Walk(Script s){
        this.script = s;
    }

    public Position[] randomizePath(Position [] path, int maxX, int maxY){
        Position [] randomizedPath = new Position[path.length];
        for (int i = 0; i < path.length; i++){
            int x = path[i].getX();
            int y = path[i].getY();
            if (maxX > 0){
                double d = Math.random() * 2 - 1.0;
                d *= maxX;
                x += (int)d;
            }
            if (maxY > 0){
                double d = Math.random() * 2 -1.0;
                d *= maxY;
                y += (int)d;
            }
            randomizedPath[i] = new Position(x,y,path[i].getZ());
        }
        return randomizedPath;
    }

    public Position getNextPosition(Position [] path){
        int dist = 99; int closest = -1;
        for (int i = path.length - 1; i >= 0; i--){
            Position pos = path[i];
            int d = script.distance(pos);
            if (d < dist){
                dist = d;
                closest = i;
            }
        }
        if (closest == -1)return null;
        int index = -1;

        for (int i = closest; i < path.length; i++) {

            if (script.distance(path[i]) <= 16) {
                index = i;
            } else {
                break;
            }
        }

        if (index == -1) {
            return null;
        } else {
            return path[index];
        }
    }
    public void walkPath(Position[] path) throws InterruptedException {
        Position nextPosition = getNextPosition(path);
        if (nextPosition == null)script.log("Could not find path");
        if (nextPosition != null && script.canReach(nextPosition)){
            script.log("Walking to "+nextPosition.getX()+","+nextPosition.getY());
            script.walkMiniMap(nextPosition);
        }
        while (script.distance(nextPosition) > 5 || script.client.getMyPlayer().isMoving()){
            script.sleep(50);
        }


    }

}

How to use:

walker.walkPath(walker.randomizePath(toBank,2,2));
Position[] toBank = new Position[]{new Position(2611,3101,0),new Position(2612,3112,0),new Position(2604,3115,0)};
    
    public void onStart() {
        try {
            Walk walker = new Walk(this);
            startTime = System.currentTimeMillis();

        } catch (Exception e) {
            log("EXCEPTION"  + e.getStackTrace()[0]);
        }


    }

Edited by Mr Asshole

  • Author

You should have it handle Doors and Gates if you want it to stand out...there's already a path walker, and you can add randomization it in like 5 minutes.

Not sure what other path walker your talking about. This is easier as you can use cory's path grabber to grab the path array and then you can feed it as a parameter. The other path walkers use multi dimensional arrays which isn't practical.

 

You should have it handle Doors and Gates if you want it to stand out...there's already a path walker, and you can add randomization it in like 5 minutes.

Not sure what other path walker your talking about. This is easier as you can use cory's path grabber to grab the path array and then you can feed it as a parameter. The other path walkers use multi dimensional arrays which isn't practical.

 

How is a multidimensional array not practical? Yours uses an array of Position objects. I'd say the multidimensional array is more practical in that it uses less memory because each "element" stores 2 ints rather than a Position object that is (slightly) larger than 2 ints. 

  • Author

I'm saying in terms of usability it's easier as you don't have to write the array.

You should have it handle Doors and Gates if you want it to stand out...there's already a path walker, and you can add randomization it in like 5 minutes.

Not sure what other path walker your talking about. This is easier as you can use cory's path grabber to grab the path array and then you can feed it as a parameter. The other path walkers use multi dimensional arrays which isn't practical.

How is a multidimensional array not practical? Yours uses an array of Position objects. I'd say the multidimensional array is more practical in that it uses less memory because each "element" stores 2 ints rather than a Position object that is (slightly) larger than 2 ints.

hey i am using your script and i get a error on

startTime = System.currentTimeMillis();

do u know why?

hey i am using your script and i get a error on

startTime = System.currentTimeMillis();

do u know why?

That isn't part of the path walking. That was just in his start method, which he was showing as a reference.

 

hey i am using your script and i get a error on

startTime = System.currentTimeMillis();

do u know why?

That isn't part of the path walking. That was just in his start method, which he was showing as a reference.

 

 

can u add me on skype and help me with that?

Oh also, when using 

walker.walkPath(walker.randomizePath(toBank,2,2));

in your loop, you're effectively calling the randomizePath function every time you loop around. Not only is this a huge waste of time/resources, but it also leads to the path being less "random". As you randomize it many times per tile walked possibly, you'd get a distribution centered toward your actual tile, rather than closer to true random. It's more like gaussian random.

  • Author

Oh also, when using

walker.walkPath(walker.randomizePath(toBank,2,2));
in your loop, you're effectively calling the randomizePath function every time you loop around. Not only is this a huge waste of time/resources, but it also leads to the path being less "random". As you randomize it many times per tile walked possibly, you'd get a distribution centered toward your actual tile, rather than closer to true random. It's more like gaussian random.
You could always call the randomize path method once in onStart.

I get an error when I try to add this to my code can you help me Mr Asshole?

Guest
This topic is now closed to further replies.

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.