SkrrtNick 240 Posted July 2, 2023 Share Posted July 2, 2023 These are option related goodies that I think we are missing, a lot of it is quite new. Some of them like disabling GE warnings are pretty nice if you want to do anything with the Grand Exchange. It's easy to extend and add your own options too! Any questions or concerns please let me know 😄 import lombok.RequiredArgsConstructor; import org.tribot.script.sdk.*; import org.tribot.script.sdk.query.Query; import org.tribot.script.sdk.types.Widget; public class OptionsUtility { public static boolean isDisableLevelUpInterfaceEnabled() { return GameState.getVarbit(9452) == 1; } public static boolean setDisableLevelUpInterfaceEnabled(boolean enabled) { if (enabled == isDisableLevelUpInterfaceEnabled()) return true; boolean priorValue = isDisableLevelUpInterfaceEnabled(); if (!setSetting(AllSettingsTabs.INTERFACES, "Disable level-up interface")) { return false; } return Waiting.waitUntil(3000, ()-> OptionsUtility.isDisableLevelUpInterfaceEnabled() != priorValue); } public static boolean isShowActivityAdviserEnabled() { return GameState.getVarbit(5368) == 0; } public static boolean setShowActivityAdviserEnabled(boolean enabled) { if (enabled == isShowActivityAdviserEnabled()) return true; boolean priorValue = isShowActivityAdviserEnabled(); if (!setSetting(AllSettingsTabs.INTERFACES, "Show Activity Adviser")) { return false; } return Waiting.waitUntil(3000, ()-> OptionsUtility.isShowActivityAdviserEnabled() != priorValue); } public static boolean isAcceptTradeDelayEnabled() { return GameState.getVarbit(13130) == 0; } public static boolean setAcceptTradeDelayEnabled(boolean enabled) { if (enabled == isAcceptTradeDelayEnabled()) { return true; } boolean priorValue = isAcceptTradeDelayEnabled(); if (!setSetting(AllSettingsTabs.INTERFACES, "Accept trade delay")) { return false; } return Waiting.waitUntil(3000, ()-> OptionsUtility.isAcceptTradeDelayEnabled() != priorValue); } public static boolean isGrandExchangeBuyWarningEnabled() { return GameState.getVarbit(14700) == 0; } public static boolean setGrandExchangeBuyWarning(boolean enabled) { if (enabled == isGrandExchangeBuyWarningEnabled()) return true; boolean priorValue = isGrandExchangeBuyWarningEnabled(); if (!setSetting(AllSettingsTabs.WARNINGS, "Show warning when a buy offer price is too high in the Grand Exchange")) { return false; } return Waiting.waitUntil(3000, ()-> OptionsUtility.isGrandExchangeBuyWarningEnabled() != priorValue); } public static boolean isGrandExchangeSellWarningEnabled() { return GameState.getVarbit(14701) == 0; } public static boolean setGrandExchangeSellWarning(boolean enabled) { if (enabled == isGrandExchangeSellWarningEnabled()) return true; boolean priorValue = isGrandExchangeSellWarningEnabled(); if (!setSetting(AllSettingsTabs.WARNINGS, "Show warning when a sell offer price is too low in the Grand Exchange")) { return false; } return Waiting.waitUntil(3000, ()-> OptionsUtility.isGrandExchangeSellWarningEnabled() != priorValue); } public static boolean setEscapeClosing(boolean enabled) { if (enabled == Options.isEscapeClosingEnabled()) return true; boolean priorValue = Options.isEscapeClosingEnabled(); if (!setSetting(AllSettingsTabs.CONTROLS, "Esc closes the current interface")) { return false; } return Waiting.waitUntil(3000, ()-> Options.isEscapeClosingEnabled() != priorValue); } @RequiredArgsConstructor public enum AllSettingsTabs { ACTIVITIES("Activities", 0), AUDIO("Audio", 1), CHAT("Chat", 2), CONTROLS("Controls", 3), DISPLAY("Display", 4), GAMEPLAY("Gameplay", 5), INTERFACES("Interfaces", 6), WARNINGS("Warnings", 7), POPOUT("Popout", 8), ; private final String text; private final int openVarbit; public boolean isOpen() { return Options.isAllSettingsOpen() && GameState.getVarbit(9656) == openVarbit; } public boolean open() { if(!openAllSettings()){ return false; } if (isOpen()) { return true; } return Query.widgets() .inIndexPath(134) .textEquals(text) .isVisible() .findFirst() .filter(Widget::click) .filter(i -> Waiting.waitUntil(2000, this::isOpen)) .isPresent(); } } public static boolean openAllSettings(){ if(Options.isAllSettingsOpen()){ return true; } if (!Options.closeHouseOptionsTab() || !GameTab.OPTIONS.open()) { return false; } return Query.widgets() .inIndexPath(116) .textEquals("All settings") .isVisible() .findFirst() .filter(Widget::click) .filter(i -> Waiting.waitUntil(2000, Options::isAllSettingsOpen)) .isPresent(); } private static boolean setSetting(AllSettingsTabs allSettingsTabs, String text) { if(!allSettingsTabs.open()){ return false; } return Query.widgets() .inIndexPath(134) .textEquals(text) .findFirst() .map(i -> { return i.scrollTo() && i.click(); }) .orElse(false); } }  Quote Link to comment Share on other sites More sharing options...
SkrrtNick 240 Posted July 6, 2023 Author Share Posted July 6, 2023 ... and there's more!  import lombok.Getter; import java.util.function.BooleanSupplier; public class Option { private String name; private boolean valueToSet; @Getter private boolean isAllSettings; private BooleanSupplier isEnabled; private BooleanSupplier action; public Option(boolean valueToSet, BooleanSupplier isEnabled, BooleanSupplier action) { this.valueToSet = valueToSet; this.isEnabled = isEnabled; this.isAllSettings = false; this.action = action; } public Option(boolean valueToSet, boolean isAllSettings, BooleanSupplier isEnabled, BooleanSupplier action) { this.valueToSet = valueToSet; this.isEnabled = isEnabled; this.isAllSettings = isAllSettings; this.action = action; } public boolean valueToSet() { return valueToSet; } public boolean isEnabled() { return isEnabled.getAsBoolean(); } public boolean shouldChange() { return isEnabled() != valueToSet(); } public boolean changeSetting() { return action.getAsBoolean(); } } import org.tribot.script.sdk.Camera; import org.tribot.script.sdk.Log; import org.tribot.script.sdk.Options; import org.tribot.script.sdk.Waiting; import org.tribot.script.sdk.antiban.PlayerPreferences; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.List; public class OptionsHelper { private List<Option> options; public OptionsHelper(List<Option> options) { this.options = options; } public static class OptionsBuilder { private List<Option> options = new ArrayList<>(); public OptionsBuilder setWindowMode(Options.ResizableType resizableType) { options.add(new Option(true, false, () -> Options.getResizableModeType() == resizableType, () -> Options.setResizableModeType(resizableType))); return this; } public OptionsBuilder setDisableLevelUpInterfaceEnabled(boolean enable) { options.add(new Option(enable, true, OptionsUtility::isDisableLevelUpInterfaceEnabled, () -> OptionsUtility.setDisableLevelUpInterfaceEnabled(enable))); return this; } public OptionsBuilder setAcceptAidEnabled(boolean enable) { options.add(new Option(enable, true, Options::isAcceptAidEnabled, () -> Options.setAcceptAid(enable))); return this; } public OptionsBuilder disableSounds() { options.add(new Option(false, true, Options::isAnySoundOn, Options::turnAllSoundsOff)); return this; } public OptionsBuilder setEscapeClosing(boolean enable) { options.add(new Option(enable, true, Options::isEscapeClosingEnabled, ()-> OptionsUtility.setEscapeClosing(enable))); return this; } public OptionsBuilder setShowActivityAdviserEnabled(boolean enable) { options.add(new Option(enable, true, OptionsUtility::isShowActivityAdviserEnabled, () -> OptionsUtility.setShowActivityAdviserEnabled(enable))); return this; } public OptionsBuilder setAcceptTradeDelayEnabled(boolean enable) { options.add(new Option(enable, true, OptionsUtility::isAcceptTradeDelayEnabled, () -> OptionsUtility.setAcceptTradeDelayEnabled(enable))); return this; } public OptionsBuilder setGrandExchangeBuyWarning(boolean enable) { options.add(new Option(enable, true, OptionsUtility::isGrandExchangeBuyWarningEnabled, () -> OptionsUtility.setGrandExchangeBuyWarning(enable))); return this; } public OptionsBuilder setGrandExchangeSellWarning(boolean enable) { options.add(new Option(enable, true, OptionsUtility::isGrandExchangeSellWarningEnabled, () -> OptionsUtility.setGrandExchangeSellWarning(enable))); return this; } public OptionsHelper build() { return new OptionsHelper(options); } } public boolean setOptions() { if (options.isEmpty()) return true; Collections.shuffle(options); boolean allSettingsFirst = PlayerPreferences.preference("all.settings.first", g->g.uniform(0, 100)) > 50; if (allSettingsFirst){ options.sort(Comparator.comparing(Option::isAllSettings).reversed()); } for (Option option : options) { if(option.shouldChange()){ if (!option.changeSetting()) { return false; } Waiting.waitNormal(300,55); } } if(options.stream().noneMatch(Option::shouldChange)){ if(Options.isAllSettingsOpen()){ Options.closeAllSettings(); } return true; } return false; } } Usage is easy: val options = new OptionsHelper.OptionsBuilder() .setAcceptTradeDelayEnabled(true) .setGrandExchangeBuyWarning(true) .setWindowMode(Options.ResizableType.FIXED) .disableSounds() .setEscapeClosing(true) .build(); options.setOptions(); I'm certain it can be improved upon but it should make for a good start 🙂 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.