zasz Posted October 12, 2019 Share Posted October 12, 2019 I did this years ago and tweaked a bit for OSBot, some still has RS3 information, but how does the walking look public class Navigation { public static Script ourBot; public Navigation(Script scriptInstance) { ourBot = scriptInstance; } public enum Lodes { Lumbridge(17); private int id; public int getInterfaceID(){ return id; } Lodes(int interfaceid) { id = interfaceid; } } final static int lodestoneInt = 1092; final static int homeTelePortInterface = 1465; static final int UNWALKABLE = 256 | 0x200000 | 0x40000; public static boolean isWalkable(int flag) { return (flag & (UNWALKABLE)) == 0; } //static NavPath nullNav = new NavPath(); public boolean posReach(Collection<Position> reachableCords, Position t){ Collection<Position> p = reachableCords; for (Position c : p) { //if(t.getX()==c.getX() && t.getY()==c.getY()){ //debug("Can reach: "+t); // return t.isReachable(); //} if(c.equals(t)) return true; } return false; } public boolean stepTowardsPoint(Player local, Position point, boolean forceSteps){ XClippingPlane[] clippingPlanes = ourBot.client.accessor.getClippingPlanes(); int[][] map = clippingPlanes[ourBot.myPlayer().getZ()].getTileFlags(); ourBot.client.accessor.getCurrentRegion().getTiles().toString(); ArrayList<Position> reachablePositions = new ArrayList<Position>(); ArrayList<Position> allTiles = new ArrayList<Position>(); int localX = local.getPosition().getLocalX(ourBot.bot); int localY = local.getPosition().getLocalY(ourBot.bot); for(int i = 0; i < map.length;i++){ for(int j = 0; j < map[i].length; j++){ if((i>(localX-20) && i<(localX+20)) && (j>(localY-20) && j<(localY+20))) if(isWalkable(map[i][j])) reachablePositions.add(new Position(i,j,ourBot.myPlayer().getZ())); } } if(reachablePositions.size()>0) { for(int x=-20;x<20;x++) { for(int y=-20;y<20;y++) { Position tPos = new Position(local.getX()+x,local.getY()+y,ourBot.myPlayer().getZ()); if(tPos.isOnMiniMap(ourBot.bot)) { if(reachablePositions.size()>0) { localX = tPos.getLocalX(ourBot.bot); localY = tPos.getLocalY(ourBot.bot); Position tLocalG = new Position(localX,localY,0); if(reachablePositions.contains(tLocalG)) allTiles.add(tPos); } } } } } reachablePositions = allTiles; ourBot.log(allTiles.toString()); int z = 2; if(z==1) return false; Position bestTile = null; if(posReach(reachablePositions, point)){ double bestDist = 999; for(Position coord : reachablePositions){ if(!coord.equals(point)) coord = coord.translate(Script.random(-2,2), Script.random(-2,2)); //This adds differences int tempDist = (int) coord.distance(point); if(coord.distance(point)<=bestDist){ boolean isOnMap = coord.isOnMiniMap(ourBot.bot); if(isOnMap){ bestTile = coord; bestDist = tempDist; } } } } else if(forceSteps){ //Force double bestDist = 999; for(Position coord : reachablePositions){ coord = coord.translate(Script.random(-2,2), Script.random(-2,2)); int tempDist = (int) coord.distance(point); if(coord.distance(point)<=bestDist){ boolean isOnMap = coord.isOnMiniMap(ourBot.bot); if(isOnMap){ bestTile = coord; bestDist = tempDist; } } } } if(bestTile != null){ return ourBot.map.walking.walk(bestTile) && Sleep.sleepUntil(() -> (!local.isMoving()), 2000); } return false; } Quote Link to comment Share on other sites More sharing options...
BravoTaco Posted October 13, 2019 Share Posted October 13, 2019 2 hours ago, zasz said: I did this years ago and tweaked a bit for OSBot, some still has RS3 information, but how does the walking look public class Navigation { public static Script ourBot; public Navigation(Script scriptInstance) { ourBot = scriptInstance; } public enum Lodes { Lumbridge(17); private int id; public int getInterfaceID(){ return id; } Lodes(int interfaceid) { id = interfaceid; } } final static int lodestoneInt = 1092; final static int homeTelePortInterface = 1465; static final int UNWALKABLE = 256 | 0x200000 | 0x40000; public static boolean isWalkable(int flag) { return (flag & (UNWALKABLE)) == 0; } //static NavPath nullNav = new NavPath(); public boolean posReach(Collection<Position> reachableCords, Position t){ Collection<Position> p = reachableCords; for (Position c : p) { //if(t.getX()==c.getX() && t.getY()==c.getY()){ //debug("Can reach: "+t); // return t.isReachable(); //} if(c.equals(t)) return true; } return false; } public boolean stepTowardsPoint(Player local, Position point, boolean forceSteps){ XClippingPlane[] clippingPlanes = ourBot.client.accessor.getClippingPlanes(); int[][] map = clippingPlanes[ourBot.myPlayer().getZ()].getTileFlags(); ourBot.client.accessor.getCurrentRegion().getTiles().toString(); ArrayList<Position> reachablePositions = new ArrayList<Position>(); ArrayList<Position> allTiles = new ArrayList<Position>(); int localX = local.getPosition().getLocalX(ourBot.bot); int localY = local.getPosition().getLocalY(ourBot.bot); for(int i = 0; i < map.length;i++){ for(int j = 0; j < map[i].length; j++){ if((i>(localX-20) && i<(localX+20)) && (j>(localY-20) && j<(localY+20))) if(isWalkable(map[i][j])) reachablePositions.add(new Position(i,j,ourBot.myPlayer().getZ())); } } if(reachablePositions.size()>0) { for(int x=-20;x<20;x++) { for(int y=-20;y<20;y++) { Position tPos = new Position(local.getX()+x,local.getY()+y,ourBot.myPlayer().getZ()); if(tPos.isOnMiniMap(ourBot.bot)) { if(reachablePositions.size()>0) { localX = tPos.getLocalX(ourBot.bot); localY = tPos.getLocalY(ourBot.bot); Position tLocalG = new Position(localX,localY,0); if(reachablePositions.contains(tLocalG)) allTiles.add(tPos); } } } } } reachablePositions = allTiles; ourBot.log(allTiles.toString()); int z = 2; if(z==1) return false; Position bestTile = null; if(posReach(reachablePositions, point)){ double bestDist = 999; for(Position coord : reachablePositions){ if(!coord.equals(point)) coord = coord.translate(Script.random(-2,2), Script.random(-2,2)); //This adds differences int tempDist = (int) coord.distance(point); if(coord.distance(point)<=bestDist){ boolean isOnMap = coord.isOnMiniMap(ourBot.bot); if(isOnMap){ bestTile = coord; bestDist = tempDist; } } } } else if(forceSteps){ //Force double bestDist = 999; for(Position coord : reachablePositions){ coord = coord.translate(Script.random(-2,2), Script.random(-2,2)); int tempDist = (int) coord.distance(point); if(coord.distance(point)<=bestDist){ boolean isOnMap = coord.isOnMiniMap(ourBot.bot); if(isOnMap){ bestTile = coord; bestDist = tempDist; } } } } if(bestTile != null){ return ourBot.map.walking.walk(bestTile) && Sleep.sleepUntil(() -> (!local.isMoving()), 2000); } return false; } Just a couple of things that I noticed are: Redundant Cast: Spoiler int tempDist = (int) coord.distance(point); Using the method distance already returns an int I think? Type Arguments That Are Not Needed Spoiler ArrayList<Position> reachablePositions = new ArrayList<Position>(); ArrayList<Position> allTiles = new ArrayList<Position>(); You don't need that second type argument in their. Ex. ArrayList<Position> allTiles = new ArrayList<>(); If Statement Always Returns False? Spoiler int z = 2; if (z == 1) return false; I Think, this will always return false sense you are manually setting z == 2 right before calling the if statement. So the statement will never run. Also maybe try and break it up into separate methods for easier debugging and readability. Quote Link to comment Share on other sites More sharing options...
zasz Posted October 13, 2019 Author Share Posted October 13, 2019 4 hours ago, BravoTaco said: Just a couple of things that I noticed are: Redundant Cast: Reveal hidden contents int tempDist = (int) coord.distance(point); Using the method distance already returns an int I think? Type Arguments That Are Not Needed Reveal hidden contents ArrayList<Position> reachablePositions = new ArrayList<Position>(); ArrayList<Position> allTiles = new ArrayList<Position>(); You don't need that second type argument in their. Ex. ArrayList<Position> allTiles = new ArrayList<>(); If Statement Always Returns False? Hide contents int z = 2; if (z == 1) return false; I Think, this will always return false sense you are manually setting z == 2 right before calling the if statement. So the statement will never run. Also maybe try and break it up into separate methods for easier debugging and readability. Appreciate the time, the last one was just for debug to stop at that point. fixed the cast, originally the other bot i created for distance returned a double. Also, fixed the type, i couldve swore at some point in the long past, not doing the argument compiled with a warning. Quote Link to comment Share on other sites More sharing options...