Jump to content

Explv

Scripter II
  • Posts

    2314
  • Joined

  • Last visited

  • Days Won

    6
  • Feedback

    100%

Everything posted by Explv

  1. Sorry, I have been on vacation. I do try to fix bugs as they appear. You must understand that this is a massive script, and things do break, it is difficult for me to test absolutely everything myself. A lot of things do work, and I will keep trying to resolve issues that you find. Things may not get fixed instantly, but you should remember that I make no money from this project, and I do have other things going on in my life. That being said, I will try to take a look at these issues over the next few days, now that I am back home. Thanks
  2. If it is your own script, just write to a file instead of the logger. If it isn't, you could run the bot via the command line in debug mode using the -debug flag and then redirect the output to a file by using > logfile.txt at the end of the command. java -jar ....... -debug ..... > logfile.txt
  3. Sorry to be a hater but using null (absolute) layout, and setting fixed sizes for everything is very bad practice. You should be using a layout manager. Class names should start with a capital letter. Instead of passing a reference to your main class, you should just have getters in your GUI to return desired values.
  4. You could try doing something like: Optional<Item> glory = Arrays.stream(getBank().getItems()).filter(item -> item.getName().startsWith("Amulet of glory(")).min((g1, g2) -> g1.getName().compareTo(g2.getName())) Sorry for any syntax errors, on phone
  5. It returns a List<NPC> and you're storing it just as a List. You need to specify the type: List<NPC> npcs = getNpcs().filter(myFilter); Also no need to define your own Filter for this, OSBot already has predefined ones: getNpcs().closest(new NameFilter<>("NPC Name"), new AreaFilter<>(myArea)); Or if you don't care about whether it is the closest one: getNpcs().singleFilter(getNpcs().getAll(), new NameFilter<>("NPC Name"), new AreaFilter<>(myArea));
  6. @XaLeR Looks like maybe you could make use of the spell name field of the widget? RS2Widget goldBraceletWidget = getWidgets().singleFilter(getWidgets().getAll(), w -> w.getSpellName().contains("Gold bracelet"));
  7. It's not an issue, you can do what you want, doesn't mean i'm not allowed to think its weird. And I don't see why me thinking its stupid to travel 12 hours to see a solar eclipse makes me immature.
  8. There is, I just wanted to write it in my own style, without passing MethodProvider as a constructor argument, with a few extra constructors, and without having to explicitly call cache() before getWidget(). I could have just extended yours, but whatever.
  9. Wow, TIL, I had no idea osrs had chatbox commands. Thanks kiddo
  10. You're driving 12 hours... To see a solar eclipse... Wow bro 5 minutes of darkness this is so litttttttttt
  11. It probably shouldn't be. It's marked as internal use only, but l use it in my scripts anyway.
  12. By starting OSBot with the CLI flag -allow norandoms
  13. Explv

    Disabling Audio

    This makes use of my CachedWidget class: https://osbot.org/forum/topic/97399-a-better-way-to-handle-widgets-cachedwidget/ And also my WidgetActionFilter class: https://osbot.org/forum/topic/127248-widget-action-filter/ import org.osbot.rs07.api.ui.Tab; import org.osbot.rs07.event.Event; public final class DisableAudioEvent extends Event { private static final int musicVolumeConfig = 168; private static final int soundEffectVolumeConfig = 169; private static final int areaSoundEffectVolumeConfig = 872; private final CachedWidget soundSettingsWidget = new CachedWidget(new WidgetActionFilter("Audio")); private final CachedWidget musicVolumeWidget = new CachedWidget(new WidgetActionFilter("Adjust Music Volume")); private final CachedWidget soundEffectVolumeWidget = new CachedWidget(new WidgetActionFilter("Adjust Sound Effect Volume")); private final CachedWidget areaSoundEffectVolumeWidget = new CachedWidget(new WidgetActionFilter("Adjust Area Sound Effect Volume")); @Override public final int execute() throws InterruptedException { if (Tab.SETTINGS.isDisabled(getBot())) { setFailed(); } else if (getTabs().getOpen() != Tab.SETTINGS) { getTabs().open(Tab.SETTINGS); } else if (!musicVolumeWidget.get(getWidgets()).isPresent()) { soundSettingsWidget.get(getWidgets()).ifPresent(widget -> widget.interact()); } else if (!isVolumeDisabled(musicVolumeConfig)) { musicVolumeWidget.get(getWidgets()).ifPresent(widget -> widget.interact()); } else if (!isVolumeDisabled(soundEffectVolumeConfig)) { soundEffectVolumeWidget.get(getWidgets()).ifPresent(widget -> widget.interact()); } else if (!isVolumeDisabled(areaSoundEffectVolumeConfig)) { areaSoundEffectVolumeWidget.get(getWidgets()).ifPresent(widget -> widget.interact()); } else { setFinished(); } return 200; } private boolean isVolumeDisabled(final int config) { return getConfigs().get(config) == 4; } } Usage: Event disableAudioEvent = new DisableAudioEvent(); execute(disableAudioEvent);
  14. Alternative much simpler snippet provided by @Deceiver getKeyboard().typeString("::toggleroofs"); If you still want to use the widget interaction way: This makes use of my CachedWidget class: https://osbot.org/forum/topic/97399-a-better-way-to-handle-widgets-cachedwidget/ And also my WidgetActionFilter class: https://osbot.org/forum/topic/127248-widget-action-filter/ import org.osbot.rs07.api.ui.Tab; import org.osbot.rs07.event.Event; public final class ToggleRoofsHiddenEvent extends Event { private final CachedWidget advancedOptionsWidget = new CachedWidget("Advanced options"); private final CachedWidget displaySettingsWidget = new CachedWidget(new WidgetActionFilter("Display")); private final CachedWidget toggleRoofHiddenWidget = new CachedWidget(new WidgetActionFilter("Roof-removal")); @Override public final int execute() throws InterruptedException { if (Tab.SETTINGS.isDisabled(getBot())) { setFailed(); } else if (getTabs().getOpen() != Tab.SETTINGS) { getTabs().open(Tab.SETTINGS); } else if (!advancedOptionsWidget.get(getWidgets()).isPresent()) { displaySettingsWidget.get(getWidgets()).ifPresent(widget -> widget.interact()); } else if (!toggleRoofHiddenWidget.get(getWidgets()).isPresent()) { advancedOptionsWidget.get(getWidgets()).get().interact(); } else if (toggleRoofHiddenWidget.get(getWidgets()).get().interact()) { setFinished(); } return 200; } } Usage: if (!getSettings().areRoofsEnabled()) { Event toggleRoofsHiddenEvent = new ToggleRoofsHiddenEvent(); execute(toggleRoofsHiddenEvent); }
  15. import org.osbot.rs07.api.filter.Filter; import org.osbot.rs07.api.ui.RS2Widget; public final class WidgetActionFilter implements Filter<RS2Widget> { private final String[] actions; public WidgetActionFilter(final String... actions) { this.actions = actions; } @Override public final boolean match(final RS2Widget rs2Widget) { if (rs2Widget == null || !rs2Widget.isVisible() || rs2Widget.getInteractActions() == null) { return false; } for (final String widgetAction : rs2Widget.getInteractActions()) { for (final String matchAction : actions) { if (matchAction.equals(widgetAction)) { return true; } } } return false; } }
  16. You should be demoted REEEEEEEEEE
  17. import org.osbot.rs07.utility.ConditionalSleep; import java.util.function.BooleanSupplier; public final class Sleep extends ConditionalSleep { private final BooleanSupplier condition; public Sleep(final BooleanSupplier condition, final int timeout) { super(timeout); this.condition = condition; } public Sleep(final BooleanSupplier condition, final int timeout, final int interval) { super(timeout, interval); this.condition = condition; } @Override public final boolean condition() throws InterruptedException { return condition.getAsBoolean(); } public static boolean sleepUntil(final BooleanSupplier condition, final int timeout) { return new Sleep(condition, timeout).sleep(); } public static boolean sleepUntil(final BooleanSupplier condition, final int timeout, final int interval) { return new Sleep(condition, timeout, interval).sleep(); } } Usage: Sleep sleep = new Sleep(() -> myPlayer().isAnimating(), 5000); sleep.sleep(); Or: Sleep.sleepUntil(() -> myPlayer().isAnimating(), 5000);
  18. I think it's because the conditional sleep blocks the thread, and so onMessage isn't called until it finishes. Pretty sure ConditonalSleep doesn't cache anything because that would kind of defeat the point...
  19. I can do yeah. Will take a look tonight or tomorrow
  20. How do you fuck up a copy and paste lel
  21. Yeah, you can use the JSON Simple library no problem on the SDN. You just have to include the source (which is only a handful of classes). I have updated the original thread: https://osbot.org/forum/topic/102611-ge-data-get-price-etc-by-item-name-no-external-libraries-required/ And also written a new one that uses the JSON Simple library (probably the preferred way) https://osbot.org/forum/topic/126881-ge-data-using-rsbuddy-json-simple-library/
  22. You will need to include the JSON Simple library in your project (this can also be used on the SDN): https://github.com/fangyidong/json-simple RSExchange.java import org.json.simple.JSONObject; import org.json.simple.parser.JSONParser; import java.io.BufferedReader; import java.io.InputStreamReader; import java.net.URL; import java.net.URLConnection; import java.util.HashMap; import java.util.Map; import java.util.Optional; public final class RSExchange { private final JSONObject ITEMS_JSON; public RSExchange() throws Exception { Optional<JSONObject> itemsJSONOpt = getItemsJson(); if (!itemsJSONOpt.isPresent()) { throw new Exception("Failed to get items JSON"); } JSONObject itemsJSONKeyedByID = itemsJSONOpt.get(); JSONObject itemsJSONKeyedByName = new JSONObject(); for (Object itemValue : itemsJSONKeyedByID.values()) { JSONObject itemValueJSON = (JSONObject) itemValue; itemsJSONKeyedByName.put(itemValueJSON.get("name"), itemValueJSON); } ITEMS_JSON = itemsJSONKeyedByName; } private Optional<JSONObject> getItemsJson() { try { URL url = new URL("https://rsbuddy.com/exchange/summary.json"); URLConnection con = url.openConnection(); con.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36"); con.setUseCaches(true); try (InputStreamReader inputStreamReader = new InputStreamReader(con.getInputStream()); BufferedReader bufferedReader = new BufferedReader(inputStreamReader)) { JSONParser jsonParser = new JSONParser(); return Optional.of((JSONObject) jsonParser.parse(bufferedReader)); } } catch (Exception e) { e.printStackTrace(); } return Optional.empty(); } public final Map<String, ExchangeItem> getExchangeItems(final String... itemNames) { Map<String, ExchangeItem> exchangeItems = new HashMap<>(); for (final String itemName : itemNames) { getExchangeItem(itemName).ifPresent(exchangeItem -> exchangeItems.put(itemName, exchangeItem)); } return exchangeItems; } public final Optional<ExchangeItem> getExchangeItem(final String itemName) { Object itemObj = ITEMS_JSON.get(itemName); if (itemObj == null) { return Optional.empty(); } JSONObject itemJSON = (JSONObject) itemObj; return Optional.of(new ExchangeItem((String) itemJSON.get("name"), (long) itemJSON.get("id"))); } } ExchangeItem.java import org.json.simple.JSONObject; import org.json.simple.parser.JSONParser; import java.io.BufferedReader; import java.io.InputStreamReader; import java.net.URL; import java.net.URLConnection; public final class ExchangeItem { private final String name; private final long id; private long overallAverage = -1; private long buyAverage = -1; private long sellAverage = -1; private long buyingQuantity; private long sellingQuantity; public ExchangeItem(final String name, final long id) { this.name = name; this.id = id; updateRSBuddyValues(); } public final String getName() { return name; } public final long getId() { return id; } public final long getBuyAverage() { return buyAverage; } public final long getSellAverage() { return sellAverage; } public final long getBuyingQuantity() { return buyingQuantity; } public final long getSellingQuantity() { return sellingQuantity; } public void updateRSBuddyValues() { try { URL url = new URL("http://api.rsbuddy.com/grandExchange?a=guidePrice&i=" + id); URLConnection con = url.openConnection(); con.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36"); try (InputStreamReader inputStreamReader = new InputStreamReader(con.getInputStream()); BufferedReader bufferedReader = new BufferedReader(inputStreamReader)) { JSONParser jsonParser = new JSONParser(); JSONObject itemJSON = (JSONObject) jsonParser.parse(bufferedReader); overallAverage = (long) itemJSON.get("overall"); sellAverage = (long) itemJSON.get("selling"); buyAverage = (long) itemJSON.get("buying"); buyingQuantity = (long) itemJSON.get("buyingQuantity"); sellingQuantity = (long) itemJSON.get("sellingQuantity"); } } catch (Exception e) { e.printStackTrace(); } } public final String toString() { return String.format("Name: %s, ID: %d, Overall AVG: %d gp, Buying AVG: %d gp, Selling AVG: %d gp, Buying Quantity: %d, Selling Quantity:%d", name, id, overallAverage, buyAverage, sellAverage, buyingQuantity, sellingQuantity); } } Usage: RSExchange rsExchange = new RSExchange(); Optional<ExchangeItem> exchangeItem = rsExchange.getExchangeItem("Yew logs"); exchangeItem.ifPresent(System.out::println); Prints: Name: Yew logs, ID: 1515, Overall AVG: 355 gp, Buying AVG: 354 gp, Selling AVG: 355 gp, Buying Quantity: 67874, Selling Quantity:72956 Or: Map<String, ExchangeItem> exchangeItems = rsExchange.getExchangeItems("Yew logs", "Iron bar"); exchangeItems.values().forEach(System.out::println); Prints: Name: Yew logs, ID: 1515, Overall AVG: 354 gp, Buying AVG: 354 gp, Selling AVG: 354 gp, Buying Quantity: 47056, Selling Quantity:33141 Name: Iron bar, ID: 2351, Overall AVG: 179 gp, Buying AVG: 182 gp, Selling AVG: 177 gp, Buying Quantity: 2765, Selling Quantity:4467
  23. Right now it just stores the overall price value. I can modify it though to store information. Will update the thread shortly
×
×
  • Create New...