Swizzbeat Posted July 4, 2014 Share Posted July 4, 2014 (edited) Pretty basic, all credits to @Maxi who designed pretty much the whole thing while I updated a few core components. 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 July 4, 2014 by Swizzbeat 1 Link to comment Share on other sites More sharing options...
Khaleesi Posted July 4, 2014 Share Posted July 4, 2014 Thats a lot of code to handle an obstacle xDWell done ^^ 1 Link to comment Share on other sites More sharing options...
Joseph Posted July 4, 2014 Share Posted July 4, 2014 http://osbot.org/forum/topic/13575-walking-class-doorgate-handler/ Link to comment Share on other sites More sharing options...
NotoriousPP Posted July 4, 2014 Share Posted July 4, 2014 http://osbot.org/forum/topic/13575-walking-class-doorgate-handler/ This is a well known snippet, he was just sharing updated for OSBot2... 1 Link to comment Share on other sites More sharing options...
Joseph Posted July 4, 2014 Share Posted July 4, 2014 This is a well known snippet, he was just sharing updated for OSBot2... i know, i was actually trying to do that. But he beat me to the punch Link to comment Share on other sites More sharing options...
Swizzbeat Posted July 4, 2014 Author Share Posted July 4, 2014 i know, i was actually trying to do that. But he beat me to the punch Lol you should see my walker with multiplane handling as well as @NotoriousPP's sexy blindwalking addition ;) 2 Link to comment Share on other sites More sharing options...
Pug Posted July 4, 2014 Share Posted July 4, 2014 love how i post the initial idea and then the blue pixels come along and re-do it. lol. Maybe i should post more basic concepts for OSB2 and then we might actually get back to somewhere close of a decent community of free scripts. Link to comment Share on other sites More sharing options...
NotoriousPP Posted July 4, 2014 Share Posted July 4, 2014 love how i post the initial idea and then the blue pixels come along and re-do it. lol. Maybe i should post more basic concepts for OSB2 and then we might actually get back to somewhere close of a decent community of free scripts. Well Pug remember that walking snippet that Swizz posted has been public since before I started writing bots, it's honestly the same base I have been using in all of my walking since the beginning of my career at OSBot. It wasn't anything new. Link to comment Share on other sites More sharing options...
Khaleesi Posted July 4, 2014 Share Posted July 4, 2014 Lol you should see my walker with multiplane handling as well as @NotoriousPP's sexy blindwalking addition In my and Precise's walker you can even input Actions to interact with ladder to go up or down xD Also multiplanar and handles all obstacles ^^ Can we know stop acitng like kids who always compete over pointless stuff ... -_- Khaleesi 2 Link to comment Share on other sites More sharing options...
Joseph Posted July 4, 2014 Share Posted July 4, 2014 love how i post the initial idea and then the blue pixels come along and re-do it. lol. Maybe i should post more basic concepts for OSB2 and then we might actually get back to somewhere close of a decent community of free scripts. do it pussy but really they came to help the community. I also created my own walker because i wanted something that could use path finder, rather then having to make my own path. The when i stated i couldn't create a obstacle handler. They help out by giving out a snippet so..... 1 Link to comment Share on other sites More sharing options...
Swizzbeat Posted July 4, 2014 Author Share Posted July 4, 2014 do it pussy but really they came to help the community. I also created my own walker because i wanted something that could use path finder, rather then having to make my own path. The when i stated i couldn't create a obstacle handler. They help out by giving out a snippet so..... love how i post the initial idea and then the blue pixels come along and re-do it. lol. Maybe i should post more basic concepts for OSB2 and then we might actually get back to somewhere close of a decent community of free scripts. Read the above quote. I saw asking about clipping data so I posted a snippet I had but then figured I mine as well post the whole walker. In my and Precise's walker you can even input Actions to interact with ladder to go up or down xD Also multiplanar and handles all obstacles ^^ Can we know stop acitng like kids who always compete over pointless stuff ... Khaleesi Guarantee mines better. 1 Link to comment Share on other sites More sharing options...
Pug Posted July 4, 2014 Share Posted July 4, 2014 Well Pug remember that walking snippet that Swizz posted has been public since before I started writing bots, it's honestly the same base I have been using in all of my walking since the beginning of my career at OSBot. It wasn't anything new. my point wasnt related to the code. It was pointed squarely at the fact that nothing on walking for OSB2 existed for new members until i posted it the other day but then all of a sudden after there which two new threads were made on the same subject, nothing against Swizz or Jose of course nice work guys. I just wish we all posted more open content that others can use in the future to make basic scripts for the new client. When i first joined there was a swath of content to learn from. It seems with OSB2 scriptwriters are trying to keep things they know private so others struggle or even start to learn and they then make more money. (The incident in the scriptwriters section the other day was a perfect example.) A community based around a profit will die sooner rather than later and just lately the taste around here is becoming rather sour, and i for one don't like it. said my bit, now guna fade back into the black. 3 Link to comment Share on other sites More sharing options...
Joseph Posted July 5, 2014 Share Posted July 5, 2014 (edited) private boolean clickMiniMapPosition(Position position) throws InterruptedException { return scriptInstance.mouse.click(new RectangleDestination(scriptInstance.bot, new MiniMapTileDestination(scriptInstance.bot, position).getBoundingBox())); } could be shorten to this: private boolean clickMiniMapPosition(Position position) throws InterruptedException { return scriptInstance.mouse.click(new MiniMapTileDestination(script.bot, position)); } Edited July 5, 2014 by josedpay Link to comment Share on other sites More sharing options...
Pseudo Posted July 5, 2014 Share Posted July 5, 2014 The posts on this thread are giving me cancer. 2 Link to comment Share on other sites More sharing options...
Swizzbeat Posted July 5, 2014 Author Share Posted July 5, 2014 could be shorten to this: private boolean clickMiniMapPosition(Position position) throws InterruptedException { return scriptInstance.mouse.click(new MiniMapTileDestination(script.bot, position)); } Dunno I just put that there so I wouldn't have to release my own walking method :p The posts on this thread are giving me cancer. hai corey with an e 1 Link to comment Share on other sites More sharing options...