Jump to content

Purple

Members
  • Posts

    508
  • Joined

  • Last visited

  • Days Won

    1
  • Feedback

    100%

Posts posted by Purple

  1. If you have web development knowledge, then scripting should be really easy for you pick up. 

     

    Firstly, you want to pick out an IDE; IntelliJ, Eclipse

     

    Once you've installed Java JDK 8.0+, open up your IDE and create a new project. For now you should ignore basic scripting and learn to do simple tasks in raw java such as; hello world, printing data types and objects, understanding of methods and their return types, parameters, fields, and constructors, and most importantly, understanding object references in memory. Once you're able to make a basic java application that can successfully use the core basics of Java, only then should you attempt to make a basic script. Understanding object references and their return types is going to save you a lot of headache when you're first starting to script.

     

    1. keywords  
    2. primitive data types
    3. method structure
    4. parameters
    5. fields
    6. constructors

     

    That's just to scratch the surface, but you can write a basic script with only knowledge of keywords, primitives, and method structure. The rest is only needed for more complex scripts. 

     

    If you're a visual learner, then I suggest watching Bucky's Java tutorial series on YouTube up to at least video 35 for a good grasp on how to make an intermediate script. 

     

    Good luck

    • Like 1
  2. You didn't mention anything about execution time, you think it will be faster then a regular Filter? smile.png

     

    Khaleesi

     

    You're right, but we're talking about nano seconds here :P

     

    It's not going to make a difference when it comes to RuneScape scripting. However, streams are a little bit slower than iterating over a collection using an iterator, but I'd rather have functionality and clarity of minimal performance when it comes to writing scripts. Some value speed over quality of life. Nice point out though. 

    • Like 1
  3. Introduction To Predicates

     

    What is a Predicate in Java 8?

    A predicate is a boolean-valued function. In Java 8, it's used primarily for it's functional properties as well as it's ability to result in a true or false statement. This is really useful when you need to filter collections without having to loop over a collection manually as the stream api allows you to also chain predicates.

    P: X→ {true, false}

    P being the predicate (value or reference passed in) and X represents the following truth statement resulting in true or false. This might be confusing at first, but I'll show examples later on how this makes sense and why you should use this over the commonly used Filter<T> in OSBot.

     

    How is this any better than OSBot's Filter<T> api?

    We can use predicates to chain logic expressions and filter as many conditions as me need to while keeping our logic nice and clean. We can combine two pedicates where we filter a collection where both condition are met or return the second if the first predicate returns false. 

     

     

    Collection of Loaded NPS

     

    List<NPC> where we'll be performing our filter

    final List<NPC> loaded = getNpcs().getAll();
    

    create a list of all loaded npcs in the area

     

     

    Simple Predicate Filtering

     

    A Predicate

    final Predicate<NPC> exists = npc -> npc.exists();

    This creates a predicate with the truth statement P(npc) : return true if npc exist

     

    Using it inside a stream to filter a collection

    final NPC getNpcWhere = loaded.stream().filter(exists).findFirst().orElse(null)

    This will return the first match in the collection that matches the predicate truth statement that returned true or else returns a null NPC object.

     

     

     

    Chaining Predicates

     

    Two Predicates we're going to chain

    final Predicate<NPC> exists = npc -> npc.exists();
    final Predicate<NPC> isAttackable = npc -> npc.exists() && npc.hasAction("Attack") && !npc.isUnderAttack();

    Predicate Chain were 2 Predicates return true

    final NPC getNpcWhere = loaded.stream().filter(exists.and(isAttackable)).findFirst().orElse(null);

    Here, we're simply chaining preidicates. We're filtering the collection where the the npc exists and it's attackable and if both 

     

    This or That Predicates

     

    Three Predicates we're going to chain

    final Predicate<NPC> exists = npc -> npc.exists();
    final Predicate<NPC> isInteractingLocally = npc -> npc.isInteracting(getPlayers().myPlayer());
    final Predicate<NPC> isAttackable = npc -> npc.exists() && npc.hasAction("Attack") && !npc.isUnderAttack();
    

    Alright, this is where the magic happens in a combat script! We can create 1 predicate query that should always return true then either return the second one or the third depending on the second returns true or not.

     

    The logic behind this one is that in a combat script, you'd obviously want to return npcs attacking you before you attack a random npc right? So you can achieve this by doing a predicate or function.

     final NPC getNpcWhere = loaded.stream().filter(exists.and(isInteractingLocally.or(isAttackable))).findFirst().orElse(null);
    

    We just made a really advanced logic filter in 1 line of code!

     

    That's the power of using Predicates over a generic Filter<T>

    • Like 9
  4. Changes your OSBot frame title to show your current IP address of your bot.

     

    Source

    import org.osbot.rs07.script.Script;
    import org.osbot.rs07.script.ScriptManifest;
    
    import javax.swing.*;
    import java.awt.*;
    import java.io.BufferedReader;
    import java.io.InputStreamReader;
    import java.net.URL;
    
    @ScriptManifest(author = "Purple", name = "IP Display Changer", version = 1.01, info = "Changes the title of your osbot to display your bots IP address.", logo = "")
    public class Display extends Script {
    
        @Override
        public int onLoop() throws InterruptedException {
            changeFrameTitle("OSBot (" + getCurrentIPAddress() + ")");
            stop(false);
            return 0;
        }
    
        public void changeFrameTitle(final String title) {
            for(Frame frame : Frame.getFrames()) {
                if(frame.isVisible() && frame.getTitle().startsWith("OSBot")) {
                    SwingUtilities.invokeLater(() -> frame.setTitle(title));
                    break;
                }
            }
        }
    
        public String getCurrentIPAddress() {
            try {
                URL url = new URL("http://myip.dnsomatic.com/");
                BufferedReader b = new BufferedReader(new InputStreamReader(url.openStream()));
                String ip = b.readLine();
                b.close();
                return ip;
            } catch (Exception e) {
                e.printStackTrace();
            }
            return "null";
        }
    }
     

    Aaes83X.png

    • Like 9
  5. Made this awhile back, but I don't really PK anymore. (pretty fun account ability to combo 30+ maul 25 dfs 18 venom)

     

    Pretty much all the hard work is done just needs gloves

     

    59 combat

    64 hitpoints

    5 attack

    72 strength

    75 defence

     

    noteable skills

    99 fishing

    72 agility

    50 con

     

  6. Please make sure they are under this directory

    C:\Users\#USERNMAE_HERE\OSBot\scripts
    

    Also, make sure the scripts you are downloading are currently working or if you're making your own scripts, then make sure they have a script manifest in order for the bot to correctly parse the script. 

  7. If you are going to do something like this, then you should probably have it running on a separate thread s your bot doesn't just sit there doing nothing. Might be more realistic than just straight up logging out when a JMod is around, but it still doesn't look good if all bots in one area just stood still. 

  8. I don't see why someone cant be a head admin of two different communities. However, he did always seem lazy and couldn't take the pressure of dealing with everything. Cya in 2 weeks when he becomes admin again for the third time. 

    • Like 2
×
×
  • Create New...