Jump to content

Need help with walking a path


OneLuckyDuck

Recommended Posts

I know xD

 

Which method you use to walk ?

 

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);
		}
	}
Link to comment
Share on other sites

 

Not my greatest snippet tongue.png

	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);
		}
	}

 

Well thats very good :o

 

How do you walk to something without a path?

Because thats mainly my weak point ...

 

localwalker and map.walk are all bit glitchy and 90% of the time doesn't walk to something you want :s

 

any ideas?

Link to comment
Share on other sites

Well thats very good ohmy.png

 

How do you walk to something without a path?

Because thats mainly my weak point ...

 

localwalker and map.walk are all bit glitchy and 90% of the time doesn't walk to something you want :s

 

any ideas?

 

You'd have to write a pathfinding algorithm.

 

http://en.wikipedia.org/wiki/Pathfinding

 

Haven't ever needed a custom pathfinding method myself, but I might write on just for challenge of it ;D

Link to comment
Share on other sites

 

Not my greatest snippet tongue.png

	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);
		}
	}

 

 

It works as well as i need it to, thank you! :D

Link to comment
Share on other sites

Khaleesi, have you tried osbot pathFinder ? i use iy for walking when i only have one point

That only works for your current region (think it's like 72 tiles?).

 

You'd have to write a pathfinding algorithm.

 

http://en.wikipedia.org/wiki/Pathfinding

 

Haven't ever needed a custom pathfinding method myself, but I might write on just for challenge of it ;D

You also need map data.

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...