Jump to content

Explv

Scripter II
  • Posts

    2314
  • Joined

  • Last visited

  • Days Won

    6
  • Feedback

    100%

Everything posted by Explv

  1. I'm going to have a long bug fixing session this weekend, so I hope to have these issues addressed Which fishing spot was this? I will fix it this weekend if you provide more information, thanks Addressing these this weekend. Will post again when fixed. Sorry (again) for the delay, have been extremely busy. I have free'd up the whole weekend to get all of these issues sorted. Thanks
  2. @@Th3's method is the same one that I use
  3. Yes most people do use gui builders, and I recommend using one. This tutorial is so that people understand the basics, so that they don't just use a gui builder and have no idea what any of the code it generates does.
  4. Arrays.stream(getInventory().getItems()) .filter(Objects::nonNull) .distinct() .map(item -> String.format("Item: %s Amount: %d", item.getName(), getInventory().getAmount(item.getName()))) .forEach(this::log); The above is equivalent to: // Get all inventory items as an Item[] Item[] inventoryItems = getInventory().getItems(); // Create a Stream of Items from the Item[] Stream<Item> itemStream = Stream.of(inventoryItems); // Remove any Item from the Stream that is null Stream<Item> itemStreamNoNull = itemStream.filter(item -> item != null); // Get only the unique Items from the Stream Stream<Item> uniqueItems = itemStreamNoNull.distinct(); // Convert each Item to a String containing the item name & amount Stream<String> itemTexts = uniqueItems.map(item -> "Item: " + item.getName() + " Amount: " + getInventory().getAmount(item.getName())); // For each String, log it on the console itemTexts.forEach(itemText -> log(itemText)); Hope that helps
  5. You could add a JLabel with an icon set like so: JLabel jLabel = new JLabel(); try { Image image = ImageIO.read(YourClass.class.getResourceAsStream("/resources/image.png")); ImageIcon imageIcon = new ImageIcon(image); jLabel.setIcon(imageIcon); } catch (IOException e) { e.printStackTrace(); } Or you could add a custom JPanel with its paintComponent method overriden: public final class ImagePanel extends JPanel { private final BufferedImage image; public ImagePanel(final String imagePath) { image = ImageIO.read(ImagePanel.class.getResourceAsStream(imagePath)); } @[member=Override] public final void paintComponent(final Graphics g) { super.paintComponent(g); g.drawImage(image, 0, 0, image.getWidth(), image.getHeight(), null); } }
  6. Or you could do something like: Arrays.stream(getInventory().getItems()) .filter(Objects::nonNull) .distinct() .map(item -> String.format("Item: %s Amount: %d", item.getName(), getInventory().getAmount(item.getName()))) .forEach(this::log);
  7. Most editors will insert spaces when you press the tab key, if it doesn't you should set it so that it does. Tabs are generally bad in programming because different editors will insert different amounts of whitespace for a tab. So when viewing your code it can look completely different. That clip from Silicon Valley is bullshit because no one sits there pressing the space key, as their tab key inserts spaces rather than tabs.
  8. The data is retrieved in the format: {"overall":369,"buying":372,"buyingQuantity":108551,"selling":367,"sellingQuantity":121543} Using a URL such as: http://api.rsbuddy.com/grandExchange?a=guidePrice&i=1515 The following method retrieves the "overall" value: private Optional<Integer> getRSBuddyPrice(){ 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"); con.setUseCaches(true); BufferedReader br = new BufferedReader(new InputStreamReader(con.getInputStream())); String json = br.readLine(); br.close(); Matcher matcher = Pattern.compile("\"overall\"\\s*:\\s*(\\d*)").matcher(json); return matcher.find() ? Optional.of(Integer.parseInt(matcher.group(1))) : Optional.empty(); } catch(Exception e){ e.printStackTrace(); } return Optional.empty(); } If you wanted to retrieve all of these data items, you can just alter this method to instead return a Map<String, Integer>, and instead of just doing: Matcher matcher = Pattern.compile("\"overall\"\\s*:\\s*(\\d*)").matcher(json); return matcher.find() ? Optional.of(Integer.parseInt(matcher.group(1))) : Optional.empty(); Which gets the "overall" value, you can do this for "buying", "selling" etc. and add it to the Map. I will write this up when I get home if you aren't sure how to do it.
  9. Explv

    JavaFX

    Just so you know, because you are running JavaFX from a Swing application you don't need to extend the application class. https://docs.oracle.com/javase/8/javafx/interoperability-tutorial/swing-fx-interoperability.htm
  10. I c, @op have you tried using getBank().open() ?
  11. Well isn't it a deposit box not a bank at the barbarian outpost?
  12. I'll fix it when I get home, I am away on holiday at the moment.
  13. I'll take a look at it this weekend, thanks
  14. You're welcome. I don't think that the AudioListener class is even listed on the API, so your search would have been futile.
  15. You can add an AudioListener like so: getBot().addAudioListener(i -> {}); Haven't used it before so I'm not too sure what the integer value is, might be the id of the track. What exactly are you trying to achieve?
  16. Good to hear you're enjoying the script. Sorry about the slow updates I have been very busy at work. I'll take a look at this issue this weekend for you. Thanks.
  17. Google Maps JavaScript API? https://developers.google.com/maps/documentation/javascript/examples/polyline-simple
  18. So this is a snippet I wrote as a reply to a thread, but it's pretty buried and some people may find it useful: public final void typeStringInstant(final String output){ for(int i = 0; i < output.length(); i ++){ getBot().getKeyEventHandler().generateBotKeyEvent(KEY_TYPED, System.currentTimeMillis(), 0, VK_UNDEFINED, output.charAt(i)); } getBot().getKeyEventHandler().generateBotKeyEvent(KEY_TYPED, System.currentTimeMillis(), 0, VK_UNDEFINED, (char) VK_ENTER); }
  19. Why would you need to know that? I'm assuming you want to know how long to sleep for, if not, disregard this: The simplest way to sleep until a fire is lit, is to sleep until the player's position has changed. The player always moves after lighting a fire, so you can just do something like: Position currentPos = S.myPosition(); if(S.getInventory().getItem("Logs").interact()) { new ConditionalSleep(15_000) { @ Override public boolean condition() throws InterruptedException { return !S.myPosition().equals(currentPos) && !S.myPlayer().isMoving(); } }.sleep(); }
  20. Instead of checking if your player is under attack (the chicken might not be fighting back), instead you can check if your player is interacting with a Chicken. Also, in your ConditionalSleep, considering it takes time for your player to walk to the chicken, and another player might attack it first, you should check in your sleep condition if the chicken is under attack, or dead etc. Consider this short example (untested): import org.osbot.rs07.api.filter.NameFilter; import org.osbot.rs07.api.model.NPC; import org.osbot.rs07.script.Script; import org.osbot.rs07.script.ScriptManifest; import org.osbot.rs07.utility.ConditionalSleep; @ScriptManifest(name = "Chicken Killer", info = "Kills Chickens...", author = "Explv", version = 0.1, logo = "") public final class ChickenKiller extends Script { private NPC currentChicken; @[member='Override'] public final int onLoop() throws InterruptedException { if(!isAttackingChicken()) attackChicken(); return random(150, 200); } private boolean isAttackingChicken() { return currentChicken != null && currentChicken.exists() && currentChicken.getHealthPercent() > 0 && myPlayer().isInteracting(currentChicken) && currentChicken.isUnderAttack(); } private void attackChicken() { currentChicken = getClosestChicken(); if(currentChicken != null && currentChicken.interact("Attack")) { new ConditionalSleep(5000) { @[member='Override'] public boolean condition() throws InterruptedException { return myPlayer().isInteracting(currentChicken) || !isAttackableTarget(currentChicken); } }.sleep(); } } private NPC getClosestChicken() { return getNpcs().closest( new NameFilter<>("Chicken"), this::isAttackableTarget ); } private boolean isAttackableTarget(final NPC target) { return target != null && target.exists() && target.getHealthPercent() > 0 && !target.isUnderAttack(); } }
×
×
  • Create New...