GhostData 6 Posted August 27, 2022 I wrote a tile walker for one of my scripts and i am having an issue with it. The way it works is based on @420x69x420 Tile Walker but instead of iterating all at once it goes to next tile on each tick. If the tile is not available on the screen it uses a random tile nearby selected tile. The error seems to be when incrementing pathStep but i only increment it once. The arrays that im passing through range in lengh from 8 - 11. Somewhere durring the walking method it increments pathStep more than once and gets to the end of the available path before actually being there. I think this my java skill being challenge not an issue with DreamBot. Can you see where i am doing wrong with this? Console Output Spoiler 2:39:41 PM: [SCRIPT] Using Path Walker 2:39:41 PM: [SCRIPT] Path Length: 10 2:39:41 PM: [SCRIPT] Current Step: 0 2:39:41 PM: [SCRIPT] Started Walking 2:39:43 PM: [SCRIPT] Using Path Walker 2:39:43 PM: [SCRIPT] Path Length: 10 2:39:43 PM: [SCRIPT] Current Step: 1 2:39:43 PM: [SCRIPT] Started Walking 2:39:46 PM: [SCRIPT] Using Path Walker 2:39:46 PM: [SCRIPT] Path Length: 10 2:39:46 PM: [SCRIPT] Current Step: 2 2:39:46 PM: [SCRIPT] Started Walking 2:39:51 PM: [SCRIPT] Using Path Walker 2:39:51 PM: [SCRIPT] Path Length: 10 2:39:51 PM: [SCRIPT] Current Step: 3 2:39:51 PM: [SCRIPT] Started Walking 2:39:57 PM: [SCRIPT] Using Path Walker 2:39:57 PM: [SCRIPT] Path Length: 10 2:39:57 PM: [SCRIPT] Current Step: 4 2:39:57 PM: [SCRIPT] Started Walking 2:39:57 PM: [SCRIPT] Using Path Walker 2:39:57 PM: [SCRIPT] Path Length: 10 2:39:57 PM: [SCRIPT] Current Step: 5 2:39:57 PM: [SCRIPT] Started Walking 2:40:04 PM: [SCRIPT] Using Path Walker 2:40:04 PM: [SCRIPT] Path Length: 10 2:40:04 PM: [SCRIPT] Current Step: 6 2:40:04 PM: [SCRIPT] Started Walking 2:40:13 PM: [SCRIPT] Using Path Walker 2:40:13 PM: [SCRIPT] Path Length: 10 2:40:13 PM: [SCRIPT] Current Step: 7 2:40:13 PM: [SCRIPT] Started Walking 2:40:23 PM: [SCRIPT] Using Path Walker 2:40:23 PM: [SCRIPT] Path Length: 10 2:40:23 PM: [SCRIPT] Current Step: 8 2:40:24 PM: [SCRIPT] Started Walking 2:40:32 PM: [SCRIPT] Using Path Walker 2:40:32 PM: [SCRIPT] Path Length: 10 2:40:32 PM: [SCRIPT] Current Step: 9 2:40:33 PM: [SCRIPT] Started Walking 2:40:42 PM: [SCRIPT] Using Path Walker 2:40:42 PM: [SCRIPT] Path Length: 10 2:40:42 PM: [SCRIPT] Current Step: 10 2:40:42 PM: [ERROR] Walking Path selected is larger than available path. 2:40:42 PM: [ERROR] Error: 10 >= 10 2:40:42 PM: [SCRIPT] Started Walking 2:40:51 PM: [SCRIPT] Using Path Walker 2:40:51 PM: [SCRIPT] Path Length: 10 2:40:51 PM: [SCRIPT] Current Step: 11 2:40:51 PM: [ERROR] Walking Path selected is larger than available path. 2:40:51 PM: [ERROR] Error: 11 >= 10 2:40:52 PM: [SCRIPT] Started Walking 2:40:55 PM: [SCRIPT] Using Path Walker 2:40:55 PM: [SCRIPT] Path Length: 10 2:40:55 PM: [SCRIPT] Current Step: 12 2:40:55 PM: [ERROR] Walking Path selected is larger than available path. 2:40:55 PM: [ERROR] Error: 12 >= 10 2:40:55 PM: [SCRIPT] Didnt walk to (3166, 3305, 0) 2:40:56 PM: [SCRIPT] Using Path Walker 2:40:56 PM: [SCRIPT] Path Length: 10 2:40:56 PM: [SCRIPT] Current Step: 12 2:40:56 PM: [ERROR] Walking Path selected is larger than available path. 2:40:56 PM: [ERROR] Error: 12 >= 10 2:40:56 PM: [SCRIPT] Started Walking Code Below Spoiler import ghostdata.flourpots.ScriptStats; import ghostdata.framework.behaviortree.Node; import org.dreambot.api.methods.Calculations; import org.dreambot.api.methods.MethodProvider; import org.dreambot.api.methods.interactive.Players; import org.dreambot.api.methods.map.Area; import org.dreambot.api.methods.map.Map; import org.dreambot.api.methods.map.Tile; import org.dreambot.api.methods.walking.impl.Walking; import org.dreambot.api.utilities.impl.Condition; public abstract class AdvancedWalker implements Node { private final Area finalArea; private Tile[][] availablePaths = null; private int selectedPath = -1; private int pathStep = 0; public AdvancedWalker(Area area) { this.finalArea = area; } public AdvancedWalker(Area area, Tile[]... walkingPaths) { this.finalArea = area; this.availablePaths = walkingPaths; } @Override public Object tick() { if (finalArea.contains(Players.localPlayer().getTile())) { selectedPath = -1; return onArrival(); } if (selectedPath == -1) { selectedPath = Calculations.random(0, availablePaths.length); pathStep = findClosestTileIndex(availablePaths[selectedPath]); } if (Players.localPlayer().isMoving()) { return -1; } Tile walkTile = null; if (availablePaths == null || availablePaths.length == 0) { walkTile = ScriptStats.R.nextBoolean() ? finalArea.getRandomTile() : finalArea.getTile(); MethodProvider.log("Using Area Walker"); } else { MethodProvider.log("Using Path Walker"); try { Tile[] path = availablePaths[selectedPath]; MethodProvider.log("Path Length: " + path.length); MethodProvider.log("Path Step: " + pathStep); if (pathStep >= path.length) { walkTile = finalArea.getTile().getRandomizedTile(1); MethodProvider.logError("Walking Path selected is larger than available path. Using Random Tile."); MethodProvider.logError("Error: " + pathStep + " >= " + path.length); } else { walkTile = path[pathStep]; } } catch (Exception e) { MethodProvider.logError("There was an error with AdvancedWalker. Out of Bounds."); MethodProvider.logError(e); } } if (walkTile(walkTile != null ? walkTile : finalArea.getRandomTile(), 1)) { MethodProvider.log("Started Walking"); pathStep += 1; } else { MethodProvider.log("Didn't walk to " + walkTile); } return new Object[] { (Condition) () -> Walking.getDestinationDistance() <= 1, Calculations.random(3000, 10000) }; } public abstract Object onArrival(); private final int findClosestTileIndex(Tile[] tiles) { int closestIndex = 0; double closestDistance = -1; for (int i = 0; i < tiles.length; i++) { Tile tile = tiles[i]; double distance = tile.distance(Players.localPlayer().getTile()); if (distance < closestDistance || closestDistance == -1) { closestDistance = distance; closestIndex = i; } } return closestIndex; } public boolean walkTile(Tile tile, int shouldWalk) { return walkTile(tile, shouldWalk, true); } public boolean walkTile(Tile tile, int shouldWalk, boolean findClosest) { if (Map.isTileOnMap(tile)) { if (Walking.shouldWalk(shouldWalk)) { int bounds = Calculations.random(0, 100); if (bounds <= 25) { return Map.interact(tile, "Walk here"); } else if (bounds >= 75) { return Walking.clickTileOnMinimap(tile); } else { return Walking.walk(tile); } } } else if (findClosest) { return Walking.walk(tile.getRandomizedTile(2)); } return false; } }
Axolotl 31 Posted August 28, 2022 Your error is cause you are incrementing path step and never resetting it when its about to hit array length. Change: if (pathStep >= path.length) { walkTile = finalArea.getTile().getRandomizedTile(1); MethodProvider.logError("Walking Path selected is larger than available path. Using Random Tile."); MethodProvider.logError("Error: " + pathStep + " >= " + path.length); } else { walkTile = path[pathStep]; } To: if (pathStep + 1 >= path.length) { pathStep = 0; MethodProvider.log("Resetting path step"); } else { walkTile = path[pathStep]; } Within your try block
GhostData 6 Author Posted August 28, 2022 25 minutes ago, Axolotl said: To: if (pathStep + 1 >= path.length) { pathStep = 0; MethodProvider.log("Resetting path step"); } else { walkTile = path[pathStep]; } Within your try block To take your advice i have a method called findClosestTileIndex that i am using to change the pathStep if i start from the closest tile in the path and use that to change the pathStep when the array is out of bounds. I also changed the return condition to better account for if the player is still out of range What it looks like now... if (pathStep >= path.length) { MethodProvider.logError("Walking Path selected is larger than available path. Finding Closest Tile Index."); MethodProvider.logError("Error: " + pathStep + " >= " + path.length); pathStep = findClosestTileIndex(path); MethodProvider.logError("Found Closest Tile Index - " + pathStep); } walkTile = path[pathStep]; Doing all of that seems to have fixed the issue that i was having on a smaller scale. Thanks for the help @Axolotl
Recommended Posts
Archived
This topic is now archived and is closed to further replies.