Jump to content
View in the app

A better way to browse. Learn more.

OSBot :: 2007 OSRS Botting

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Diclonius Path Walking

Featured Replies

Usage:

Place this somewhere in the class:
DicloniusWalking walker = null; 


 
Place this onStart:

walker = new DicloniusWalking(this); 


 
Create a new path like so, note that the positions can be as far away from each other as you like as this will walk along the lines between each position. For easy path generation, use this: http://osbot.org/forum/topic/13836-multi-path-recorder/

Position[] path = new Position[] {
new Position(3093,3491,0),
new Position(3080,3483,0),
new Position(3081,3472,0),
new Position(3082,3466,0),
new Position(3090,3440,0),
new Position(3081,3421,0),
}; 


 
Walk like so:

walker.walk(path,direction); 


 
Class:

import java.util.ArrayList;
import java.util.List;

import org.osbot.script.MethodProvider;
import org.osbot.script.Script;
import org.osbot.script.rs2.map.Position;

public class DicloniusWalking {

	Script S;

	public DicloniusWalking(Script script) {
		S = script;
	}

	public boolean walk(Position[] path, boolean direction) throws InterruptedException {
		Position dest = S.client.getDestination();
		if(S.distance(dest)<MethodProvider.random(3,7) || !S.myPlayer().isMoving()) {
			Position pos = nextPos(path, direction);
			
			if(pos == null) {
				return false;
			} else {
				return S.walkMiniMap(pos);
			}
				
		}
		return true;
	}
	
	public Position nextPos(Position[] path, boolean direction) {
		List<Position> fullPath = getFullPath(path);

		if(direction) {
			for(int u = 0; u < fullPath.size(); u++) {
				Position p = fullPath.get(u);
				if(S.distance(p) < 10) {
					int xOffSet = MethodProvider.random(3)-1;
					int yOffSet = MethodProvider.random(3)-1;
					return new Position(p.getX()+ xOffSet,p.getY()+yOffSet,S.myZ());
				}
			}
		} else {
			for(int u = fullPath.size()-1; u > 0; u=u-1) {
				Position p = fullPath.get(u);
				if(S.distance(p) < 10) {
					int xOffSet = MethodProvider.random(3)-1;
					int yOffSet = MethodProvider.random(3)-1;
					return new Position(p.getX()+ xOffSet,p.getY()+yOffSet,S.myZ());
				}
			}
		}



		return null;

	}

	public boolean atPathEnd(Position[] path, int distance) {
		if(S.distance(path[0]) > distance) {
			return true;
		}
		if(S.distance(path[path.length-1]) > distance) {
			return true;
		}
		return false;
	}

	private boolean yEqualsMXPlusC(int y,double m,int x, int c) {
		int a =(((int)Math.round(m*x))+c) -y;
		return a == -1 ||  a == 0 ||  a == 1;
	}

	private List<Position> getFullPath(Position[] path) {
		List<Position> fullPath = new ArrayList<Position>();
		for(int a = 0; a < path.length -1;a++) {
			Position pos1 = path[a];
			Position pos2 = path[a+1];

			int y = pos1.getY() - pos2.getY();
			int x = pos1.getX() - pos2.getX();

			double m = (double)(y)/(double)(x);
			int c = (int) Math.round(pos1.getY() - m*pos1.getX());

			
			//straight line along y axis
			if(pos1.getY() == pos2.getY()) {
				if(pos1.getX() < pos2.getX()) {
					for(int i = pos1.getX(); i <= pos2.getX(); i++ ) {
						fullPath.add(new Position(i,pos1.getY(),0));
					}
				} else {
					for(int i = pos1.getX(); i >= pos2.getX(); i = i-1) {
						fullPath.add(new Position(i,pos1.getY(),0));
					}
				}
			}
			
			//straight line along X axis
			if(pos1.getX() == pos2.getX()) {
				if(pos1.getY() < pos2.getY()) {
					for(int i = pos1.getY(); i <= pos2.getY(); i++ ) {
						fullPath.add(new Position(i,pos1.getX(),0));
					}
				} else {
					for(int i = pos1.getX(); i >= pos2.getX(); i = i-1) {
						fullPath.add(new Position(i,pos1.getX(),0));
					}
				}
			}
			
			//if pos1 is below pos2
			if(pos1.getY() < pos2.getY()) {
				//loop the squares between pos1 and 2 on the y axis
				for(int l = pos1.getY(); l < pos2.getY(); l++) {

					//if pos1 is left of pos2
					if(pos1.getX() < pos2.getX()) {
						//loop the squares between pos1 and 2 on the x axis
						for(int w = pos1.getX() ; w < pos2.getX() ; w++) {
							//if y=mx+c, pretty much if this square is on the line.
							if(yEqualsMXPlusC(l,m,w,c)) {
								fullPath.add(new Position(w,l,0));
							}
						}
					} else if(pos1.getX() > pos2.getX()){//pos1 is right of pos 2
						//loop the squares between pos1 and 2 on the x axis
						for(int w = pos1.getX() ; w > pos2.getX() ; w = w-1) {

							//if y=mx+c, pretty much if this square is on the line.
							if(yEqualsMXPlusC(l,m,w,c)) {
								fullPath.add(new Position(w,l,0));
							}
						}
					}
				}
			} else if(pos1.getY() > pos2.getY()) {
				//loop the squares between pos1 and 2 on the y axis
				for(int l = pos1.getY(); l > pos2.getY(); l=l-1) {

					//if pos1 is left of pos2
					if(pos1.getX() < pos2.getX()) {
						//loop the squares between pos1 and 2 on the x axis
						for(int w = pos1.getX() ; w < pos2.getX() ; w++) {
							//if y=mx+c, pretty much if this square is on the line.
							if(yEqualsMXPlusC(l,m,w,c)) {
								fullPath.add(new Position(w,l,0));
							}
						}
					} else if(pos1.getX() > pos2.getX()) {//pos1 is right of pos 2
						//loop the squares between pos1 and 2 on the x axis
						for(int w = pos1.getX() ; w > pos2.getX() ; w = w-1) {

							//if y=mx+c, pretty much if this square is on the line.
							if(yEqualsMXPlusC(l,m,w,c)) {
								fullPath.add(new Position(w,l,0));
							}
						}
					}
				}
			}
		}
		return fullPath;
	}
}
 

 

Edited by Diclonius

  • Author

If you used this code before this post, copy class code again because I fixed an error with straight lines.

Edited by Diclonius

 

This is awfully long. :x

It's cool though because the points can be as far away from each other as you like and it's randomized.

 

Ah, that's nice. :) I have a nifty snippet as well which works awesome too. ;)

  • Author

Is there any way to add support for door handling in this snippet? smile.png

Thanks.

 

 

I suppose I could try to implement the other door handling snippet that somebody posted but to be honest I can't really be bothered and I can see it causing some problems for example, if you wanted to walk from across Varrock from one corner to another, if one of the tiles it walks to is inside a building, it would go through opening that door and then by the time the door is open, it would probably be trying to walk inside a different building. I think it would be better to just code in doors yourself. A good way to detect if you need to open a door is using realDistance(Position). it will return -1 if the position is unreachable so make it a position on the side of the door you want to be on and it will return -1 if you need to open the door.

Please utilise the methods already provided by the java api, they're there for a reason. Specifically the Math class.

 

@DoorHandling, Please check the api. 

import org.osbot.script.rs2.map.DoorHandler;

DoorHandler doorHandler = new DoorHandler();
if(doorHandler.handleNextObstacle(...)) {
	//can reach ...
}

Oh, and what is the point of your, getFullPath method?

  • Author

It gets a list, in order, of all the tiles along the line so that I can loop through them going up/down the line. Also I already explained why I didn't add door handling. I might give it a try though,

It gets a list, in order, of all the tiles along the line so that I can loop through them going up/down the line. Also I already explained why I didn't add door handling. I might give it a try though,

 

Why not just use

DoorHandler doorHandler = new DoorHandler();
if(doorHandler.handleNextObstacle(...)) {
	//can reach ...
}

when walking to each point

 

and why haven't you used the Math class etc, could make this a lot simpler and shorter.

  • Author

 

It gets a list, in order, of all the tiles along the line so that I can loop through them going up/down the line. Also I already explained why I didn't add door handling. I might give it a try though,

Why not just use

DoorHandler doorHandler = new DoorHandler();if(doorHandler.handleNextObstacle(...)) {	//can reach ...}
when walking to each point

and why haven't you used the Math class etc, could make this a lot simpler and shorter.

I didn't use the math class because I can't see how any of the methods could be used for what I wanted to do. If you could explain a better method, that would help me out :).

Edited by Diclonius


int a = 10, b = 6;

if(a > b) {

for(int i = b; i <= a; i++) {

}

} else {

for(int i = a; i <= b; i++) {

}

}

=

int a = 10, b = 6;

for(int i = Math.min(a, b); i <= Math.max(a, b); i++) {

}

Guest
This topic is now closed to further replies.

Recently Browsing 0

  • No registered users viewing this page.

Account

Navigation

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.