Jump to content

Won't walk?


Daviyow

Recommended Posts

hey im making a script and im trying to run from falador to the crumbling wall, heres where im trying to run to, the red dots on the minimap is what my toFence positions are..

b098c17c26.png

feaa05e1bb.png

 

edc14ef7a3.png

 

why is it just standing there and not doing anything? if i help it run it JUST outside the bank, it starts running?

Link to comment
Share on other sites

Hello there, I use this method that was updated by Swizzbeat and originally created by Maxi, works pretty damn good. Try out this method and see if it will work. It works really good for me :D

import org.osbot.rs07.api.def.ObjectDefinition;
import org.osbot.rs07.api.map.Position;
import org.osbot.rs07.api.model.Entity;
import org.osbot.rs07.api.model.RS2Object;
import org.osbot.rs07.api.util.LocalPathFinder;
import org.osbot.rs07.input.mouse.MiniMapTileDestination;
import org.osbot.rs07.input.mouse.RectangleDestination;
import org.osbot.rs07.script.Script;

import java.util.LinkedList;
import java.util.List;

/**
 * Originally created by Maxi
 */

/**
 * Updated by Swizzbeat
 */

public class Walker {
    
    private Script scriptInstance;
    
    public Walker(Script scriptInstance) {
        this.scriptInstance = scriptInstance;
    }
    
    public boolean noObstacleBlocking(Position p) throws InterruptedException {
        RS2Object obstacle = getNextObstacle(p);
        if (obstacle != null) {
            obstacle.interact("open");
            return false;
        }
        return true;
    }
    
    public boolean walkPathMM(Position[] path) throws InterruptedException {
        return walkPathMM(path, 3);
    }
    
    public boolean walkPathMM(Position[] path, int distance) throws InterruptedException {
        Position next = nextTile(path, 15);
        if (next != null && noObstacleBlocking(next)) {
            return clickMiniMapPosition(next);
        }
        Position lastNode = path[path.length - 1];
        return lastNode != null && scriptInstance.map.distance(lastNode) < distance;
    }
    
    public Position nextTile(Position path[], int skipDist) {
        int dist = -1, closest = -1;
        for (int i = path.length - 1; i >= 0; i--) {
            Position tile = path[i];
            int d = scriptInstance.map.distance(tile);
            if (d < dist || dist == -1) {
                dist = d;
                closest = i;
            }
        }
        
        int feasibleTileIndex = -1;
        
        for (int i = closest; i < path.length; i++) {
            if (scriptInstance.map.distance(path[i]) <= skipDist) {
                feasibleTileIndex = i;
            } else {
                break;
            }
        }

		return (feasibleTileIndex == -1) ? null : path[feasibleTileIndex];
    }
    
    public RS2Object getNextObstacle(Entity e) {
        List<RS2Object> obstacles = getObstacles();
        List<Position> path = generatePath(e);
        if (path == null) {
            return null;
        }
        
        for (RS2Object obj : obstacles) {
            for (Position pos : path) {
                if (obj.getPosition().equals(pos)) {
                    return obj;
                }
            }
        }
        return null;
    }
    
    public RS2Object getNextObstacle(Position p) {
        List<RS2Object> obstacles = getObstacles();
        List<Position> path = generatePath(p);
        if (path == null) {
            return null;
        }
        
        for (RS2Object obj : obstacles) {
            for (Position pos : path) {
                if (obj.getPosition().equals(pos)) {
                    return obj;
                }
            }
        }
        return null;
    }
    
    public List<RS2Object> getObstacles() {
        List<RS2Object> list = new LinkedList<>();
        for (RS2Object obj : scriptInstance.objects.getAll()) {
            if (obj.getType() == 0 && obj.getDefinition() != null && obj.getDefinition().getActions() != null && obj.getDefinition().getModelIds() != null && obj.getDefinition().getModelIds().length < 3) {
                search:
                {
                    for (String action : obj.getDefinition().getActions()) {
                        if (action != null && action.equalsIgnoreCase("open")) {
                            list.add(obj);
                            break search;
                        }
                    }
                }
            }
        }
        return list;
    }
    
    private List<Position> generatePath(Position p) {
		LocalPathFinder pf = new LocalPathFinder(scriptInstance.bot);
        int[][] flags = generateModifiedClippingData();
        List<Position> path = pf.findPath(p, flags);
        if (path == null) {
            return null;
        }
        return path;
    }
    
    private List<Position> generatePath(Entity e) {
		LocalPathFinder pf = new LocalPathFinder(scriptInstance.bot);
        int[][] flags = generateModifiedClippingData();
        List<Position> path = pf.findPath(e, flags);
        if (path == null) {
            return null;
        }
        return path;
    }
    
    private int[][] generateModifiedClippingData() {
        int[][] origFlags = scriptInstance.map.getRegion().getClippingPlanes()[scriptInstance.map.getPlane()].getTileFlags();
        int[][] flags = new int[origFlags.length][origFlags.length];
        for (int x = 0; x < flags.length; x++) {
            for (int y = 0; y < flags.length; y++) {
                flags[x][y] = origFlags[x][y];
            }
        }
        
        for (RS2Object obj : getObstacles()) {
            int lx = obj.getLocalX();
            int ly = obj.getLocalY();
            ObjectDefinition def = obj.getDefinition();
            if (def.isClipping1()) {
                switch (obj.getOrientation()) {
                    case 0:
                    case 2:
                        flags[lx][ly] &= ~585;
                        break;
                    case 1:
                    case 3:
                        flags[lx][ly] &= ~1170;
                        break;
                }
            }
            
            if (def.getClipping2() != 0) {
                if (0 == obj.getOrientation()) {
                    flags[lx][ly] &= ~128;
                    flags[lx - 1][ly] &= ~8;
                }
                
                if (1 == obj.getOrientation()) {
                    flags[lx][ly] &= ~2;
                    flags[lx][ly + 1] &= ~32;
                }
                
                if (2 == obj.getOrientation()) {
                    flags[lx][ly] &= ~8;
                    flags[lx + 1][ly] &= ~128;
                }
                
                if (3 == obj.getOrientation()) {
                    flags[lx][ly] &= ~32;
                    flags[lx][ly - 1] &= ~2;
                }
                
                if (def.isClipping3()) {
                    if (0 == obj.getOrientation()) {
                        flags[lx][ly] &= ~65536;
                        flags[lx - 1][ly] &= ~4096;
                    }
                    
                    if (obj.getOrientation() == 1) {
                        flags[lx][ly] &= ~1024;
                        flags[lx][ly + 1] &= ~16384;
                    }
                    
                    if (2 == obj.getOrientation()) {
                        flags[lx][ly] &= ~4096;
                        flags[lx + 1][ly] &= ~65536;
                    }
                    
                    if (3 == obj.getOrientation()) {
                        flags[lx][ly] &= ~16384;
                        flags[lx][ly - 1] &= ~1024;
                    }
                }
            }
        }
        return flags;
    }

    private boolean clickMiniMapPosition(Position position) throws InterruptedException {
	return scriptInstance.mouse.click(new RectangleDestination(scriptInstance.bot, new MiniMapTileDestination(scriptInstance.bot, position).getBoundingBox()));
    }
    
    public Position[] reversePath(Position[] path) {
        Position[] t = new Position[path.length];
        for (int i = 0; i < t.length; i++) {
            t[i] = path[path.length - i - 1];
        }
        return t;
    }
}
Edited by denziz
Link to comment
Share on other sites

  • 4 weeks later...

 

Hello there, I use this method that was updated by Swizzbeat and originally created by Maxi, works pretty damn good. Try out this method and see if it will work. It works really good for me biggrin.png

import org.osbot.rs07.api.def.ObjectDefinition;
import org.osbot.rs07.api.map.Position;
import org.osbot.rs07.api.model.Entity;
import org.osbot.rs07.api.model.RS2Object;
import org.osbot.rs07.api.util.LocalPathFinder;
import org.osbot.rs07.input.mouse.MiniMapTileDestination;
import org.osbot.rs07.input.mouse.RectangleDestination;
import org.osbot.rs07.script.Script;

import java.util.LinkedList;
import java.util.List;

/**
 * Originally created by Maxi
 */

/**
 * Updated by Swizzbeat
 */

public class Walker {
    
    private Script scriptInstance;
    
    public Walker(Script scriptInstance) {
        this.scriptInstance = scriptInstance;
    }
    
    public boolean noObstacleBlocking(Position p) throws InterruptedException {
        RS2Object obstacle = getNextObstacle(p);
        if (obstacle != null) {
            obstacle.interact("open");
            return false;
        }
        return true;
    }
    
    public boolean walkPathMM(Position[] path) throws InterruptedException {
        return walkPathMM(path, 3);
    }
    
    public boolean walkPathMM(Position[] path, int distance) throws InterruptedException {
        Position next = nextTile(path, 15);
        if (next != null && noObstacleBlocking(next)) {
            return clickMiniMapPosition(next);
        }
        Position lastNode = path[path.length - 1];
        return lastNode != null && scriptInstance.map.distance(lastNode) < distance;
    }
    
    public Position nextTile(Position path[], int skipDist) {
        int dist = -1, closest = -1;
        for (int i = path.length - 1; i >= 0; i--) {
            Position tile = path[i];
            int d = scriptInstance.map.distance(tile);
            if (d < dist || dist == -1) {
                dist = d;
                closest = i;
            }
        }
        
        int feasibleTileIndex = -1;
        
        for (int i = closest; i < path.length; i++) {
            if (scriptInstance.map.distance(path[i]) <= skipDist) {
                feasibleTileIndex = i;
            } else {
                break;
            }
        }

		return (feasibleTileIndex == -1) ? null : path[feasibleTileIndex];
    }
    
    public RS2Object getNextObstacle(Entity e) {
        List<RS2Object> obstacles = getObstacles();
        List<Position> path = generatePath(e);
        if (path == null) {
            return null;
        }
        
        for (RS2Object obj : obstacles) {
            for (Position pos : path) {
                if (obj.getPosition().equals(pos)) {
                    return obj;
                }
            }
        }
        return null;
    }
    
    public RS2Object getNextObstacle(Position p) {
        List<RS2Object> obstacles = getObstacles();
        List<Position> path = generatePath(p);
        if (path == null) {
            return null;
        }
        
        for (RS2Object obj : obstacles) {
            for (Position pos : path) {
                if (obj.getPosition().equals(pos)) {
                    return obj;
                }
            }
        }
        return null;
    }
    
    public List<RS2Object> getObstacles() {
        List<RS2Object> list = new LinkedList<>();
        for (RS2Object obj : scriptInstance.objects.getAll()) {
            if (obj.getType() == 0 && obj.getDefinition() != null && obj.getDefinition().getActions() != null && obj.getDefinition().getModelIds() != null && obj.getDefinition().getModelIds().length < 3) {
                search:
                {
                    for (String action : obj.getDefinition().getActions()) {
                        if (action != null && action.equalsIgnoreCase("open")) {
                            list.add(obj);
                            break search;
                        }
                    }
                }
            }
        }
        return list;
    }
    
    private List<Position> generatePath(Position p) {
		LocalPathFinder pf = new LocalPathFinder(scriptInstance.bot);
        int[][] flags = generateModifiedClippingData();
        List<Position> path = pf.findPath(p, flags);
        if (path == null) {
            return null;
        }
        return path;
    }
    
    private List<Position> generatePath(Entity e) {
		LocalPathFinder pf = new LocalPathFinder(scriptInstance.bot);
        int[][] flags = generateModifiedClippingData();
        List<Position> path = pf.findPath(e, flags);
        if (path == null) {
            return null;
        }
        return path;
    }
    
    private int[][] generateModifiedClippingData() {
        int[][] origFlags = scriptInstance.map.getRegion().getClippingPlanes()[scriptInstance.map.getPlane()].getTileFlags();
        int[][] flags = new int[origFlags.length][origFlags.length];
        for (int x = 0; x < flags.length; x++) {
            for (int y = 0; y < flags.length; y++) {
                flags[x][y] = origFlags[x][y];
            }
        }
        
        for (RS2Object obj : getObstacles()) {
            int lx = obj.getLocalX();
            int ly = obj.getLocalY();
            ObjectDefinition def = obj.getDefinition();
            if (def.isClipping1()) {
                switch (obj.getOrientation()) {
                    case 0:
                    case 2:
                        flags[lx][ly] &= ~585;
                        break;
                    case 1:
                    case 3:
                        flags[lx][ly] &= ~1170;
                        break;
                }
            }
            
            if (def.getClipping2() != 0) {
                if (0 == obj.getOrientation()) {
                    flags[lx][ly] &= ~128;
                    flags[lx - 1][ly] &= ~8;
                }
                
                if (1 == obj.getOrientation()) {
                    flags[lx][ly] &= ~2;
                    flags[lx][ly + 1] &= ~32;
                }
                
                if (2 == obj.getOrientation()) {
                    flags[lx][ly] &= ~8;
                    flags[lx + 1][ly] &= ~128;
                }
                
                if (3 == obj.getOrientation()) {
                    flags[lx][ly] &= ~32;
                    flags[lx][ly - 1] &= ~2;
                }
                
                if (def.isClipping3()) {
                    if (0 == obj.getOrientation()) {
                        flags[lx][ly] &= ~65536;
                        flags[lx - 1][ly] &= ~4096;
                    }
                    
                    if (obj.getOrientation() == 1) {
                        flags[lx][ly] &= ~1024;
                        flags[lx][ly + 1] &= ~16384;
                    }
                    
                    if (2 == obj.getOrientation()) {
                        flags[lx][ly] &= ~4096;
                        flags[lx + 1][ly] &= ~65536;
                    }
                    
                    if (3 == obj.getOrientation()) {
                        flags[lx][ly] &= ~16384;
                        flags[lx][ly - 1] &= ~1024;
                    }
                }
            }
        }
        return flags;
    }

    private boolean clickMiniMapPosition(Position position) throws InterruptedException {
	return scriptInstance.mouse.click(new RectangleDestination(scriptInstance.bot, new MiniMapTileDestination(scriptInstance.bot, position).getBoundingBox()));
    }
    
    public Position[] reversePath(Position[] path) {
        Position[] t = new Position[path.length];
        for (int i = 0; i < t.length; i++) {
            t[i] = path[path.length - i - 1];
        }
        return t;
    }
}

 

I'm new to scripting how would I implement this method?

Link to comment
Share on other sites

I'm new to scripting how would I implement this method?

 

Make a second class and name it Walker, then just copy and paste it. And im not 100% sure since I'm not to familiar with osbot scripting but you might need to do Walker rswalk = new Walker(and then if something goes in here you type it); don't quote me on that though.

Edited by twin 763
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...