Eagle Scripts Posted April 28, 2015 Share Posted April 28, 2015 Hello all,I'd like to know if anybody could help me to make something like a random pathwalking system.I was thinking about my script to go from point A to B with random paths, so it won't walk the same path for hours straight. How would I do this?Also, I was thinking about making a failsafe in the walking, if the player isn't at point A or B, the walking should continue and it should NOT go into another state like WAIT.Every help is appreciated!-Ragfr00b Quote Link to comment Share on other sites More sharing options...
Precise Posted April 28, 2015 Share Posted April 28, 2015 Hello all, I'd like to know if anybody could help me to make something like a random pathwalking system. I was thinking about my script to go from point A to B with random paths, so it won't walk the same path for hours straight. How would I do this? Also, I was thinking about making a failsafe in the walking, if the player isn't at point A or B, the walking should continue and it should NOT go into another state like WAIT. Every help is appreciated! -Ragfr00b You can easily make it so you randomise each position when you plan on walking the preset path. Each time you call that position just randomise the x and y by 1 or more depending on the surrounding space you plan on walking through. If you want to take a completely different route either make a fair amount of pre set paths in an array, select a random number and walk that path in the array. The first one is the easiest one to do as you don't have to collect loads of data. The final way would be to retrieve the flags in the loaded region and use A* to calculate a path using the flags and checking if they are walkable. This should only be done if you have a good knowledge of how A* algorithm works and how to plement it into java. But you can load the flags 52 rules in every direction, so if you path is longer than this, use preset paths and randomise each position like I said above. I hope this helped and if you have anymore question feel free to ask ^_^ Quote Link to comment Share on other sites More sharing options...
Eagle Scripts Posted April 28, 2015 Author Share Posted April 28, 2015 You can easily make it so you randomise each position when you plan on walking the preset path. Each time you call that position just randomise the x and y by 1 or more depending on the surrounding space you plan on walking through. If you want to take a completely different route either make a fair amount of pre set paths in an array, select a random number and walk that path in the array. The first one is the easiest one to do as you don't have to collect loads of data. The final way would be to retrieve the flags in the loaded region and use A* to calculate a path using the flags and checking if they are walkable. This should only be done if you have a good knowledge of how A* algorithm works and how to plement it into java. But you can load the flags 52 rules in every direction, so if you path is longer than this, use preset paths and randomise each position like I said above. I hope this helped and if you have anymore question feel free to ask Thinking about doing the first option, randomizing the x & y from 1 - 3 . How would I implement this in my script? I'll past the walking method and path connected to it in pastebin. http://pastebin.com/j7nupvms Could you tell me what to change/add to make this randomizing method? Quote Link to comment Share on other sites More sharing options...
Precise Posted April 28, 2015 Share Posted April 28, 2015 Thinking about doing the first option, randomizing the x & y from 1 - 3 . How would I implement this in my script? I'll past the walking method and path connected to it in pastebin. http://pastebin.com/j7nupvms Could you tell me what to change/add to make this randomizing method? Ah i see the issue you are having. you can only do this if you make your own method. how i would make my own method? i would make a method which is called getNextPositionOnPath(Path path) this should return the next position in the array which is walkable. i would make a for loop which goes from path.length-1 to 0 to find which finds which position is closest to you and return it. once you get the getNextPositionOnPath(Path path) assign it to a variable called nextPosition, make a new variable called newPosition= new Position(nextPosition.getX() + ***RANDOM NUMBER***, nextPosition.getY() + ***DIFFERENT RANDOM NUMBER***, nextPosition.getZ()) then make another method called walkPath which walks to the next position, once the distance < random number, getnextPosition and walk to it etc. Quote Link to comment Share on other sites More sharing options...
lare96 Posted April 29, 2015 Share Posted April 29, 2015 (edited) Ah i see the issue you are having. you can only do this if you make your own method. how i would make my own method? i would make a method which is called getNextPositionOnPath(Path path) this should return the next position in the array which is walkable. i would make a for loop which goes from path.length-1 to 0 to find which finds which position is closest to you and return it. once you get the getNextPositionOnPath(Path path) assign it to a variable called nextPosition, make a new variable called newPosition= new Position(nextPosition.getX() + ***RANDOM NUMBER***, nextPosition.getY() + ***DIFFERENT RANDOM NUMBER***, nextPosition.getZ()) then make another method called walkPath which walks to the next position, once the distance < random number, getnextPosition and walk to it etc. Some ugly pseudo-code, I wrote this in the reply box off top so I can't guarantee it'll work but it should give you some sort of idea on how to do what he suggested. Basically what the method does is take an array of positions, find the one closest to you and then reconstructs a randomized new path and returns it as a new array of positions. It does not modify the given array, and the returned array holds no references to the given one... because that obviously wouldn't work out too well. public Position[] getRandomizedPath(Position[] path) { // local fields Position player = myPlayer().getPosition(); int index = 0; int dist = Integer.MAX_VALUE; // get index closest to player for(int i = 0; i < path.length; i++) { int amount = path[i].distance(player); if(amount < dist) { dist = amount; index = i; } } // filter positions and randomize them List<Position> list = new LinkedList<>(); for(int i = 0; i < path.length; i++) { if(i >= index) { list.add(new Position(path[i].getX() + MethodProvider.random(5), path[i].getY() + MethodProvider.random(5)); } } // return filtered and randomized positions return list.toArray(new Position[list.size()]); } private static final Position[] PATH = { ... } public void ... () { ... localWalker.walk(getRandomizedPath(PATH)); ... } Edited April 29, 2015 by lare96 Quote Link to comment Share on other sites More sharing options...