Jump to content

convert perfect walking method from OSB1 to OSB2


Pug

Recommended Posts

hey guys once i again in need of pro help.. go figure. Anyway i had a perfect walking method from OSB1 and after converting it to OSB2 it didnt function the same. I dont claim to be a java wizard and so alot of the code gets me out of my depth. So the question is how can i get this method to function the same as it did in osbot1. The problem is that it wont click the next position to walk when the player is say 2 or 3 tiles away from the destination position. 

I need this because as i was speaking to Apaec on skype he explained that the loading pause random actually shows how weak some code can be. The method below got past this problem of the random being initialized and pausing the script.

 

so:

	//walking methods
	public boolean WalkAlongPath(int[][] path, boolean AscendThroughPath, int distanceFromEnd)
	{
		log("walk along path");
		if (distanceToPoint(AscendThroughPath ? path[(path.length - 1)][0] : path[0][0], AscendThroughPath ? path[(path.length - 1)][1] : path[0][1]) <= distanceFromEnd) 
		{
			log("dist to point ascend though path ? path <= distance from end");
			return true;
		}
		log("walk along path");
		WalkAlongPath(path, AscendThroughPath);
		return false;
	}

	public void WalkAlongPath(int[][] path, boolean AscendThroughPath)
	{
		int destination = 0;
		for (int i = 0; i < path.length; i++) 
		{
			log("for int i = 0;");
			if (distanceToPoint(path[i][0], path[i][1]) < distanceToPoint(path[destination][0], path[destination][1])) 
			{
				log("if distance to point path i 0 path i 1 < distance to point path dest 0 path dest 1");
				destination = i;
			}
		}
		
		if (this.client.getMyPlayer().isMoving()) 
		{
			log("player is moving");
			if (distanceToPoint(path[destination][0], path[destination][1]) > (this.client.getMyPlayer().isMoving() ? 2 : 2)) 
			{
				log("distance to point path dest 0 path dest 1 > (client moving > 2 : 2)");
				return;
			}
		}
		
		if (((AscendThroughPath) && (destination != path.length - 1)) || ((!AscendThroughPath) && (destination != 0))) 
		{
			log("(ascend through path & dest != path length -1) || ascend through path && dest != 0");
			destination += (AscendThroughPath ? 1 : -1);
		}
	
		try
		{
			log("walk mini map");
			walkMiniMap(new Position(path[destination][0], path[destination][1], 0));
			shout = new Position(path[destination][0], path[destination][1], 0);
			Thread.sleep(700 + MethodProvider.random(600));
		}
		catch (InterruptedException e)
		{
			e.printStackTrace();
		}
	}

	private int distanceToPoint(int pointX, int pointY)
	{
		log("dist to point method");
		return (int)Math.sqrt(Math.pow(this.client.getMyPlayer().getX() - pointX, 6.0D) + Math.pow(this.client.getMyPlayer().getY() - pointY, 6.0D));
	}

osbot spacing may be fucked up in which case for those of you that hate poor formatting as i do, here:

 

http://pastebin.com/uHVGzWLJ

Link to comment
Share on other sites


package pathwalking.Botrepreneur;

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;

import sleep.Botrepreneur.SleepMethods;

import time.Botrepreneur.Timer;

import energy.Botrepreneur.RunMethods;

public class PathWalkMethods {

/**

* @author Botrepreneur

* @Version: 00.41 *Deux*

*/

public static boolean traversePath(Script script, Position[] path, boolean reversed, int toggleRunOnAt, int toggleRunOffAt, boolean toggleRunOnInCombat, long timeout) throws InterruptedException {

Timer timer = new Timer();

int attempts = 0;

while ((!reversed ? !script.myPosition().equals(path[path.length - 1]) : !script.myPosition().equals(path[0])) && timer.getElapsed() < timeout && attempts <= 10) {

RunMethods.manage(script, toggleRunOnAt, toggleRunOffAt, toggleRunOnInCombat);

Position bestPosition = null;

if (!reversed) {

for (int i = 1; i < path.length; i++) {

MiniMapTileDestination mmtd;

if (script.getMap().canReach(path) && (mmtd = new MiniMapTileDestination(script.getBot(), path)) != null && mmtd.isVisible()) {

bestPosition = path;

}

}

} else {

for (int i = path.length - 1; i > 0; i--) {

MiniMapTileDestination mmtd;

if (script.getMap().canReach(path) && (mmtd = new MiniMapTileDestination(script.getBot(), path)) != null && mmtd.isVisible()) {

bestPosition = path;

}

}

}

if (bestPosition != null) {

boolean clicked = false;

if (script.getMap().distance(bestPosition) <= 5 && bestPosition.isVisible(script.getBot())) {

clicked = bestPosition.interact(script.getBot(), "Walk here");

} else {

clicked = script.getMouse().click(new MiniMapTileDestination(script.getBot(), bestPosition));

}

if (clicked) {

SleepMethods.untilMoving(script, 900L);

if (script.myPlayer().isMoving()) {

int speed = MethodProvider.gRandom(script.getSettings().isRunning() ? 250 : 500, 100);

MethodProvider.sleep(script.getMap().distance(bestPosition) * speed);

}

}

else {

script.getCamera().moveYaw(script.getCamera().getYawAngle() + MethodProvider.gRandom(50, 20));

attempts++;

}

} else {

script.getCamera().moveYaw(script.getCamera().getYawAngle() + MethodProvider.gRandom(50, 20));

attempts++;

}

}

return !reversed ? script.myPosition().equals(path[path.length - 1]) : script.myPosition().equals(path[0]);

}

public static boolean traversePath(Script script, Position position, boolean reversed, int toggleRunOnAt, int toggleRunOffAt, boolean toggleRunOnInCombat, long timeout) throws InterruptedException {

if (position == null || !script.getMap().canReach(position)) {

return false;

}

LinkedList<Position> pathList;

Position[] path = null;

if ((pathList = new LocalPathFinder(script.getBot()).findPath(position)) != null) {

path = (Position[]) pathList.toArray(new Position[pathList.size()]);

}

return path != null ? traversePath(script, path, reversed, toggleRunOnAt, toggleRunOffAt, toggleRunOnInCombat, timeout) : false;

}

public static boolean traversePath(Script script, Entity entity, boolean reversed, int toggleRunOnAt, int toggleRunOffAt, boolean toggleRunOnInCombat, long timeout) throws InterruptedException {

Position position;

LinkedList<Position> pathList;

Position[] path = null;

if (entity != null && entity.exists() && (position = entity.getPosition()) != null && script.getMap().canReach(position) && (pathList = new LocalPathFinder(script.getBot()).findPath(position)) != null) {

path = (Position[]) pathList.toArray(new Position[pathList.size()]);

}

else {

return false;

}

return traversePath(script, path, reversed, toggleRunOnAt, toggleRunOffAt, toggleRunOnInCombat, timeout);

}

}

  • Like 1
Link to comment
Share on other sites

package pathwalking.Botrepreneur;

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;

import sleep.Botrepreneur.SleepMethods;
import time.Botrepreneur.Timer;
import energy.Botrepreneur.RunMethods;

public class PathWalkMethods {

	/**
	 * @author Botrepreneur
	 * @Version: 00.41 *Deux*
	 */

	public static boolean traversePath(Script script, Position[] path, boolean reversed, int toggleRunOnAt, int toggleRunOffAt, boolean toggleRunOnInCombat, long timeout) throws InterruptedException {
		Timer timer = new Timer();
		int attempts = 0;
		while ((!reversed ? !script.myPosition().equals(path[path.length - 1]) : !script.myPosition().equals(path[0])) && timer.getElapsed() < timeout && attempts <= 10) {
			RunMethods.manage(script, toggleRunOnAt, toggleRunOffAt, toggleRunOnInCombat);
			Position bestPosition = null;
			if (!reversed) {
				for (int i = 1; i < path.length; i++) {
					MiniMapTileDestination mmtd;
					if (script.getMap().canReach(path[i]) && (mmtd = new MiniMapTileDestination(script.getBot(), path[i])) != null && mmtd.isVisible()) {
						bestPosition = path[i];
					}
				}
			} else {
				for (int i = path.length - 1; i > 0; i--) {
					MiniMapTileDestination mmtd;
					if (script.getMap().canReach(path[i]) && (mmtd = new MiniMapTileDestination(script.getBot(), path[i])) != null && mmtd.isVisible()) {
						bestPosition = path[i];
					}
				}
			}
			if (bestPosition != null) {
				boolean clicked = false;
				if (script.getMap().distance(bestPosition) <= 5 && bestPosition.isVisible(script.getBot())) {
					clicked = bestPosition.interact(script.getBot(), "Walk here");
				} else {
					clicked = script.getMouse().click(new MiniMapTileDestination(script.getBot(), bestPosition));
				}
				if (clicked) {
					SleepMethods.untilMoving(script, 900L);
					if (script.myPlayer().isMoving()) {
						int speed = MethodProvider.gRandom(script.getSettings().isRunning() ? 250 : 500, 100);
						MethodProvider.sleep(script.getMap().distance(bestPosition) * speed);
					}
				}
				else {
					script.getCamera().moveYaw(script.getCamera().getYawAngle() + MethodProvider.gRandom(50, 20));
					attempts++;
				}
			} else {
				script.getCamera().moveYaw(script.getCamera().getYawAngle() + MethodProvider.gRandom(50, 20));
				attempts++;
			}
		}
		return !reversed ? script.myPosition().equals(path[path.length - 1]) : script.myPosition().equals(path[0]);
	}

	public static boolean traversePath(Script script, Position position, boolean reversed, int toggleRunOnAt, int toggleRunOffAt, boolean toggleRunOnInCombat, long timeout) throws InterruptedException {
		if (position == null || !script.getMap().canReach(position)) {
			return false;
		}
		LinkedList<Position> pathList;
		Position[] path = null;
		if ((pathList = new LocalPathFinder(script.getBot()).findPath(position)) != null) {
			path = (Position[]) pathList.toArray(new Position[pathList.size()]);
		}
		return path != null ? traversePath(script, path, reversed, toggleRunOnAt, toggleRunOffAt, toggleRunOnInCombat, timeout) : false;
	}

	public static boolean traversePath(Script script, Entity entity, boolean reversed, int toggleRunOnAt, int toggleRunOffAt, boolean toggleRunOnInCombat, long timeout) throws InterruptedException {
		Position position;
		LinkedList<Position> pathList;
		Position[] path = null;
		if (entity != null && entity.exists() && (position = entity.getPosition()) != null && script.getMap().canReach(position) && (pathList = new LocalPathFinder(script.getBot()).findPath(position)) != null) {
			path = (Position[]) pathList.toArray(new Position[pathList.size()]);
		}
		else {
			return false;
		}
		return traversePath(script, path, reversed, toggleRunOnAt, toggleRunOffAt, toggleRunOnInCombat, timeout);
	}

}

 

Your using static imports for methods that he wont have. ^_^

Link to comment
Share on other sites

Holy shit you guys make everything overly complex.

 

Iterate over your path to grab the closest path index to your current position. From there add one to your index and continue iterating over the path checking to see if the position is within your desired distance. Once the distance exceeds the threshold return the position value located in the last index you grabbed.

public Position nextTile(Position path[], int skipDist) {
    int dist = -1, closest = -1;
    for (int i = path.length - 1; i >= 0; i--) {
        Position tile = path[i];
        int d = scriptInstance.map.distance(tile);
        if (d < dist || dist == -1) {
            dist = d;
            closest = i;
        }
    }
        
    int feasibleTileIndex = -1;
        
    for (int i = closest; i < path.length; i++) {
        if (scriptInstance.map.distance(path[i]) <= skipDist) {
            feasibleTileIndex = i;
        }
        else {
            break;
        }
    }

    return (feasibleTileIndex == -1) ? null : path[feasibleTileIndex];
} 
Edited by Swizzbeat
Link to comment
Share on other sites

f1279479fbb167e4f30fae3cf3eb68a7.png

 

That's not human behavior but a static condition. If you're really trying to mimic a human at the very least add some random deviation to your tile/minimap click points.

 

script.getMap().distance(bestPosition) <= MethodProvider.gRandom(5, 3)

 

fixed <3

 

I didn't add tile deviation because I usually make it choose from a list of paths therefore reducing the probability of hot tile detection.

 

though I will probably  add that feature soon, it will however require collision flag checking and therefore even more complexity, the thing you criticized me for in the first place :p

Link to comment
Share on other sites

script.getMap().distance(bestPosition) <= MethodProvider.gRandom(5, 3)

 

fixed QwPha8E.png

 

I didn't add tile deviation because I usually make it choose from a list of paths therefore reducing the probability of hot tile detection.

 

though I will probably  add that feature soon, it will however require collision flag checking and therefore even more complexity, the thing you criticized me for in the first place tongue.png

You completely missed the point of my last post dry.png

Link to comment
Share on other sites

Please do elaborate then ^^

Creating an actual "human" walker (or even antiban in general) requires more than just calculating a random number and executing an action based on the result. All calculating a random number does is execute your action based on a never changing percentage instead of what you had it at previously with a given number.

 

Previously you had it click the game tile if the distance was less than or equal to 5. Now it will only click if the distance is less than or equal to 3 or 4. If we ran a large number of trail runs at lets say, a distance of 3 between you and the next tile, what you had before would click on the game window 100% while the random number calculation you just implemented would result in a change to 50%. A lower percentage (which I guess isn't bad) but still static nonetheless.

 

Incorporating real human actions requires a multitude of conditions to check and ever changing values to be recalculated. Maybe instead of deciding to click the game based on a distance threshold you instead check to see if the player is in combat? A condition like this is ever changing (like a real human) and is completely based on the concept of "here and now". While it may become evident what is happening if a real Jagex employee decides to look into your past account actions it's most likely not going to be detected by a detection program.

 

What I'm trying to say is if you are using a condition where you can actually calculate the chances of it happening, resort to something else that cannot be predetermined.

Edited by Swizzbeat
Link to comment
Share on other sites

f1279479fbb167e4f30fae3cf3eb68a7.png

 

That's not human behavior but a static condition. If you're really trying to mimic a human at the very least add some random deviation to your tile/minimap click points.

 

although randomness in clicking on the map is in theory a good idea. In practice it can create problems when walking. E.g random(1,3) might seem like a good idea but that might end up clicking the other side of a wall in which you walk 20+ tiles to reach in the oppersite direction lol. 

 

edit: i appeared to have created a conversation. This is GOOD.

 

feel free to continue the discussion on walking etc. All code is interesting to read through and mess with so please keep it coming i love using new code and learning from it.

 

No bitching or getting all high on blue pixels n shit though please :) keep it peaceful <3

Edited by Pug
  • Like 1
Link to comment
Share on other sites

 

Holy shit you guys make everything overly complex.

 

Iterate over your path to grab the closest path index to your current position. From there add one to your index and continue iterating over the path checking to see if the position is within your desired distance. Once the distance exceeds the threshold return the position value located in the last index you grabbed.

public Position nextTile(Position path[], int skipDist) {
    int dist = -1, closest = -1;
    for (int i = path.length - 1; i >= 0; i--) {
        Position tile = path[i];
        int d = scriptInstance.map.distance(tile);
        if (d < dist || dist == -1) {
            dist = d;
            closest = i;
        }
    }
        
    int feasibleTileIndex = -1;
        
    for (int i = closest; i < path.length; i++) {
        if (scriptInstance.map.distance(path[i]) <= skipDist) {
            feasibleTileIndex = i;
        }
        else {
            break;
        }
    }

    return (feasibleTileIndex == -1) ? null : path[feasibleTileIndex];
} 

I agree with Swizz. Y;all are making this shit too complex -.-

	private void walkPath(Position[] path){
		Position finalPos = null;
		for(Position pos : path){
			if(map.canReach(pos) && pos.distance(myPlayer().getPosition())<12 &&                 pos.getZ()==myPosition().getZ()){
				finalPos = pos;
			}
		}
		if((finalPos!=null && (map.getDestination()==null|| map.getDestination().distance(finalPos)>3))){
			localWalker.walk(finalPos);
		}
	}

  • Like 3
Link to comment
Share on other sites

 

What I'm trying to say is if you are using a condition where you can actually calculate the chances of it happening, resort to something else that cannot be predetermined.

 

I see your points.

 

I never claimed my snippet reproduces human behavior perfectly or even got close, all I said was that if you are trying to emulate such behavior it requires complexity.

 

If you think my snippet is more or as ban-productive as the average walker, then fair enough, I don't have any empirical data to contradict that stance. I might be fooling myself, but to me my snippet looks more human-like than any other walker I ever used.

 

Returning the closest tile from an array isn't the most intelligent design either however :p

although randomness in clicking on the map is in theory a good idea. In practice it can create problems when walking. E.g random(1,3) might seem like a good idea but that might end up clicking the other side of a wall in which you walk 20+ tiles to reach in the oppersite direction lol. 

 

 

This could be checked for via collision flags / rooms, might be a bit processing heavy though (unless you cache the data, which is probably how I'll do it :D). 

 

I agree with Swizz. Y;all are making this shit too complex -.-

	private void walkPath(Position[] path){
		Position finalPos = null;
		for(Position pos : path){
			if(map.canReach(pos) && pos.distance(myPlayer().getPosition())<12 &&                 pos.getZ()==myPosition().getZ()){
				finalPos = pos;
			}
		}
		if((finalPos!=null && (map.getDestination()==null|| map.getDestination().distance(finalPos)>3))){
			localWalker.walk(finalPos);
		}
	}

 

I like some control over my walking, if you're fine with localWalker.walk(Position position), then fair nuf I guess :p

Link to comment
Share on other sites

although randomness in clicking on the map is in theory a good idea. In practice it can create problems when walking. E.g random(1,3) might seem like a good idea but that might end up clicking the other side of a wall in which you walk 20+ tiles to reach in the oppersite direction lol. 

 

edit: i appeared to have created a conversation. This is GOOD.

 

feel free to continue the discussion on walking etc. All code is interesting to read through and mess with so please keep it coming i love using new code and learning from it.

 

No bitching or getting all high on blue pixels n shit though please smile.png keep it peaceful QwPha8E.png

 

What you can do is have a boolean in your method for randomizing. walkPath(Path path, boolean randomizeTiles)

 

Then if you are traversing a very sensitive path, set randomizeTiles to false, if the path is in the open let the tiles have a slight randomness. ^_^

 

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...