Mr Asshole Posted November 27, 2013 Share Posted November 27, 2013 (edited) 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 November 27, 2013 by Mr Asshole Link to comment Share on other sites More sharing options...
GoldenGates Posted November 27, 2013 Share Posted November 27, 2013 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. Link to comment Share on other sites More sharing options...
Mr Asshole Posted November 27, 2013 Author Share Posted November 27, 2013 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. Link to comment Share on other sites More sharing options...
Toph Posted November 28, 2013 Share Posted November 28, 2013 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. Link to comment Share on other sites More sharing options...
GoldenGates Posted November 28, 2013 Share Posted November 28, 2013 I fixed up Cory's to make it more adjustable. Link to comment Share on other sites More sharing options...
Mr Asshole Posted November 28, 2013 Author Share Posted November 28, 2013 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. Link to comment Share on other sites More sharing options...
lolmanden Posted November 30, 2013 Share Posted November 30, 2013 Thanks for the snippet. Link to comment Share on other sites More sharing options...
fvpredator9 Posted December 3, 2013 Share Posted December 3, 2013 hey i am using your script and i get a error on startTime = System.currentTimeMillis(); do u know why? Link to comment Share on other sites More sharing options...
fvpredator9 Posted December 3, 2013 Share Posted December 3, 2013 (edited) whoops it posted 2 times Edited December 3, 2013 by fvpredator9 Link to comment Share on other sites More sharing options...
Omoshu Posted December 3, 2013 Share Posted December 3, 2013 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. Link to comment Share on other sites More sharing options...
fvpredator9 Posted December 3, 2013 Share Posted December 3, 2013 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? Link to comment Share on other sites More sharing options...
Toph Posted December 3, 2013 Share Posted December 3, 2013 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. 1 Link to comment Share on other sites More sharing options...
Mr Asshole Posted December 3, 2013 Author Share Posted December 3, 2013 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. Link to comment Share on other sites More sharing options...
Program Posted December 3, 2013 Share Posted December 3, 2013 I get an error when I try to add this to my code can you help me Mr Asshole? Link to comment Share on other sites More sharing options...
fvpredator9 Posted December 3, 2013 Share Posted December 3, 2013 Can someone who know how to use this script help me with it please. Xfire/Steam/Skype:FVPredator9 Link to comment Share on other sites More sharing options...