SkrrtNick 243 Posted June 30, 2023 Share Posted June 30, 2023 I wrote these so you can recover if you need to cast a spell that is being filtered. Hope it's helpful ๐ import lombok.AllArgsConstructor; import lombok.val; import org.tribot.script.sdk.GameState; import org.tribot.script.sdk.Magic; import org.tribot.script.sdk.Waiting; import org.tribot.script.sdk.WidgetAddress; import org.tribot.script.sdk.query.Query; import org.tribot.script.sdk.types.Widget; import java.util.Arrays; public class SpellFilter { private static final WidgetAddress spellFilters = WidgetAddress.create(() -> Query.widgets().inRoots(218).isDepth(2).textEquals("Spell Filters").isVisible().findFirst()); private static final int SPELL_FILTERS_ROOT = 218; private static final WidgetAddress spellFilterButton = WidgetAddress.create(() -> Query.widgets().inRoots(SPELL_FILTERS_ROOT).isDepth(3).textEquals("Filters").isVisible().findFirst()); /** * Checks if any spell filter is enabled * * @return true if a spell filter is enabled, false otherwise */ public static boolean isSpellsFiltered() { return Arrays.stream(Filter.values()).anyMatch(Filter::isFiltered); } /** * Opens the spell filters widget * * @return true if the spell filters widget is opened, false otherwise */ public static boolean openSpellFilters() { if (Magic.isSpellFiltersOpen()) { return true; } if (!org.tribot.script.sdk.GameTab.MAGIC.open()) { return false; } if (!Magic.isSpellFiltersOpen() && !spellFilterButton.lookup().map(Widget::click).orElse(false)) { return false; } return Waiting.waitUntil(4000, Magic::isSpellFiltersOpen); } /** * Toggles the specified spell filter * * @param filter the filter to toggle * @return true if the filter is toggled, false otherwise */ public static boolean toggleFilter(Filter filter) { if(!openSpellFilters()){ return false; } val priorState = filter.isFiltered(); if(!spellFilters.lookup().flatMap(i -> i.getChild(filter.widgetIndex)).map(i -> i.click("Change")).orElse(false)){ return false; } return Waiting.waitUntil(4000, ()-> filter.isFiltered() != priorState); } @AllArgsConstructor public enum Filter { COMBAT_SPELLS(6605, 0), TELEPORT_SPELLS(6609, 1), UTILITY_SPELLS(6606, 2), MISSING_LEVEL(6607, 3), MISSING_RUNES(6608, 4), MISSING_REQUIREMENTS(12137, 5), ICON_RESIZING(6548, 6); private final int varbit; private final int widgetIndex; public boolean isFiltered() { return GameState.getVarbit(varbit) == 1; } } } I also have the varbits and an isFiltered method for prayer, I didn't get as far as making a toggle, but I could if anyone needs it ๐ @AllArgsConstructor public enum Filter { LOWER_TIERS(6574), LOWER_TIERS_MULTISKILL(6575), RAPID_HEALING(6576), MISSING_LEVEL(6577), MISSING_REQUIREMENTS(6578); private final int varbit; public boolean isFiltered() { return GameState.getVarbit(varbit) == 1; } } ย Quote Link to comment Share on other sites More sharing options...
geo 1 Posted June 30, 2023 Share Posted June 30, 2023 Thanks for this Quote Link to comment Share on other sites More sharing options...
SkrrtNick 243 Posted June 30, 2023 Author Share Posted June 30, 2023 15 minutes ago, geo said: Thanks for this Youโre welcome!ย 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.