Jump to content

HHopper | Hop to a specific world + interrupt condition


House

Recommended Posts

FrostHopper is cool and all but i needed this for a specific project and thought i would share.
Credits to @@FrostBug

 

EDIT: Added interrupt to whole method not just scrolling. derp

/**
 * Simplified version of FrostHopper by FrostBug on OSBot.
 * Hops to a specific world with an interrupt condition when scrolling worlds.
 * Credits: FrostBug
 *
 * @author House
 */
public class HHopper {

	private final static int WIDGET_INDEX_ROOT = 14;
	private final static int WIDGET_ROOT = 69;
	private final static int WIDGET_SCROLL = 15;
	private final static int WIDGET_SCROLL_UP = 4;
	private final static int WIDGET_SCROLL_DOWN = 5;

	private final static int MIN_FRAME_Y = 230;
	private final static int MAX_FRAME_Y = 416;

	private final int NOT_LOADING_STATE = 30;

	Script script;

	public HHopper(Script script) {
		this.script = script;
	}

	public boolean hop(int world, BooleanSupplier condition) {
		
		if(condition.getAsBoolean())
			return false;

		if (script.getClient().getLoginStateValue() != NOT_LOADING_STATE)
			return false;

		if (trimWorldNumber(script.getWorlds().getCurrentWorld()) == world)
			return true;

		if (script.getTabs().getOpen().equals(Tab.LOGOUT)) {

			if (isQuickhopOpen()) {

				if (loadingWorlds())
					return false;

				RS2Widget worldWidget = getWorld(world);

				if (worldWidget == null)
					return false;

				if (isSelectable(worldWidget)) {

					Rectangle rect = worldWidget.getRectangle();
					rect.translate(0, 2);
					rect.setSize((int) rect.getWidth(), (int) rect.getHeight() - 4);
					RectangleDestination dest = new RectangleDestination(script.getBot(), rect);
					if (script.getMouse().click(dest, false))
						return false;

				} else
					scrollToWidget(worldWidget, condition);

			} else
				openQuickhop();

		} else
			script.getTabs().open(Tab.LOGOUT);

		return false;

	}

	private boolean scrollToWidget(RS2Widget widget, BooleanSupplier condition) {

		RS2Widget scroll;

		if (widget.getPosition().getY() < MIN_FRAME_Y) {
			scroll = script.getWidgets().get(WIDGET_ROOT, WIDGET_SCROLL, WIDGET_SCROLL_UP);
		} else if (widget.getPosition().getY() > MAX_FRAME_Y) {
			scroll = script.getWidgets().get(WIDGET_ROOT, WIDGET_SCROLL, WIDGET_SCROLL_DOWN);
		} else {
			return false;
		}

		if (scroll != null) {
			final long startTime = System.currentTimeMillis();
			WidgetDestination wDest = new WidgetDestination(script.getBot(), scroll);
			script.getMouse().continualClick(wDest, new Condition() {
				@[member=Override]
				public boolean evaluate() {
					return isSelectable(widget) || (System.currentTimeMillis() - startTime) >= 6000 || condition.getAsBoolean();
				}
			});
		}

		return true;
	}

	private boolean isSelectable(RS2Widget widget) {
		return widget.getPosition().getY() >= MIN_FRAME_Y && widget.getPosition().getY() <= MAX_FRAME_Y;
	}

	private RS2Widget getWorld(int world) {
		@SuppressWarnings("unchecked")
		RS2Widget worldWidget = script.getWidgets().filter(WIDGET_ROOT, (Filter<RS2Widget>) (RS2Widget w) -> {

			if (!w.isThirdLevel() || w.getSecondLevelId() != WIDGET_INDEX_ROOT || w.getThirdLevelId() <= 300 || w.getThirdLevelId() > 400 || w.getHiddenUntilMouseOver()) {
				return false;
			}

			int worldNumber = trimWorldNumber(w.getThirdLevelId());
			return worldNumber == world;

		}).get(0);
		return worldWidget;
	}

	private int trimWorldNumber(int number) {
		return (number > 300) ? number - 300 : number;
	}

	public boolean loadingWorlds() {
		return !script.getWidgets().containingText("Loading...").isEmpty();
	}

	private boolean isQuickhopOpen() {
		return script.getTabs().getOpen() == Tab.LOGOUT && script.getWidgets().containingText("World Switcher").isEmpty();
	}

	private boolean openQuickhop() {
		List<RS2Widget> list = script.getWidgets().containingText("World Switcher");
		if (!list.isEmpty()) {
			return list.get(0).interact();
		}
		return false;
	}

}

Usage:

hHopper.hop(86, () -> false);
Edited by House
  • Like 5
Link to comment
Share on other sites

FrostHopper is cool and all but i needed this for a specific project and thought i would share.

Credits to @@FrostBug

EDIT: Added interrupt to whole method not just scrolling. derp

/** * Simplified version of FrostHopper by FrostBug on OSBot. * Hops to a specific world with an interrupt condition when scrolling worlds. * Credits: FrostBug * * @author House */public class HHopper {	private final static int WIDGET_INDEX_ROOT = 14;	private final static int WIDGET_ROOT = 69;	private final static int WIDGET_SCROLL = 15;	private final static int WIDGET_SCROLL_UP = 4;	private final static int WIDGET_SCROLL_DOWN = 5;	private final static int MIN_FRAME_Y = 230;	private final static int MAX_FRAME_Y = 416;	private final int NOT_LOADING_STATE = 30;	Script script;	public HHopper(Script script) {		this.script = script;	}	public boolean hop(int world, BooleanSupplier condition) {				if(condition.getAsBoolean())			return false;		if (script.getClient().getLoginStateValue() != NOT_LOADING_STATE)			return false;		if (trimWorldNumber(script.getWorlds().getCurrentWorld()) == world)			return true;		if (script.getTabs().getOpen().equals(Tab.LOGOUT)) {			if (isQuickhopOpen()) {				if (loadingWorlds())					return false;				RS2Widget worldWidget = getWorld(world);				if (worldWidget == null)					return false;				if (isSelectable(worldWidget)) {					Rectangle rect = worldWidget.getRectangle();					rect.translate(0, 2);					rect.setSize((int) rect.getWidth(), (int) rect.getHeight() - 4);					RectangleDestination dest = new RectangleDestination(script.getBot(), rect);					if (script.getMouse().click(dest, false))						return false;				} else					scrollToWidget(worldWidget, condition);			} else				openQuickhop();		} else			script.getTabs().open(Tab.LOGOUT);		return false;	}	private boolean scrollToWidget(RS2Widget widget, BooleanSupplier condition) {		RS2Widget scroll;		if (widget.getPosition().getY() < MIN_FRAME_Y) {			scroll = script.getWidgets().get(WIDGET_ROOT, WIDGET_SCROLL, WIDGET_SCROLL_UP);		} else if (widget.getPosition().getY() > MAX_FRAME_Y) {			scroll = script.getWidgets().get(WIDGET_ROOT, WIDGET_SCROLL, WIDGET_SCROLL_DOWN);		} else {			return false;		}		if (scroll != null) {			final long startTime = System.currentTimeMillis();			WidgetDestination wDest = new WidgetDestination(script.getBot(), scroll);			script.getMouse().continualClick(wDest, new Condition() {				@[member='Override']				public boolean evaluate() {					return isSelectable(widget) || (System.currentTimeMillis() - startTime) >= 6000 || condition.getAsBoolean();				}			});		}		return true;	}	private boolean isSelectable(RS2Widget widget) {		return widget.getPosition().getY() >= MIN_FRAME_Y && widget.getPosition().getY() <= MAX_FRAME_Y;	}	private RS2Widget getWorld(int world) {		@SuppressWarnings("unchecked")		RS2Widget worldWidget = script.getWidgets().filter(WIDGET_ROOT, (Filter<RS2Widget>) (RS2Widget w) -> {			if (!w.isThirdLevel() || w.getSecondLevelId() != WIDGET_INDEX_ROOT || w.getThirdLevelId() <= 300 || w.getThirdLevelId() > 400 || w.getHiddenUntilMouseOver()) {				return false;			}			int worldNumber = trimWorldNumber(w.getThirdLevelId());			return worldNumber == world;		}).get(0);		return worldWidget;	}	private int trimWorldNumber(int number) {		return (number > 300) ? number - 300 : number;	}	public boolean loadingWorlds() {		return !script.getWidgets().containingText("Loading...").isEmpty();	}	private boolean isQuickhopOpen() {		return script.getTabs().getOpen() == Tab.LOGOUT && script.getWidgets().containingText("World Switcher").isEmpty();	}	private boolean openQuickhop() {		List<RS2Widget> list = script.getWidgets().containingText("World Switcher");		if (!list.isEmpty()) {			return list.get(0).interact();		}		return false;	}}
Usage:
hHopper.hop(86, () -> false);

Very nice thank you for this :)

  • Like 1
Link to comment
Share on other sites

What does the 

() -> false

 parameter do?

 

Same as passing in false, means there is no interrupt.

Alternative use:

 

hHopper.hop(86, () -> me.isUnderAttack());

This would return right away or while scrolling the worlds list if you are under attack and given you a chance to eat for example instead of continuing trying to hop.

Edited by House
Link to comment
Share on other sites

Apanzms.png

 

Hey, wondering if you can help me with this.

 

http://stackoverflow.com/questions/4922145/non-static-method-cannot-be-referenced-from-a-static-context-error

 

From SO, I've made this change...

    void jumpToSafeWorld()
    {
        status = "There are people on the radar, jumping away from them...";
        //getWorlds().hop(Worlds[random(3,11)]);
        HHopper s = new HHopper(this);
        s.hop(Worlds[random(3,11)], ()->false);
    }

(EDIT: ^ This is really bad, don't do this)

but I'm wondering where I'm supposed to instantiate the new HHopper object and if I need to have a separate instance each time I jump. Thanks for writing this, and thanks for your time.

 

EDIT:

 

If anyone else doesn't know how to use this, and you want to take advice from someone who is more or less mentally retarded and has less than 4 days of Java experience...

public class someClass {
    private HHopper hopper = new HHopper(this);

    private void someFunction() {
        hopper.hop(world, condition)
    }
}
Edited by FuckingAshole
  • Like 1
Link to comment
Share on other sites

  • 5 months later...
  • 1 month later...
1 hour ago, whipz said:

How would I go about using this to just randomly hop to certain worlds ? eg f2p ?

There are some examples already above of how to apply it.

As for hopping to specific worlds you can hop to, you can store an array of f2p world numbers as an example and get a random one from those.

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