Pug Posted June 29, 2014 Share Posted June 29, 2014 (edited) needed this and @Pandemic was kind enough to donate his. So in the interest of the community and for new scriptwriters to learn the art of walking in there script which is pretty pivotal im posting an example here so everyone can use it in the future of OSB2. feel free to post improvements. import org.osbot.rs07.api.map.Position; import org.osbot.rs07.api.util.LocalPathFinder; import org.osbot.rs07.input.mouse.MiniMapTileDestination; import org.osbot.rs07.script.Script; import org.osbot.rs07.script.ScriptManifest; import org.osbot.rs07.utility.Area; @ScriptManifest(name="name", author="author", info="info", logo="", version=0.1D) public final class walker extends Script { // area declarations private static final Area vWestBank = new Area(3186, 3433, 3180, 3437); private static final Area vEastBank = new Area(3256,3420,3250,3423); // walking path ( walks from varrock west to varrock east bank private final Position[] pathToWalk = { new Position(3182, 3436,0), new Position(3189, 3430,0), new Position(3200, 3429,0), new Position(3211, 3428,0), new Position(3223, 3429,0), new Position(3233, 3430,0), new Position(3244, 3429,0), new Position(3254, 3428,0), new Position(3254, 3420,0) }; @Override public int onLoop() throws InterruptedException { if(!vEastBank.contains(myPlayer())) { log("not in east bank, walking"); walkPath(pathToWalk); } if(vEastBank.contains(myPlayer())) { log("made it!"); stop(); } return 300; } //walking methods public void walkPath(Position[] path) throws InterruptedException { for (Position p : path) { if (myPosition().distance(p) > 16 || myPosition().distance(p) < 3) continue; boolean success; do { success = walkTile(p); } while (!success); } } public boolean walkTile(Position p) throws InterruptedException { if (myPosition().distance(p) > 13) { Position pos = new Position(((p.getX() + myPosition().getX()) / 2) + random(-3, 3), ((p.getY() + myPosition().getY()) / 2) + random(-3, 3), myPosition().getZ()); walkTile(pos); } mouse.click(new MiniMapTileDestination(bot, p), false); int fail = 0; while (myPosition().distance(p) > 2 && fail < 10) { sleep(500); if (!myPlayer().isMoving()) fail++; } return fail != 10; } } Edited June 29, 2014 by Pug Link to comment Share on other sites More sharing options...
Mysteryy Posted June 30, 2014 Share Posted June 30, 2014 It will get the job done. I am not a fan of using while loops in scripts, you should add a timeout so that if the loop runs for more than x seconds it will stop. ^_^ 1 Link to comment Share on other sites More sharing options...
Mr def nerd Posted June 30, 2014 Share Posted June 30, 2014 Personally I just use this if I am walking any normal paths without any obstacles:The walk method is simply walking a MinimapTileDestination. The code simply finds the best tile (It requires that the destination is at the end of the array, you can always reverse it yourself ), then if it manages to click the tile and the destination is somewhat close to the tile you wanted to walk, it will sleep until you are 5 tiles away from it (You can always randomize it) public boolean walkPath(Position[] path) { for (int i = path.length - 1; i >= 0; i--) { final Position pos = path[i]; if (pos != null && pos.distance(ctx.myPosition()) <= 16 && ctx.getMap().canReach(pos)) { if (walk(pos) && ctx.getMap().getDestination().distance(pos) <= 2) { ctx.sleep(new Condition() { @Override public boolean evaluate() { return pos.distance(ctx.myPosition()) > 5; } }, 3500); return true; } else { return false; } } } return false; } You would also need some sort of conditional sleeping method for this to work. You can also create a new instance of the LocalPathFinder which will allow you to generate a path between two points using A* (I am pretty sure its using A*) Link to comment Share on other sites More sharing options...
OneLuckyDuck Posted June 30, 2014 Share Posted June 30, 2014 Personally I just use this if I am walking any normal paths without any obstacles: The walk method is simply walking a MinimapTileDestination. The code simply finds the best tile (It requires that the destination is at the end of the array, you can always reverse it yourself ), then if it manages to click the tile and the destination is somewhat close to the tile you wanted to walk, it will sleep until you are 5 tiles away from it (You can always randomize it) public boolean walkPath(Position[] path) { for (int i = path.length - 1; i >= 0; i--) { final Position pos = path[i]; if (pos != null && pos.distance(ctx.myPosition()) <= 16 && ctx.getMap().canReach(pos)) { if (walk(pos) && ctx.getMap().getDestination().distance(pos) <= 2) { ctx.sleep(new Condition() { @Override public boolean evaluate() { return pos.distance(ctx.myPosition()) > 5; } }, 3500); return true; } else { return false; } } } return false; } You would also need some sort of conditional sleeping method for this to work. You can also create a new instance of the LocalPathFinder which will allow you to generate a path between two points using A* (I am pretty sure its using A*) LocalPathFinder throws a NPE and crashes my script. Link to comment Share on other sites More sharing options...
Mr def nerd Posted June 30, 2014 Share Posted June 30, 2014 LocalPathFinder throws a NPE and crashes my script. You have to create a new instance of it with bot as a parameter Link to comment Share on other sites More sharing options...
OneLuckyDuck Posted June 30, 2014 Share Posted June 30, 2014 You have to create a new instance of it with bot as a parameter Yeah i know, let me see if i can reproduce the crash under more controlled parameters. Link to comment Share on other sites More sharing options...
Pug Posted June 30, 2014 Author Share Posted June 30, 2014 thanks for the responses guys! all good comments, i want to see lots of free scripts getting put out and re-build this community for the wide range of scripts we had in OSBot1. Link to comment Share on other sites More sharing options...
Khaleesi Posted June 30, 2014 Share Posted June 30, 2014 (edited) It will get the job done. I am not a fan of using while loops in scripts, you should add a timeout so that if the loop runs for more than x seconds it will stop. Exactly what I said on another topic, then got flamed ... xD Looks like a great snippet Edited June 30, 2014 by Khaleesi Link to comment Share on other sites More sharing options...
Apaec Posted June 30, 2014 Share Posted June 30, 2014 For those of u using this pathwalking and experience obstacles, to handle doors you would use this snippet to walk to the obstacle in mind (albeit a door or gate or w/ever), then you would check if the door is open (for example check its actions for a specific action eg check if the doors right click contains 'open' and that way you know it's closed. You would then, if the door is closed, interact open with the door and proceed to commence your next path. Link to comment Share on other sites More sharing options...
Precise Posted June 30, 2014 Share Posted June 30, 2014 For those of u using this pathwalking and experience obstacles, to handle doors you would use this snippet to walk to the obstacle in mind (albeit a door or gate or w/ever), then you would check if the door is open (for example check its actions for a specific action eg check if the doors right click contains 'open' and that way you know it's closed. You would then, if the door is closed, interact open with the door and proceed to commence your next path. that would work, but what if the door closes behind you? you would be spamming the door. but that can be easily fixed ^_^ Link to comment Share on other sites More sharing options...
Apaec Posted June 30, 2014 Share Posted June 30, 2014 that would work, but what if the door closes behind you? you would be spamming the door. but that can be easily fixed That's for them to work out 1 Link to comment Share on other sites More sharing options...
Swizzbeat Posted July 1, 2014 Share Posted July 1, 2014 Meh it's nice but kind of useless if it cannot handle obstacles Link to comment Share on other sites More sharing options...
Pug Posted July 1, 2014 Author Share Posted July 1, 2014 Meh it's nice but kind of useless if it cannot handle obstacles if useless means then it cant be used to walk from A to B across 50% of runescape without encountering an obstacle then yes you are right lol. 99% of my scripts need this. It can also be adapted very easily to handle any obstacle when in range. But for those just starting out with a script that needs to make it walk, its just the job ;) 1 Link to comment Share on other sites More sharing options...
Th3 Posted July 1, 2014 Share Posted July 1, 2014 that would work, but what if the door closes behind you? you would be spamming the door. but that can be easily fixed To tackle this you use a pathfinder, clear the obstacle flags, and check to see if next position on the path is reachable. That's how mine does it. 1 Link to comment Share on other sites More sharing options...