Jump to content
Joseph

Walking snippet OSB2

Recommended Posts

It uses the local path finder. When using entity, they must have been loaded. Also canReach() is bugged when checking to see if your on top of the position. So i tweaked it a bit.

 

This doesnt contain obstacle handling, im still a bit confused on how im going to add it in. If you have an idea i would love to hear it.

import java.util.LinkedList;

import org.osbot.rs07.api.map.Position;
import org.osbot.rs07.api.model.Entity;
import org.osbot.rs07.api.util.LocalPathFinder;
import org.osbot.rs07.input.mouse.MiniMapTileDestination;
import org.osbot.rs07.script.MethodProvider;
import org.osbot.rs07.script.Script;

public class Walking {
	
	/*
	 * Doesn't contain obstacle handling.
	 */
	private LocalPathFinder pathFinder;
	private Script script;
	
	public Walking(Script script)	{
		this.script = script;
		this.pathFinder = new LocalPathFinder(script.bot);
	}
	
	public boolean canReach(Position pos)	{
		if (script.myPlayer().getPosition().equals(pos))
			return true;
		else
			return script.map.canReach(pos);
	}

	public boolean setRun(int amount)	{
		if (script.settings.getRunEnergy() >= amount && !script.settings.isRunning())	{
			if (script.settings.isDataOrbsActive())
				return script.interfaces.getChild(548, 39).interact();
			else
				return	script.settings.setRunning(true);
		}
		return script.settings.getRunEnergy() >= amount && script.settings.isRunning();
	}
	
	public boolean walkMiniMap(int threshold, Position pos) throws InterruptedException	{
		MiniMapTileDestination des = new MiniMapTileDestination(script.bot, pos);
	
		if (canReach(pos))	{
		    int fail = 0;
			script.mouse.click(des);
			//script.log("tries: " +fail);
		    while (script.myPosition().distance(pos) > threshold && fail < 10)	{
		    	MethodProvider.sleep(500);
		    	if (!script.myPlayer().isMoving())
		    		fail++;
		    }
		    return fail != 10;
		}
		return false;
	}
	
	public void walkPath(int threshold, Entity entity) throws InterruptedException	{
		LinkedList<Position> path = pathFinder.findPath(entity);
		
		if (pathFinder.foundPath())	{
			for (Position pos: path)	{
				if (pos != null && script.myPosition().distance(pos) > threshold)	{
					if (canReach(pos)) {
						this.walkMiniMap(threshold, pos);
					}else{
						script.log("cant reach pos: " +pos.toString());
					}
				}
			}
		}else
			script.log("error looking for path");
	}
	
	public void walkPath(int threshold, Position endPos) throws InterruptedException	{
		LinkedList<Position> path = pathFinder.findPath(endPos);
		
		if (pathFinder.foundPath())	{
			for (Position pos: path)	{
				if (pos != null && script.myPosition().distance(pos) > threshold)	{
					if (canReach(pos)) {
						this.walkMiniMap(threshold, pos);
					}else{
						script.log("cant reach pos: " +pos.toString());
					}
				}
			}
		}else
			script.log("error looking for path");
		
	}
	
}
Edited by josedpay
  • Like 1
Link to comment
Share on other sites

I actually made something that uses same algo for finding the position ur at in path. Then, I created a class Node, which is just liek a tile. Node has 2 functions: atNode() and interact() the default interact() for a node is to walk The constructor for this class contains the position of the node. Then I have two more classes NPCNode and ObjectNode that extend node. These 2 classes extend node and override interact method to itneract with the specified object, with the specified verb. (They take id/name and a verb as constructor + the Position for Node.) Also, with the ObjectNodes and NPCNodes i sometimes override the interact() or atNode() methods if i need a more complex interaction.

 

Finally, I got a class called NodePath which traverses the a list of NPC's (Which includes objectNodes and npcNodes's since they extend node.)

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.


  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...