Jump to content
Sign in to follow this  
Zappa

Zappa's Path Walking

Recommended Posts

Put this just after your class extends script declaration (replace names and coordinates with your own):

ArrayList<Position> toMine = new ArrayList();
 
        public static Position[] MinePos = { new Position(2845, 2961, 0),
                new Position(2831, 2969, 0), new Position(2827, 2981, 0),
                new Position(2823, 2998, 0) };

Put this in your onStart(); statement:

loadPath(this.toMine, MinePos);

Put this after your onStart(); statement:

private void doWalk(ArrayList<Position> posList)
                        throws InterruptedException {
                for (Iterator localIterator = posList.iterator(); localIterator
                                .hasNext(); this.client.getMyPlayer().isMoving()) {
                        Position pos = (Position) localIterator.next();
                        walkMiniMap(pos);
                        sleep(1300 + random(600));
                }
        }
 
        private void loadPath(ArrayList<Position> list, Position[] pos) {
                for (Position path : pos)
                        list.add(path);
        }

Put this wherever you want to execute the walk:

 

try {
    doWalk(this.toMine);
} catch (Exception localException) {
}
Edited by Zappa
  • Like 2

Share this post


Link to post
Share on other sites

This is a pretty bad path walking implementation... 

 

1. - only supports 1 way walking

2. - only works if you start from the first position in the path

3. - you end up storing the exact same path twice... pointless?

 

Something along the lines of;

/**
 *
 * Walks through an array of tiles to reach the destination
 *
 * @param reverse whether we're going through the tiles in reverse.
 * @param distance the distance threshold of the destination.
 * @param path the tiles that we wish to traverse through
 * @return whether the tiles has been traversed (1), whether the tiles are currently being traversed (0), whether there was an error traversing a tile (-1) or whether the tiles cannot be traversed (-2).
 * @throws InterruptedException
 */
public int walk(boolean reverse, int distance, Position... path) throws InterruptedException {

	if(distance(path[path.length-1]) <= distance && !reverse)
		return 1;
		
	if(distance(path[0]) <= distance && reverse)
		return 1;

	for(int i = reverse ? 0 : path.length-1; reverse ? i < path.length : i >= 0; i += reverse ? 1 : -1) {

		if(path[i] == null || distance(path[i]) <= distance)
			return -1;

		if((distance(path[i]) <= 18) || i == (reverse ? path.length-1 : 0)) {
			if(!canReach(path[i])) {
				if(doorHandler.handleNextObstacle(path[i]) == -1)
					return -2;
			} else
				walk(path[i]);
			return 0;
		}
	}
	return -2;
}

Would be much better.

Share this post


Link to post
Share on other sites

This is a pretty bad path walking implementation... 

 

1. - only supports 1 way walking

2. - only works if you start from the first position in the path

3. - you end up storing the exact same path twice... pointless?

 

Something along the lines of;

/**
 *
 * Walks through an array of tiles to reach the destination
 *
 * @param reverse whether we're going through the tiles in reverse.
 * @param distance the distance threshold of the destination.
 * @param path the tiles that we wish to traverse through
 * @return whether the tiles has been traversed (1), whether the tiles are currently being traversed (0), whether there was an error traversing a tile (-1) or whether the tiles cannot be traversed (-2).
 * @throws InterruptedException
 */
public int walk(boolean reverse, int distance, Position... path) throws InterruptedException {

	if(distance(path[path.length-1]) <= distance && !reverse)
		return 1;
		
	if(distance(path[0]) <= distance && reverse)
		return 1;

	for(int i = reverse ? 0 : path.length-1; reverse ? i < path.length : i >= 0; i += reverse ? 1 : -1) {

		if(path[i] == null || distance(path[i]) <= distance)
			return -1;

		if((distance(path[i]) <= 18) || i == (reverse ? path.length-1 : 0)) {
			if(!canReach(path[i])) {
				if(doorHandler.handleNextObstacle(path[i]) == -1)
					return -2;
			} else
				walk(path[i]);
			return 0;
		}
	}
	return -2;
}

Would be much better.

 

 

Yea, this post is old. I have learned a lot since then haha. I basically made that when I first started scripting.

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...