Not my greatest snippet :p
public static boolean traversePath(Script script, Position[] path, boolean reversed, int toggleRunOnAt, int toggleRunOffAt, boolean toggleRunOnInCombat, long timeout) throws InterruptedException {
Timer timer = new Timer();
while (!reversed ? script.map.distance(path[path.length - 1]) > 4 : script.map.distance(path[0]) > 4 && timer.getElapsed() < timeout) {
PathWalkMethods.runManager(script, toggleRunOnAt, toggleRunOffAt, toggleRunOnInCombat);
Position bestPosition = null;
int attempts = 0;
if (!reversed) {
for (int i = 1; i < path.length; i++) {
if (script.map.canReach(path[i])) {
MiniMapTileDestination mmtd = new MiniMapTileDestination(script.bot, path[i]);// TODO
if (mmtd != null && mmtd.isVisible()) {
bestPosition = path[i];
}
}
}
} else {
for (int i = path.length - 1; i > 0; i--) {
if (script.map.canReach(path[i])) {
MiniMapTileDestination mmtd = new MiniMapTileDestination(script.bot, path[i]);// TODO
if (mmtd != null && mmtd.isVisible()) {
bestPosition = path[i];
}
}
}
}
if (bestPosition != null) {
script.mouse.click(new MiniMapTileDestination(script.bot, bestPosition));
int failsafe = 0;
while (failsafe < 10 && script.myPlayer().getPosition().distance(bestPosition) > 2) {
MethodProvider.sleep(600);
failsafe++;
if (script.myPlayer().isMoving()) {
failsafe = 0;
}
}
return true;
}
else {
attempts++;
if (attempts > 5) {
return false;
}
script.camera.moveYaw(script.camera.getYawAngle() + MethodProvider.random(60,80));
}
}
return true;
}
public static void runManager(Script script, int toggleRunOnAt, int toggleRunOffAt, boolean toggleRunOnInCombat) {
if (script.settings.getRunEnergy() >= toggleRunOnAt || (toggleRunOnInCombat ? script.settings.getRunEnergy() > 0 && script.myPlayer().isUnderAttack() : false)) {
script.settings.setRunning(true);
}
if (script.settings.getRunEnergy() <= toggleRunOffAt && (toggleRunOnInCombat ? !script.myPlayer().isUnderAttack() : true)) {
script.settings.setRunning(false);
}
}