Jump to content

Bot World RandomSolver


Botre

Recommended Posts

A simple event to escape bot worlds.

 

Code:

package dependencies.experimental;

import org.osbot.rs07.api.filter.Filter;
import org.osbot.rs07.api.ui.World;
import org.osbot.rs07.script.MethodProvider;
import org.osbot.rs07.script.RandomEvent;
import org.osbot.rs07.script.RandomSolver;

import dependencies.imported.MilliTimer;

/** 
 * @author 		Bjorn Krols (Botre)
 * @version		0.0
 * @since		April 9, 2015
 */

public class BotWorldSolver extends RandomSolver {
	
	/**
	 * The filter used to hop to an appropriate world.
	 */
	private Filter<World> filter;
	
	/**
	 * A timer that records the time elapsed since world detection.
	 */
	private MilliTimer timer;
	
	/**
	 * The amount of time, in seconds, to wait before hopping.
	 */
	private int seconds;
	
	public BotWorldSolver() {
		super(RandomEvent.OTHER);
	}

	/**
	 * Return true if and only if player is in a bot world.
	 */
	@Override
	public boolean shouldActivate() {
		if (filter == null) prepareFilter();
		return inBotWorld();
	}
	
	@Override
	public void onStart() throws InterruptedException {
		super.onStart();
		// Create a new timer instance.
		timer = new MilliTimer();
		// Set the time to wait before hopping is allowed (30 seconds - 20 minutes).
		seconds = MethodProvider.random.nextInt(1200000) + 30;
	}

	@SuppressWarnings("unchecked")
	@Override
	public int onLoop() throws InterruptedException {
		if (!inBotWorld()) stop();
		if (timer.getElapsedSeconds() > seconds) getWorlds().hop(filter);
		return 1000;
	}
	
	@Override
	public void onExit() throws InterruptedException {
		super.onExit();
		// Clear timer instance.
		timer = null;
	}
	
	public void prepareFilter() {
		// Fetch current world.
		World current = getWorlds().getWorld(getClient().getCurrentWorld());
		// Is current world P2P?
		final Boolean members = Boolean.valueOf(current.isMembers());
		// Is current world PVP?
		final Boolean pvp = Boolean.valueOf(current.isPvpWorld());
		// Create filter based on previous results.
		filter = new Filter<World>() {
			@Override
			public boolean match(World world) {
				return world.isMembers() == members && world.isPvpWorld() == pvp && !world.isFull();
			}
		};
	}
	
	public boolean inBotWorld() {
		int myWorld = getClient().getCurrentWorld();
		return myWorld == 385 || myWorld == 386; 
	}
	
}

How to register:

// Register BotWorldSolver.
getBot().getRandomExecutor().registerRandoms(new BotWorldSolver());
Loaded 1 third-party random solvers!
Edited by Botre
  • Like 1
Link to comment
Share on other sites

for those that get error with the timer:

 

change a few thing to this

	/**
	 * A timer that records the time elapsed since world detection.
	 */
	private long timer;


	@Override
	public void onStart() throws InterruptedException {
		super.onStart();
		// Create a new timer instance.
		this.timer = System.currentTimeMillis();
		// Set the time to wait before hopping is allowed (30 seconds - 20 minutes).
		seconds = MethodProvider.random.nextInt(1200000) + 30;
	}


	@SuppressWarnings("unchecked")
	@Override
	public int onLoop() throws InterruptedException {
		if (!inBotWorld()) stop();
		if (getTimerElapsedSeconds() > seconds) getWorlds().hop(filter);
		return 1000;
	}

add on:
	public int getTimerElapsedSeconds()	{
		return (int) (System.currentTimeMillis() - this.timer / 1000);
	}
  • Like 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

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