TheManWhoLicks Posted November 1, 2024 Share Posted November 1, 2024 Alright i need some help fellas. My walking file seems to be very inconsistent. webWalk usually does not work that well for example. Anyone see what I'm doing wrong? import org.osbot.rs07.api.map.Position; import org.osbot.rs07.api.map.Area; import java.util.List; import org.osbot.rs07.script.MethodProvider; public class MasterWalker extends MethodProvider { private static final int WEB_WALK_TIMEOUT = 5000; // Increased timeout for longer paths private static final int INTERACT_DISTANCE_THRESHOLD = 10; // Proximity threshold for target position private static final int MAX_REGULAR_WALK_ATTEMPTS = 3; // Max attempts for regular walking before using webWalk private static final int STEP_DIVISION_UNIT = 5; // Smaller step distances for finer control // Overloaded walkTo method that accepts a list of waypoints public boolean walkTo(Position destination, List<Position> waypoints, CheckInterrupt interrupt) throws InterruptedException { // Check if the player is already at the destination if (myPosition().equals(destination)) { log("Player is already at the destination: " + destination); return true; } for (Position waypoint : waypoints) { if (divideAndWalk(waypoint, interrupt)) { if (getWalking().webWalk(destination)) { return true; } } } log("Fallback to direct webWalk to final destination."); return webWalkWithTimeout(destination); // Fallback if waypoints don’t work } public boolean walkTo(Object destination, CheckInterrupt interrupt) throws InterruptedException { checkRunEnergy(); if (destination instanceof Position) { Position position = (Position) destination; // Check if the player is already at the position if (myPosition().equals(position)) { log("Player is already at the target position: " + position); return true; } if (canReach(position)) { log("Position is reachable via regular walk."); return divideAndWalk(position, interrupt); } else { log("Position appears unreachable via regular walk, attempting web walk as fallback."); return webWalkWithTimeout(position); } } else if (destination instanceof Area) { Area area = (Area) destination; // Check if the player is already within the area if (area.contains(myPosition())) { log("Player is already within the target area: " + area); return true; } Position randomPosition = area.getRandomPosition(); if (canReach(randomPosition)) { log("Area is reachable via regular walk."); return divideAndWalk(randomPosition, interrupt); } else { log("Area appears unreachable via regular walk, attempting web walk as fallback."); return webWalkWithTimeout(randomPosition); } } else if (destination instanceof List) { return handlePath((List<Position>) destination, interrupt); } return false; // Invalid input } private boolean divideAndWalk(Position target, CheckInterrupt interrupt) throws InterruptedException { double distance = myPosition().distance(target); int steps = (int) Math.ceil(distance / STEP_DIVISION_UNIT); log("Calculated steps to target: " + steps); Position currentPosition = myPosition(); for (int i = 0; i < steps; i++) { checkRunEnergy(); if (interrupt.shouldInterrupt()) { log("Interrupt condition met; stopping walk."); return false; } Position stepTarget = getIntermediatePosition(currentPosition, target, STEP_DIVISION_UNIT); log("Attempting regular walk to intermediate point: " + stepTarget); if (!walkToPosition(stepTarget)) { log("Failed to reach intermediate point: " + stepTarget); return false; } currentPosition = stepTarget; waitUntilStopped(3000); } log("Successfully divided and reached target position: " + target); return true; } private Position getIntermediatePosition(Position from, Position to, int stepDistance) { double distance = from.distance(to); double ratio = stepDistance / distance; int x = (int) (from.getX() + (to.getX() - from.getX()) * ratio); int y = (int) (from.getY() + (to.getY() - from.getY()) * ratio); return new Position(x, y, from.getZ()); } private boolean walkToPosition(Position position) throws InterruptedException { checkRunEnergy(); log("Attempting regular walk to: " + position); if (getWalking().walk(position)) { customSleep(5000); return true; } log("Regular walking to " + position + " failed."); return false; } private boolean webWalkWithTimeout(Position position) throws InterruptedException { long startTime = System.currentTimeMillis(); log("Attempting webWalk to position: " + position); while (System.currentTimeMillis() - startTime < WEB_WALK_TIMEOUT) { if (getWalking().webWalk(position)) { customSleep(10000); return true; } log("Attempting to reach position: " + position + " - Time elapsed: " + (System.currentTimeMillis() - startTime) + "ms"); sleep(200); } log("Web walk to position timed out after " + WEB_WALK_TIMEOUT + "ms."); return false; } private void checkRunEnergy() { if (!getSettings().isRunning() && getSettings().getRunEnergy() > 15) { getSettings().setRunning(true); log("Run energy above 15%; enabling run mode."); } } private void waitUntilStopped(int timeout) throws InterruptedException { int timeWaited = 0; while (myPlayer().isMoving() && timeWaited < timeout) { sleep(100); timeWaited += 100; } } // Utility method to simulate custom sleep private void customSleep(int timeout) throws InterruptedException { int timeWaited = 0; while (myPlayer().isMoving() && timeWaited < timeout) { sleep(100); timeWaited += 100; } } private boolean handlePath(List<Position> path, CheckInterrupt interrupt) throws InterruptedException { for (Position position : path) { checkRunEnergy(); if (interrupt.shouldInterrupt()) { log("Interrupt condition met; stopping path."); return false; } if (!walkToPosition(position)) { log("Failed to walk to position in path: " + position); return false; } waitUntilStopped(3000); } return true; } public interface CheckInterrupt { boolean shouldInterrupt(); } private boolean canReach(Position position) { return getMap().canReach(position); } private boolean canReach(Area area) { for (Position pos : area.getPositions()) { if (getMap().canReach(pos)) { return true; } } return false; } } Quote Link to comment Share on other sites More sharing options...
Khaleesi Posted November 1, 2024 Share Posted November 1, 2024 Hard to tell by reading the code, but seems quiet the overkill as most of it is already done by the API you can simply make WalkingEvent and webWalkEvent and set all of these settings you need https://osbot.org/api/org/osbot/rs07/event/WalkingEvent.html For WebwalkEvent you can even create a PathPreference profile to determine what telewports to use etc. https://osbot.org/api/org/osbot/rs07/event/WebWalkEvent.html 1 Quote Link to comment Share on other sites More sharing options...
dubai Posted November 2, 2024 Share Posted November 2, 2024 What is going wrong exactly? I made a similar one a while ago that still works today: Spoiler package scripts; import org.osbot.rs07.api.map.Area; import org.osbot.rs07.script.Script; import org.osbot.rs07.script.ScriptManifest; import javax.swing.*; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.HashMap; import java.util.Map; @ScriptManifest(name = "Walker", author = "Dubai", version = 0.3, info = "common locations", logo = "") public class Walker extends Script { private Map<String, Area> locations; private Area selectedLocation; @Override public void onStart() { // Initialize common locations locations = new HashMap<>(); locations.put("Grand Exchange", new Area(3164, 3485, 3168, 3489)); locations.put("Varrock Bank", new Area(3180, 3445, 3185, 3433)); locations.put("Lumbridge Castle", new Area(3210, 3216, 3214, 3220)); locations.put("Fally East Bank", new Area(3009, 3355, 3017, 3358));; locations.put("Fally SW Cows", new Area(3022, 3298, 3042, 3312)); // Show RockCrabsGUI to select location SwingUtilities.invokeLater(this::showGUI); } private void showGUI() { JFrame frame = new JFrame("Select Location"); frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); frame.setSize(300, 150); JComboBox<String> locationComboBox = new JComboBox<>(locations.keySet().toArray(new String[0])); JButton startButton = new JButton("Start"); startButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { String selected = (String) locationComboBox.getSelectedItem(); selectedLocation = locations.get(selected); frame.dispose(); } }); frame.setLayout(new FlowLayout()); frame.add(new JLabel("Select a location:")); frame.add(locationComboBox); frame.add(startButton); frame.setVisible(true); } @Override public void onExit() { log("Stopping walk wherever script..."); } @Override public int onLoop() { if (selectedLocation != null) { getWalking().webWalk(selectedLocation); selectedLocation = null; // Reset after walking to the location } return 100; // The amount of time in milliseconds before the loop starts over } @Override public void onPaint(Graphics2D g) { g.drawString("Walk Wherever", 10, 40); } } Quote Link to comment Share on other sites More sharing options...
TheManWhoLicks Posted November 3, 2024 Author Share Posted November 3, 2024 Dang, I didn't realize all of that was handled. You're 100% right. I simplied it all down and no longer am having trouble walking. Thanks!!! Quote Link to comment Share on other sites More sharing options...
dubai Posted November 8, 2024 Share Posted November 8, 2024 Webwalk is actually overpowered as f. Definitely a lot of time taken to make it this good you can tell. Quote Link to comment Share on other sites More sharing options...