House Posted August 3, 2016 Share Posted August 3, 2016 (edited) 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 August 3, 2016 by House 5 Quote Link to comment Share on other sites More sharing options...
Saiyan Posted August 3, 2016 Share Posted August 3, 2016 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 1 Quote Link to comment Share on other sites More sharing options...
Solzhenitsyn Posted August 3, 2016 Share Posted August 3, 2016 What does the () -> false parameter do? Quote Link to comment Share on other sites More sharing options...
House Posted August 3, 2016 Author Share Posted August 3, 2016 (edited) 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 August 3, 2016 by House Quote Link to comment Share on other sites More sharing options...
Explv Posted August 3, 2016 Share Posted August 3, 2016 (edited) Good job Except for the if if if if if .... You can easily avoid that if you just invert the condition like: if (!script.getTabs().getOpen().equals(Tab.LOGOUT)) { script.getTabs().open(Tab.LOGOUT); return false; } Edited August 3, 2016 by Explv Quote Link to comment Share on other sites More sharing options...
Botre Posted August 3, 2016 Share Posted August 3, 2016 What does the () -> false parameter do? https://docs.oracle.com/javase/8/docs/api/java/util/function/BooleanSupplier.html 1 Quote Link to comment Share on other sites More sharing options...
Auron Posted August 3, 2016 Share Posted August 3, 2016 Oh nice, cheers for this. Will most likely be using.I would add this to save writing a million empty lambda functions public boolean hop(int world) { return hop(world, () -> false); } 2 Quote Link to comment Share on other sites More sharing options...
Solzhenitsyn Posted August 4, 2016 Share Posted August 4, 2016 (edited) 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 August 4, 2016 by FuckingAshole 1 Quote Link to comment Share on other sites More sharing options...
House Posted August 4, 2016 Author Share Posted August 4, 2016 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. Create an instance in your main class that extends Script and pass it into the constructor of your tasks 2 Quote Link to comment Share on other sites More sharing options...
InsomniakSam Posted January 20, 2017 Share Posted January 20, 2017 Is there a way to get it to randomly choose between x worlds ? something like hHopper.hop(1,2,3,etc () -> false); can't seems to get it done... Quote Link to comment Share on other sites More sharing options...
The Undefeated Posted February 22, 2017 Share Posted February 22, 2017 On 1/20/2017 at 6:41 AM, insomniaksam said: Is there a way to get it to randomly choose between x worlds ? something like hHopper.hop(1,2,3,etc () -> false); can't seems to get it done... hHopper.hop(random(1,94), () -> false); // This will randomly choose from world 1 to 94. 1 Quote Link to comment Share on other sites More sharing options...
whipz Posted February 23, 2017 Share Posted February 23, 2017 How would I go about using this to just randomly hop to certain worlds ? eg f2p ? Quote Link to comment Share on other sites More sharing options...
House Posted February 23, 2017 Author Share Posted February 23, 2017 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. Quote Link to comment Share on other sites More sharing options...
whipz Posted February 23, 2017 Share Posted February 23, 2017 7 minutes ago, House said: 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. sweet will this try to log into the world your already in by accident ? Quote Link to comment Share on other sites More sharing options...
House Posted February 23, 2017 Author Share Posted February 23, 2017 15 minutes ago, whipz said: sweet will this try to log into the world your already in by accident ? its not an accident if you choose to make it try log into the same one. You need to check for that yourself 1 Quote Link to comment Share on other sites More sharing options...