Camaro Posted November 8, 2019 Share Posted November 8, 2019 (edited) Simple class to help change the zoom Spoiler import org.osbot.rs07.Bot; import org.osbot.rs07.api.Settings; import org.osbot.rs07.api.ui.RS2Widget; import org.osbot.rs07.api.ui.Tab; import org.osbot.rs07.event.Event; import org.osbot.rs07.input.mouse.PointDestination; import org.osbot.rs07.input.mouse.WidgetDestination; import org.osbot.rs07.utility.Condition; import org.osbot.rs07.utility.ConditionalSleep2; public final class ZoomControl extends Event { /** * Determines if the camera Z scale is within a requested Zoom * * @param currentZoom the current Z scale of the camera * @param requestedZoom the requested Z scale of the camera * @return true if we are within the range, otherwise false */ public static boolean isInRange(int currentZoom, int requestedZoom) { int currentPos = (int) getPosition(currentZoom); int requestedPos = (int) getPosition(requestedZoom); return currentPos > requestedPos - 5 && currentPos < requestedPos + 5; } /** * Public method to execute event * * @param bot the bot instance * @param requestedZoom the zoom value to set * @return true if the event finished successfully */ public static boolean setZoom(Bot bot, int requestedZoom) { Event event = new ZoomControl(requestedZoom); bot.getEventExecutor().execute(event); return event.hasFinished(); } private final int zoom; private ZoomControl(int zoom) { this.zoom = zoom; } /** * Generates the would-be X position of the slider if the Z scale was the given value * * @param zoom the camera Z scale * @return the X position of the slider */ private static double getPosition(int zoom) { double a = 415.7837; double power = 0.07114964; return a * Math.pow(zoom, power); } /** * Creates a new Condition, representing a Mouse Drag from the current position * of the slider to the requested position to achieve the correct zoom * * @param slider the slider widget object * @return the Condition to pass to a continualClick method */ private Condition moveMouse(RS2Widget slider) { return new Condition() { @Override public boolean evaluate() { // Generate the X position for the slider of the requested zoom double widgetDestX = getPosition(zoom); // Generate the mouse's end X position for moving the slider int mouseDestX = (int) widgetDestX + (int) (getMouse().getPosition().getX() - slider.getBounds().getX()); // Generate the mouse's end Y position for moving the slider int mouseDestY = (int) slider.getPosition().getY() + (int) (slider.getHeight() / 2.00); return getMouse().move(new PointDestination(getBot(), mouseDestX, mouseDestY)); } }; } /** * Execution method * * @return the sleep time in between loops */ @Override public int execute() { if (isInRange(getCamera().getScaleZ(), zoom)) { setFinished(); return 0; } else if (!getTabs().isOpen(Tab.SETTINGS)) { if (getSettings().open()) return 0; } else if (getSettings().getCurrentBasicSettingsTab() != Settings.BasicSettingsTab.DISPLAY) { if (getSettings().open(Settings.BasicSettingsTab.DISPLAY)) { return 0; } } else { RS2Widget slider = getWidgets().getWidgetContainingSprite(116, 1201); if (slider != null) { if (getMouse().continualClick(new WidgetDestination(getBot(), slider, 3), moveMouse(slider)) && ConditionalSleep2.sleep(1000, () -> isInRange(getCamera().getScaleZ(), zoom))) { return 0; } } } return 300; } } Usage Spoiler if (!ZoomControl.isInRange(getCamera().getScaleZ(), 275)) { ZoomControl.setZoom(getBot(), 275); } Extreme usage Spoiler public class Main extends Script { private Deque<Integer> deck; private int flag = 0; { deck = IntStream.rangeClosed(181, 1448).boxed().collect(Collectors.toCollection(LinkedList::new)); } @Override public int onLoop() throws InterruptedException { if (deck.isEmpty()) { stop(); } else { ZoomControl.setZoom(getBot(), flag++%2==0 ? deck.removeFirst() : deck.removeLast()); } return 50; } } Edited December 15, 2021 by Camaro 6 2 Quote Link to comment Share on other sites More sharing options...
Gunman Posted November 8, 2019 Share Posted November 8, 2019 No idea how efficient, effective, or if it would even work, but if it does this could be useful in some scenarios. Quote Link to comment Share on other sites More sharing options...
Czar Posted November 8, 2019 Share Posted November 8, 2019 Excellent job, should be very useful to many. Keep it up ^^ Quote Link to comment Share on other sites More sharing options...
BuyingHardcores Posted November 8, 2019 Share Posted November 8, 2019 great stuff man Quote Link to comment Share on other sites More sharing options...
wontonlover Posted April 3, 2020 Share Posted April 3, 2020 Very useful! Thanks 1 Quote Link to comment Share on other sites More sharing options...
Chris Posted April 22, 2020 Share Posted April 22, 2020 Thanks 1 Quote Link to comment Share on other sites More sharing options...
Camaro Posted December 15, 2021 Author Share Posted December 15, 2021 updated for the new settings tab changes Quote Link to comment Share on other sites More sharing options...
Gabriel Ramuglia Posted January 19, 2022 Share Posted January 19, 2022 Another way to do it is with scroll wheel up or down, provided the mouse is onscreen: if (zScale > 500) { ctx.log("Z scale > 500. Zooming out. 181 is max zoom out. 1448 is max zoom in). "); if (ctx.getMouse().isOnScreen()) { ctx.getMouse().scrollDown(); sleep(rand(50,150)); ctx.getMouse().scrollDown(); sleep(rand(50,150)); ctx.log("Former Z scale = " + zScale + ". New Z scale = " + thisCamera.getScaleZ()); } } else if (zScale < 300) { ctx.log("Z scale < 300. Zooming in. 181 is max zoom out. 1448 is max zoom in). "); if (ctx.getMouse().isOnScreen()) { ctx.getMouse().scrollUp(); sleep(rand(50,150)); ctx.getMouse().scrollUp(); sleep(rand(50,150)); ctx.log("Former Z scale = " + zScale + ". New Z scale = " + thisCamera.getScaleZ()); } } else { ctx.log("Z scale = " + zScale); } Quote Link to comment Share on other sites More sharing options...