Jump to content

Explv

Scripter II
  • Posts

    2314
  • Joined

  • Last visited

  • Days Won

    6
  • Feedback

    100%

Everything posted by Explv

  1. Explv's Scripting 101 Prerequisite: basic knowledge of Java 1. Setting up the Java Development Kit and an Integrated Development Environment (IDE) 2. The Script Skeleton 3. Building the script 4. The Script class continued 5. The MethodProvider class, accessing the Inventory, Bank, Player, etc. instances 6. Positions, areas and moving the player 7. Entities (Players, RS2Objects, NPCs and GroundItems) 8. Interactions 9. Sleeping 10. Items and ItemContainers (Inventory, Bank, Equipment, Store, ...) 11. Filtering 12. Widgets 13. Configs 14. Adding a paint 15. Putting it all together, an example script (Smelting iron bars in Al-kharid) 16. Adding a GUI
  2. http://www.userbenchmark.com/UserRun/2713886
  3. I could probably add something to ssh into a VPS and run the commands, i'll see what I can do when I have some free time
  4. Agreed, this is over complicated. Either of these options would suffice: Where the message is: String lootMessage = "<col=ef1020>Valuable drop: Onyx (3,038,047 coins)</col>"; Matcher m = Pattern.compile(": (.+) \\(").matcher(lootMessage); if (m.find()) { String loot = m.group(1); } or String loot = lootMessage.substring(lootMessage.indexOf(": ") + 2, lootMessage.lastIndexOf(" ("));
  5. You probably declared your JComboBox like: JComboBox comboBox = new JComboBox(); When it should be: JComboBox<Type> comboBox = new JComboBox<>(); Where "Type" is whatever type script.getTrees() returns
  6. 1. Generally you should try and avoid the use of static unless you are absolutely sure it is correct to use it, and makes sense to use it. A static method belongs to the class and not any instance of the class. It is commonly used for utility methods, another example of it's use would be in the Singleton Pattern. You will find a lot of amateur programmers abusing the static keyword due to their lack of understanding of OOP. 2. You are probably getting this warning because you are using raw types, read a tutorial on Java generics 3. An Enum is a class, it can still have methods etc. It is generally used when you want to specify a fixed list of constants. For example you may have a Tree Enum that specifies a fixed list of Trees someone can choose from in your script. TL;DR Follow some more tutorials and learn some more Java
  7. Optional<NPC> npcOpt = getNpcs().getAll() .stream() .filter(n -> n.getName().equals("NPC Name") && n.getPosition().distance(myPosition()) > 2) .min((n1, n2) -> Integer.compare(n1.getPosition().distance(myPosition()), ​n2.getPosition().distance(myPosition()))); Explanation: Construct a Stream<NPC> of all the NPCs around the Player Filter the Stream<NPC> so that only the NPCs who's name matches "NPC Name" and is more than two tiles away from the player remain Apply the min function to the Stream<NPC> using a custom comparator that compares distances from the player (essentially returns the closest NPC to the player) Returns an Optional<NPC> With the return value of Optional<NPC>, instead of null checking you do something like: npcOpt.ifPresent(npc -> { }); For more information on the Optional class see https://docs.oracle.com/javase/8/docs/api/java/util/Optional.html For more information on streams see http://www.oracle.com/technetwork/articles/java/ma14-java-se-8-streams-2177646.html and https://docs.oracle.com/javase/8/docs/api/java/util/stream/Stream.html
  8. getBank().depositAllExcept(item -> item.getName().endsWith(" axe"));
  9. In this case a JCheckBox would make more sense, however, if you want to use a JComboBox, this works: JComboBox<String> optionSelector = new JComboBox<>(new String[]{ "Yes", "No" }); To check if "Yes" is selected: boolean yesSelected = optionSelector.getSelectedItem().toString().equals("Yes");
  10. In this case I would probably just make your method throw an InterruptedException.
  11. getBank().open() Throws an InterruptedException. You either need to catch the exception or make your method throw an InterruptedException as well
  12. Firstly the answers to your questions: If i make a GUI, should it be in a separate class? It's up to you, it would be cleaner if it was in a separate class. Am I using ConditionalSleep correctly? Yes and no, the ConditionalSleep itself is fine, but you are calling it in the wrong place. You should only call the ConditionalSleep after you have checked the tree is not null and also after you have checked the interaction with the tree was successful. Otherwise your script will sleep when it shouldn't. Would using States make this script better? No, personally I don't think anyone should use States, because you are separating the condition from the action, which just makes it harder to read. I think that when your script becomes more complex, you should separate it out into classes and methods accordingly. If I have a complex script, should I put all my functions in a separate module? I don't understand what you mean by this question, consider reading some basic OOP tutorials. Other issues I can see looking at your code: Remove the onStart() and onEnd() methods considering you aren't doing anything useful in them Declare the Area lumbridgeTrees as a private global variable so that you aren't redefining it every time onLoop is called After you do the check for if the inventory is full, I would probably make the next if statement an else if You don't need to web walk to a random position in the Area lumbridgeTrees, just call webWalk(lumbridgeTrees) You probably want to check if the player should chop a new tree (your ableToWork()) method before finding a new Tree, otherwise you are just constantly looking for the closest tree when you don't even want to chop it. You should only perform the conditional sleep after the .interact("Chop down") method has returned true. You should return boolean instead of Boolean from the method ableToWork() You should follow Java naming conventions, (the name of your class should start with an uppercase letter). Also, although it doesn't particularly matter in this context, I would give your Script class a better name than "Main", perhaps "Woodchopper" would be more appropriate.
  13. Just do something like: if (myPlayer().getInteracting() == null) { NPC cow = getNpcs().singleFilter(getNpcs().getAll(), new NameFilter<>("Cow"), Character::isAttackable); if (cow != null && cow.interact("Attack")) { new ConditionalSleep(5000) { @ Override public boolean condition() throws InterruptedException { return myPlayer().isInteracting(cow) || !cow.isAttackable(); } }.sleep(); } }
  14. I don't use Eclipse but I believe that you need to set the compliance level to 1.8 under the compiler section in properties
  15. Ok, I didn't actually test the client closing on linux, I just wrote it and prayed. I'll fix it asap.
  16. There is a bug I need to fix for usernames with a space in them, for now use "Hi G00gle" as your username (with the quotes). I will fix this in the next version
  17. Check the log (right click the configuration and select view log) if it says the script stopped then it's an issue with your script. The logs will remain until you start the configuration again so you can check them
  18. You don't need to make a duplicate thread. Just edit your first one
  19. Issue fixed, user was using openJDK, installed oracle JDK instead
  20. Try Image image = ImageIO.read(URL);
  21. Did you even define the method getImage?
×
×
  • Create New...