Understanding RSBot scripting. [Java]

Discussion in 'Archives' started by Rawr, Sep 17, 2009.

Understanding RSBot scripting. [Java]
  1. Unread #1 - Sep 17, 2009 at 7:16 PM
  2. Rawr
    Joined:
    Jul 18, 2008
    Posts:
    2,442
    Referrals:
    9
    Sythe Gold:
    8
    Pokémon Trainer

    Rawr Addict.
    Retired Sectional Moderator $100 USD Donor

    Understanding RSBot scripting. [Java]

    Everyone at some point has used RSBot, and if you're anything like me you're wondering "How the hell do I make my own script?" Well, here I'm going to show you some of the basics to get you started!

    First off -
    You're going to have a simple template; like below for example...

    Code:
    //Imports
    
    @ScriptManifest(authors = { "YourName" }, category = "ScriptCategory", name = "Script Name", version = 1.00, description = "<html><head></head><body>Script description here.</body></html\n")
    public class YourScriptName extends Script implements PaintListener {
    
        public boolean onStart(Map<String, String> args) {
            return true;
        }
    
        public int loop() {
            return 100;
        }
           
        public void onRepaint(Graphics g) {
            if(isLoggedIn()) {
                //Paint Here.
            }
        }
        
        public void onFinish() {
            log("Your Script Name has finished");
        }
    }
    
    Now, this may all look very confusing at first. But I'll go through and explain all of the sections.

    Section 1) The Imports.
    What an Import basically is, is a line of code that is grabbing information from a package allowing you to collect the methods from that class and be able to implement them in your script.

    Note: If there's a * at the end of the import before the semi-colon that means the script is going to import EVERYTHING from that file.

    • import java.awt.*;
    • import java.util.*;
    • import java.util.List;
    • import java.util.logging.Level;
    • import javax.accessibility.*;
    • import javax.swing.*;
    • import org.rsbot.bot.Bot;
    • import org.rsbot.script.*;
    • import org.rsbot.script.wrappers.*;
    • import org.rsbot.accessors.*;
    • import org.rsbot.event.listeners.PaintListener;
    • import org.rsbot.event.listeners.ServerMessageListener;
    • import org.rsbot.event.events.ServerMessageEvent;

    These are the basic imports allowing you to start your first script.

    Section 2) The name.
    The name of your script is very important, because this name be EXACTLY what you save the file as. Example... If I were to save it as Template.java I MUST name the script "Template".

    Code:
    public class YourScriptName extends Script implements PaintListener {
    So, in here I'm starting with public class because it's a file for everyone to see, aka public. Then there is the name! "SCRIPT-NAME-HERE". This is where the name of your script goes, you need to change it to the name of you'd like the script to be, just make sure you save the script with that exact name (with .java after). Then after that your script is just gathering the implements the Paint (The graphics presenting data in your bot). Then there is the { bracket which is starting the script code. For every { bracket you must close it with a }.

    Section 3) Details of your script.

    RSBot has updated this to @ScriptManifest, I personally like it a lot better than the old stuff.

    Code:
    @ScriptManifest(authors = { "YourName" }, category = "ScriptCategory", name = "Script Name", version = 1.00, description = "<html><head></head><body>Script description here.</body></html\n")
    
    Here we're providing all of the details about your script, name, author, description, etc. This is probably the easiest part of your entire code. To break it down...
    Code:
    authors = { "YourName" }
    This is collecting the creators name. AKA you.
    Code:
    category = "ScriptCategory"
    This is collecting what category your script will go under, such as "Mining" for example. (Case sensitive)
    Code:
    name = "Script Name"
    This is collecting the name of your script. This is the title you will be displaying for people to see while selecting to run a bot.
    Code:
    version = 1.00
    This will collect what version the script code is, version is a "double" variable, which means it will have a decimal.
    Code:
    description = "<html><head></head><body>Script description here.</body></html\n")
    This is going to Present the data @ScriptManifest has collected in an HTML output. Basic HTML knowledge is required for this part. All of your data must go in between the <body>Right here</body> tags. Provide a brief explanation of what your bot does, and if you have selections, or options put them in here.

    Section 4) Starting up.
    Code:
        public boolean onStart(Map<String,String> args) {
            return true;
        }
    This part of your code is going to get any last minute information needed before the script starts, such as GE Prices, Locations, Skills, etc. Once it's collected all of the information, your script will start.

    Section 5) The loop!
    The loop is where all of your code that's going to run your bot will be. The loop is basically the brains of your script. You can either do a) Put your IF statements inside the loop, or b) make your methods outside it, and declare it in the loop afterwords. I'll do examples of both below... The example will detect if your characters run is greater than 50, and if it is, it will turn it on.

    Note: When doing Comments in your code you can either do "//" for commenting 1 line of code, or "/* */" for multiple lines of code.

    Note 2: After every line that doesn't end in {, } or : You must end it with a semi-colon ";".

    Code:
        /* Option B
            public int turnRunOn(){
            if(getEnergy > 50){
                  setRun(true);
            }
       */
    
        public int loop() {
            //Option A
            if(getEnergy > 50){
                  setRun(true);
            }
    
            //Continue of option B
            turnRunOn();
            return random(500, 800);
        }
    Oh yeah, another thing to mention, whenever you see a "return #;" that just means your script is going to wait that # of milliseconds before going on the the next step. Example... 1000 = 1 second. Another thing to mention, if you try to return a negative int such as -1 it will stop your loop, therefore stopping the script.


    Section 6) Some basic code to work with.
    Here I'm going to give you a few lines of basic code to help you start out making a bot.
    log();
    Code:
    log("Hello, it's Rawr Im Phat");
    log is an output statement that will appear in the description box below your bot. It's useful for declaring what your bot is doing at a certain time. You start out with log( then quotes to let the bot know we're putting in a string variable such as above "Hello, it's Rawr Im Phat." then you're going to close it with a ) and end the line with a semi-colon. ;

    atNPC();
    Code:
    RSNPC npcName = getNearestNPCByID(id#);
    atNPC(npcName, "String action");
    
    Ok, here we are declaring a final variable for the bot to read which is the RSNPC npcName = getNearestNPCByID(id#); part. We start off my stating that it's an RSNPC and we give it a name npcName. Then we have it = getNearestNPCByID(id#); to search for the nearest NPC by you. Then with our atNPC statement we're going to use that name we made npcName then tell it what to do where it says String action. This can be "Attack" "Teleport" "Trade", whatever is needed.

    atObject();
    Code:
    RSObject objectName = getNearestObjectByID(id#);
    atObject(objectName, "String action");
    
    This is very similar to atNPC but we're just doing an object, such as a bankBooth or ironRocks, but if you want to do a bot for woodcutting I suggest you use atTree instead of atObject. For string actions you could do anything such as "Mine" "Chop" "Take", etc.

    Section 7) Finishing up.
    Code:
    public void onFinish() {
        log("Thanks for using my tutorial!");
        }
    Simple part of the script, you're basically just telling the bot what to shutdown before the entire script stops, and you could put a log Message of what your bot did, etc. Example... Lets say you made a Woodcutting bot and you cut a certain number of logs, you could put that information in here of what you did.

    Section 8) The Paint.
    This is the funnest part of the script because it's what makes your script unique in my opinion. Here is where you put all of your progress information such as, exp gained, skill training, exp till next level, time running, etc.

    An example of some of the paint opportunities:
    Code:
        //Declare colors
        //You use RGB coloring.
        final Color colorName = new Color(R, G, B); 
        
        //Setting Colors 
        g.setColor(colorName); 
        
        //Filling a region
        g.fill3DRect(x, y, height, width, true);
    
        //Outputing data on your paint.
        g.drawString("Content here.", x, y); 
    
    For more on paint read here: Graphics

    Well, that's about it for now, I'll refine it more as I read through it.

    ©RawrImPhat
     
  3. Unread #2 - Sep 22, 2009 at 1:42 PM
  4. SuF
    Joined:
    Jan 21, 2007
    Posts:
    14,212
    Referrals:
    28
    Sythe Gold:
    1,234
    Discord Unique ID:
    203283096668340224
    <3 n4n0 Two Factor Authentication User Community Participant Spam Forum Participant Sythe's 10th Anniversary

    SuF Legend
    Pirate Retired Global Moderator

    Understanding RSBot scripting. [Java]

    Good for starters, but everything could be explained much more... But that would lead to a huge guide... But still good to read before so people have a better idea what questions they need answered if they want to learn... But. Good guide. Obviously.
     
  5. Unread #3 - Sep 22, 2009 at 10:19 PM
  6. Inventor
    Referrals:
    0

    Inventor Guest

    Understanding RSBot scripting. [Java]

    Can you do that with other bots using the same template?

    Also very nice guide, I'm going to need to start using it once RSBOT comes back up.
     
  7. Unread #4 - Sep 23, 2009 at 4:33 PM
  8. Rohail
    Joined:
    Jun 11, 2009
    Posts:
    2,751
    Referrals:
    2
    Sythe Gold:
    0

    Rohail The MiddleMan
    Banned

    Understanding RSBot scripting. [Java]

    Very good guide. I'm trying to learn how to script so really helped. 10/10.
     
  9. Unread #5 - Oct 8, 2009 at 12:53 AM
  10. Snow Patrol
    Joined:
    Jan 23, 2009
    Posts:
    6,538
    Referrals:
    7
    Sythe Gold:
    18

    Snow Patrol Emeritus

    Understanding RSBot scripting. [Java]

    nice guide, help me a bit

    I love your sig ;o
     
  11. Unread #6 - Oct 8, 2009 at 12:55 AM
  12. claw bogy
    Joined:
    Jan 28, 2007
    Posts:
    1,940
    Referrals:
    5
    Sythe Gold:
    0

    claw bogy Guru
    Banned

    Understanding RSBot scripting. [Java]

    Thanks, this is pretty cool.
     
  13. Unread #7 - Dec 1, 2009 at 12:39 AM
  14. Rawr
    Joined:
    Jul 18, 2008
    Posts:
    2,442
    Referrals:
    9
    Sythe Gold:
    8
    Pokémon Trainer

    Rawr Addict.
    Retired Sectional Moderator $100 USD Donor

    Understanding RSBot scripting. [Java]

    Updated new code and more explaining of everything!
     
  15. Unread #8 - Dec 11, 2009 at 3:13 PM
  16. Silrisil
    Joined:
    Aug 24, 2009
    Posts:
    813
    Referrals:
    4
    Sythe Gold:
    0

    Silrisil Apprentice

    Understanding RSBot scripting. [Java]

    Are there 2 "sections 4"?
    It seems that it isn't that hard how I thought. I will try to use it when I finish my current task (forum).
     
  17. Unread #9 - Dec 11, 2009 at 9:26 PM
  18. Raid500
    Joined:
    Feb 11, 2007
    Posts:
    592
    Referrals:
    1
    Sythe Gold:
    0

    Raid500 Forum Addict

    Understanding RSBot scripting. [Java]

    Eh, it's alright, but if you don't know this, I doubt you would be looking into making scripts, well ones people will use.
     
  19. Unread #10 - Dec 11, 2009 at 9:44 PM
  20. Jimmy
    Joined:
    Jun 24, 2008
    Posts:
    2,421
    Referrals:
    10
    Sythe Gold:
    25

    Jimmy Ghost
    Retired Sectional Moderator $5 USD Donor

    Understanding RSBot scripting. [Java]

    This is a fairly good guide to get people interested in rsbot scripting.

    A few suggestions, however:
    • Change "file" and "folder" to class and package, as class does not import a file, it imports a different class.
    • SCRIPT-NAME-HERE isn't a very good choice of an example class name, as a class name cannot contain a dash (-)
    • Do a bit more explaining about ScriptManifiest, and on how annotations like it work.
    • Explain that if the loop returns -1, then the script will stop its execution.
    • Perhaps add a link to the Sun Javadoc for java.awt.Graphics (located here) so that a scripter can see all of the things that they can do with the Graphics that were passed as an arg in the onRepaint() method.
    • Add a few basic methods of rsbot so that the new scripters know a few basic methods to work with (i.e. log(), findObject(), atObject(), atTile(), etc.).

    Overall, I think that this is a great guide to get new people into rsbot scripting, and, with a bit of improvement, can be an extremely helpful resource to these people.
     
  21. Unread #11 - Dec 12, 2009 at 12:11 AM
  22. drainingpower
    Joined:
    Jan 15, 2008
    Posts:
    1,166
    Referrals:
    0
    Sythe Gold:
    0

    drainingpower Guru

    Understanding RSBot scripting. [Java]

    Very good guide, I must say, great job. It is much use to me.
     
  23. Unread #12 - Dec 17, 2009 at 11:23 PM
  24. Rawr
    Joined:
    Jul 18, 2008
    Posts:
    2,442
    Referrals:
    9
    Sythe Gold:
    8
    Pokémon Trainer

    Rawr Addict.
    Retired Sectional Moderator $100 USD Donor

    Understanding RSBot scripting. [Java]

    Took your advice and added all of it, thanks!
     
  25. Unread #13 - Mar 2, 2010 at 8:38 PM
  26. Lukef555
    Joined:
    Aug 16, 2008
    Posts:
    3,206
    Referrals:
    6
    Sythe Gold:
    0

    Lukef555 Grand Master
    Banned

    Understanding RSBot scripting. [Java]

    Very nice guide, im planning on learning java and this pretty much gave me the basics, maybe ill make some scripts ;)

    8/10
     
  27. Unread #14 - Mar 13, 2010 at 4:47 AM
  28. pineapple
    Joined:
    Oct 29, 2008
    Posts:
    68
    Referrals:
    0
    Sythe Gold:
    0

    pineapple Member

    Understanding RSBot scripting. [Java]

    Really nice guide on scripting
    8.5/10
     
  29. Unread #15 - Jul 26, 2010 at 1:54 AM
  30. Pawn
    Joined:
    Jul 8, 2009
    Posts:
    125
    Referrals:
    0
    Sythe Gold:
    0

    Pawn Active Member
    Banned

    Understanding RSBot scripting. [Java]

    Helped a bit. I think someone should make a video commentary on how to script :p
     
  31. Unread #16 - Sep 12, 2010 at 5:58 PM
  32. i am foolish
    Joined:
    Mar 27, 2007
    Posts:
    481
    Referrals:
    1
    Sythe Gold:
    0

    i am foolish Forum Addict
    Banned

    Understanding RSBot scripting. [Java]

    An overwhelming amount to take in here. Seems like a pretty good guide. Very unfortunate that you are banned but thanks for sharing this :]
     
  33. Unread #17 - Oct 10, 2010 at 4:08 PM
  34. Perf3ctskill
    Joined:
    Sep 1, 2010
    Posts:
    362
    Referrals:
    0
    Sythe Gold:
    0

    Perf3ctskill Forum Addict

    Understanding RSBot scripting. [Java]

    I'm stupid then, I don't get ANY of this. I get the first few things(but at the "Loop"). I'm lost. I don't understand. Help?
     
  35. Unread #18 - Oct 12, 2010 at 6:52 PM
  36. Syd
    Joined:
    Aug 10, 2010
    Posts:
    218
    Referrals:
    2
    Sythe Gold:
    10

    Syd Active Member
    Banned

    Understanding RSBot scripting. [Java]

    Doesn't really get in-depth, but it's good.
     
  37. Unread #19 - Oct 14, 2010 at 1:21 PM
  38. TGNxBen
    Joined:
    Sep 30, 2010
    Posts:
    97
    Referrals:
    0
    Sythe Gold:
    0

    TGNxBen Member
    Banned

    Understanding RSBot scripting. [Java]

    Just so everyone is aware, I used RSBot, for fishing and I was perm. banned. So just watch out if you do use the bots.
     
< Help? | Dad. >

Users viewing this thread
1 guest


 
 
Adblock breaks this site