lare96 Posted May 2, 2015 Share Posted May 2, 2015 /** * Returns an array of {@link org.osbot.rs07.api.map.Position} nodes that * are randomized within {@code radius}. The {@code path} will not be * modified, nor will it hold any references to the returned array. * * @param path * the path that will be randomized. * @param radius * the radius in which the path will be randomized. * @return the new randomized path. */ public static Position[] getRandomizedPath(Position[] path, int radius) { Position[] newPath = new Position[path.length]; int idx = 0; for (Position node : path) newPath[idx++] = node.translate(MethodProvider.random(radius), MethodProvider.random(radius)); return newPath; } /** * Returns an array of {@link org.osbot.rs07.api.map.Position} nodes that * are localized for the {@code node} point. This method is very useful for * when the script needs to cut out certain positions that aren't relevant; * for example, if the player starts a script when they are in the middle of * a path instead of the beginning or ending. Take for instance, this * pseudo-code. * * <pre> * Position[] path = { position1, position2, position3, position4, position5, position6, position7 }; * </pre> * * If {@code node} is closest to "position3" in distance, the returned array * will look like... * * <pre> * ... = { position3, position4, position5, position6, position7 }; * </pre> * * @param node * the node in which the path should be localized for. * @param path * the path that will be localized. * @return the new localized path. */ public static Position[] getLocalPath(Position node, Position[] path) { List<Position> newPath = new LinkedList<>(); int dist = -1; int index = -1; for (int i = 0; i < path.length; i++) { int newDist = node.distance(path[i]); if (dist == -1 || newDist < dist) { dist = newDist; index = i; } } IntStream.range(index, path.length).forEach(x -> newPath.add(path[x])); return newPath.toArray(new Position[newPath.size()]); } Could come in handy for scripts that utilize walking, everything is explained in the documentation. Quote Link to comment Share on other sites More sharing options...
Khaleesi Posted May 2, 2015 Share Posted May 2, 2015 and this is how I want the osbot docs to be made. A decent explanation of what the function actually does Thx for your contribution! Quote Link to comment Share on other sites More sharing options...
lare96 Posted May 8, 2015 Author Share Posted May 8, 2015 and this is how I want the osbot docs to be made. A decent explanation of what the function actually does Thx for your contribution! Thanks man, I appreciate it. Quote Link to comment Share on other sites More sharing options...