Jump to content

Simple Walking


QBots

Recommended Posts

This class is simple, yet effective walking. I use it in my private scripts and it has yet to fail me.



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

import java.awt.*;

public class Walk {

    private Script script;
    //static public Position[] Path;
    private int[] distance;


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

    Position[] CreatePath(int[][] path) {
        Position[] returnpath = new Position[path.length];
        for(int i = 0; i < path.length; i++) {
            returnpath[i] = new Position(path[i][0], path[i][1], 0);
        }
        //Path = returnpath.clone();
        return returnpath;
    }

    static int current = 0;
    boolean getNext(Position[] Path, boolean isCircle) {

        if(Path[current].distance(script.myPosition()) > 50 || current > Path.length || !script.canReach(Path[current])) {
            current = 0;
        }

        if(current == Path.length-1 && isCircle) {
            script.log("Reseting path");
            current = 0;
            return true;
        }

        if(current+1 < Path.length && Path[current+1].distance(script.myPosition()) < 15) {
            current += 1;
            return true;
        }

        for(int i = current; i < Path.length; i++) {
            if(script.canReach(Path[i]) && i > current && Path[i].distance(script.client.getMyPlayer().getPosition()) < 16) {
                if(i+1 < Path.length && script.canReach(Path[i+1]) && Path[i+1].distance(script.myPosition()) < 16)
                    current = i+1;
                else
                    current = i;
                script.log("Current: "+current);
                script.log("Distance to current: "+Path[i].distance(script.myPosition()));

            }

        }

        return true;
    }

    public void WalkPath(Position[] path, boolean isCircle) throws InterruptedException {
        if(!script.isRunning() && script.client.getRunEnergy() > 50) {
            script.setRunning(true);
        }
        if(getNext(path, isCircle)) {
            script.walkMiniMap(path[current]);
        }

    }

}


Setting up this script is simple:

Walk walker = new Walk(this);

int[][] OuterAbyssPath = {
            {3017, 4823},
            {3017, 4825},
            {3017, 4827},
            removed
};

onLoop() {
            walker.WalkPath(walker.CreatePath(OuterAbyssPath),true);
            return 100;
}
Edited by QBots
Link to comment
Share on other sites

  • 4 weeks later...
  • 4 weeks later...

 

anyone else tested it? It comes to the end point and then goes there and back, in infinite loop...

I suggest not using this, there's other methods which are more efficient, plus the 2d array isn't really necessary, just adds potential confusion/problems.

 

could you link me another in PM? I can't find anything else :(

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...