How To Make An RSBot Script
How To Make An RSBot Script
1. Script Model
2. GUI Building
3. Player Movement
4. Objects, Menus, and Items
5. NPCs & Player Interactions
6. Player Properties
What you see above is the most simple script you will ever see in
Rsbot. Every script will have the minimum of these methods^. Lets
review what each method does:
loop(): this is where the scripting code will go. loop() is called
repeatedly. it repeats, and repeats, and repeats. This is how a script
works. for example: if you want your script to walk to cut some logs
and walk to the bank, your loop() method will look like this:
loop(){
return 100;
myframe.setVisible(true);
You can also set this command to "false" to make the frame invisible
again, but only a fag would do that. replace "myframe" with whatever
you named your frame in the first command I showed you^. frame
sizes need to be set, or else it will be super small. so, lets say:
myframe.setSize(250,250);
sizes are set by number of pixels, so in this command^ you are telling
the computer to set the frame size to 250 pixels wide by 250 pixels
downward (lengthwise). Alrighty! We have made a boring, stupid,
lame frame! let's put some stuff in it! Frames are spaces where you
can put components. a component can be anything, like the textfield
at the top of this tutorial^. it can be a label which just displays text, or
it can be various kinds of buttons. It can be lots of things! The only
things I use on GUIs for Rsbot scripting are buttons and text. Let's
make two input boxws, called TextFields:
myframe.add(input1);
myframe.add(input2);
This is great, but it's not great-looking. The components are smashed
together. wouldn't it be great to have a great-looking GUI where
components are spaced and good looking? java arranges things on
frames using layout managers. there are many kinds of layout
managers, but let's stick to the most simple of them all, the
FlowLayout. To set the Frame's layout manager, use this code:
myframe.setLayout(new FlowLayout(FlowLayout.CENTER,30,10));
The next things you want are Labels because if you don't have these,
how will the user know what to put into your textfields?. Labels
display text. to make one of these use this code:
Just like the Label, the Button takes a string argument saying what
text to display. And always remember to add them to the frame!
A helpful thing is to have the "x" button on a frame close the frame
when it is clicked. to do this, use this code:
Okay! HOld up! What does this do? This code tells the computer "hey
mate, add a window listener to your ear to set the frame invisible
when the window-closing button is clicked". You don't really ned to
understand this. just memorize it.
There is one last thing to do. You need to make the button close the
window and start the rsbot script when clicked.
Okay, so the text is red tells the computer to add a listener to the
button component named "button".. a listener is a "computer thing"
that "listens" or waits for something to happen. There are many kinds
of listeners: key event listeners,mouse event listeners, etc. However,
all you should worry about are actionlisteners which listen for clicks.
within the actionPerformed(ActionEven event) method is where you
put the code for what you want to happen when the button is clicked.
What I told it to do is to close the frame and record the log type and
bow type in String variables. You can then use these variables to
make your script make any kind of bow you want ( magic, yew,
maple, short, long).
Theres one extra thing I want to share with you. That is, if you want
the script to wait until the user has submitted input to you before the
script starts, make a global boolean variable and declare it false.
Then, in the actionPerformed(actionEvent event) method declare it to
be true. Then, in your loop() method you can say if(boolean variable
= true), then(do the script).This way, when the "begin script" button is
clicked, the script will start. check out what I did:
import java.awt.*;
You should see something like this if you use the above script^:
Alright, on to more boring stuff!
2. In the upper-center of the rsbot client you will see a "debug" tab.
Please click this and you will see a form like this:
Okay, now that you know this, you can learn to move your character
with code. To move your character, you need to do two things: make
an array (a list) of Runescape tiles that you want to travel to in
sequential order, and call a method to make your character walk.
Runescape tiles are called RSTiles in rsbot.
you can put as many tiles in this array as you want. However, if they
are inaccessible through your path, there will be problems. You can
also make and array of Runescape tiles like this:
Now that you have your array, let's walk! Try this code:
walkPathMM(path,20);
Woah woah woah, HOLD UP! what does the "20" in there mean? this
method takes an array of RSTiles and makes your character walk
them in sequential order. The second argument is the "maximum
distance" that you want your character to travel. Make sure that your
character doesn't go too far or he will get lost!
This is all great, but if you walk to same path all the time you're
asking to be banned. So why not randomize your path up! Try this
code:
walkPathMM(randomizePath(path,2,2),34);
Now we are going to learn the most important thing: clicking on stuff.
Thankfulling Speljohan has made this very easy for us.
There are two steps to clicking on an object: find and object, click on
the object.
This method does the same thing as the 4th method below, except it
uses integer locations instead of an RSTile.
This method finds the nearest object with the specified number and
within the specified maximum distance from your player.
You will use the 2nd method the most for its simplicity. Now, if I want
my script in the picture above to use the bank booth , I will use this
code:
atObject(bankbooth,"Use-Quickly");
Wait wait wait! what's this atObject method? This method right-clicks
on the object that you found and selects the option specified in the
2nd argument from the menu that appears. Make sure that the 2nd
argument String is EXACTLY what you want it to be, or the method
will screw up. If the option doesn't exist, it will cause the method to
screw up as well.
Items
atInventoryItem(379,"eat");
This method will right click on my lobster and then select the "eat"
option. Yum Yum! You can also use short-cut methods to use an
item:
Menus
Okay, so what is a menu? I don't know why I have to explain this, but
this tutorial is for the most noobed boober noobers. A menu is any
kind of form that pops up in runescape. It can be when you right-click
a player, or when you right-click an item, etc. Check out the sweet
bank booth menu we clicked in one of our code pieces:
One such scenario is withdrawing from the bank. the bank methods
are BROKEN, last time I checked. So, we need to withdraw on our
own. I have formulatedsome code for all of you:
Okay, so let's talk about this code. Once I have opened the bank, we
say bank.searchItem(String) which searches for the specified item in
your inventory. then, I use the clickMouse method to click on the point
where the object will be after searching for it, which is at the upper left
corner. then, i use the clickMouse method again to make a selection.
HOLD UP! there is an easier way to make the selection after right
clicking on the item in the inventory. the way to do this is to use the
atMenu method.
atMenu("Withdraw 100");
Replace the text in the quotes with the appropriate command and the
method will select that option from the menu you have open.
Well, thats it for objects, items, and menus! I hope I was as least
confusing as possible!
Tabs
Tabs are the buttons that let you switch from your inventory, to your
prayer screen, to your magic dialog in runescape. to open these tabs
in rsbot, use this code:
openTab(INTERFACE_TAB_PRAYER);
This code uses global variables. you can open any tab using one of
these pre-set variables:
public static final int INTERFACE_GUI = 548; public static final int
INTERFACE_CHAT_BOX = 137; public static final int
INTERFACE_TRADE = 279; public static final int
INTERFACE_GAME_SCREEN = 549; public static final int
INTERFACE_LEVELUP = 740;
You don't HAVE to use the variables. You could very well say
openTab(271) to open the prayer tab. The variables just make it
easier. You don't have to memorize all those numbers!
Banking
There are a few methods for banking. These ONLY WORK WHEN
THE BANK SCREEN IS OPEN! The implemented variable "bank" is
used to access bank commands. You can use its methods below:
bank.depositAllExcept(379);
With the bank screen open, this method deposits all items except the
items with the specified id number. an array of item ids can be used
with this method as well.
bank.depositAll();
With the bank screen open, this method deposits all items into the
bank.
atNPC(dragon, "Attack");
This code above attacks the dragon NPC I found^. The second
argument is the option of the menu you want to click after you right-
click on the npc.
ClickCharacter(player_to_kill,"Attack");
This code above attacks the lvl 95 player I found^. This method can
be used for a RSNPC as well.
Well, those are the basics to player and NPC interation. It isn't hard.
In fact, none of this is very hard. Have fun with your new knowledge!
RSPlayer me = getMyPlayer();
This gets your player. you can use it in place of "getMYPlayer()" for
the methods below
This gets your current destination while moving. it returns null if you
aren't moving, so make sure you call it only when moving.
This code gets the index, or number for the fishing stat and then gets
the current skill experience for it. You can get any level's stat index
with the getStatIndex(String) method.
This code, using the stat index from the code above it, gets the
current level.
You don't HAVE to use the variables. You could very well say
skills.getXPToNextLevel(10) to get the fishing XP to the next level.
Credits
Created by Ben B
Converted to PDF Format by Matt7