RsBots scripting and other guides

Posts 13 of 3 · Page 1 of 1
RsBots scripting and other guides
I was surfing for rsBots and found out this guide i am posting it.

1.scripting
2.GUI
3.Player movement
4.Object,menus,and items
5.NPC&player interaction
6.player properties.


1. scriptin:


import java.awt.*;

import com.speljohan.rsbot.bot.Bot;
import com.speljohan.rsbot.event.listeners.PaintListener;
import com.speljohan.rsbot.script.Script;
import com.speljohan.rsbot.script.wrappers.*;

public class testscript extends Script implements PaintListener {

public void onRepaint(Graphics g)
{
Bot.getEventManager().addListener(PaintListener.cl ass, this);
}
public double getVersion()
{
return 1.0;
}
public String getScriptCategory()
{
return "Ben's Scripts";
}
public String getName()
{
return "Test Script";
}
public String getAuthor()
{
return "Ben B (Hunterbdb)";
}

public boolean onStart(String[] args)
{
Bot.getEventManager().addListener(PaintListener.cl ass, this);
Frame myframe = new Frame("Input");
myframe.setVisible(true);
return true;
}

public void onFinish() {

}

public int loop() {
return 1000;
}
}



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:

onStart(): this method is called when the script begins. It returns a boolean (true or false statement), which tells the script to either continue (if true) or to halt (if false).

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(){

if(I have cut logs)

then(walk to the bank)

if(I have not cut logs)

then(cut some logs)

return 100;

}

the return statement is a number of milliseconds you want your program to wait inbetween repetitions. if you say "return 1000;" at the end of the loop(), then your script will execute your code,wait 1000 milliseconds, and then restart itself from the top.

onRepaint(Graphics g): This is a method that allows you to draw on the runescape screen. this method is called a million times a second. With this method, you can show the user progress reports. for example, if you want to show the user how many fish have been caught, you can have this be drawn with the onRepaint(Graphics g) method.

get() methods: these are methods like getVersion(), getAuthor(), etc. these simply return a string or double value, which corresponds to the name. for example, in getAuthor() I will say "return 'Ben B' " because I am the author.


PS:this aint my Guide its from a guide made by somone named Ben

---------- Post added at 03:52 AM ---------- Previous post was at 03:51 AM ----------

Alright, so the first thing you ever will want to do in your script is get input from your user. Woah woah woah, what is input, you say? input is when you ask the user for information or specifications. and example of input in Rsbot would be asking "What kind of logs do you want to fletch?". this inquiry is followed by a text box, such as the one below:




Rsbot uses the Java programming language, which means we need to use java to get input from the user of your script. The way java does this is through a GUI (Generic User Interface). Sounds high-tech, ya? Well, it isn't. Infact, it's so bloody simple I don't even know why I bother explaining it. Java is an application programming language, so it uses windows to display things. a window is anything, like the browser you are using to read this tutorial, or microsoft word. Everything on a computer is in some kind of window. A window in java is also called a frame, and this is where the code starts. Whenever you make a GUI, you will put the GUI code in the onStart() method. Why? Because the onStart() method is called when the script begins.You wouldn't want to ask the user for input after the script is done (duh!), so you ask for it when it starts (duh!).There are two ways to make windows and objects in java. there is swing and there is awt. Rsbot doesn't support swing, and I don't care to explain why, so let's stick to the older, but still equally powerful awt set of classes. To create an awt frame, use this code:

Frame myframe = new Frame("ben's GUI");

Woah woah woah,hold up, so what exactly is happening? simply what you are doing here is telling the computer "hey mate, make a window name myframe which has a title bar that says 'ben's GUI' on it". This is a powerful command, but it only makes an invisible frame. To make it visible, say:

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:

TextField input1 = new TextField();

TextField input2 = new TextField();

I made two TextFields, but they are invisible. A component becomes visible when you attach it to the frame. Lets do that:

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));

FlowLayout simply aligns components and displays them one after another. That is what the first argument does. The next two arguments (which are 30 and 10) say how much horizontal spacing and how much vertical spacing there should be between components. Yeah, it's pretty basic, but better looking that no layout at all. Remember, you can also say:

FlowLayout lm = new FlowLayout(FlowLayout.CENTER,30,10)); myframe.setLayout(lm);

these commands do the same thing. AND, remember you have options: you can say FlowLayout.LEFT or FlowLayout.RIGHT.

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:

Label lb1 = new Label("Logs type");

Label lb2 = new Label("Bow type");

And always remember to add them to the frame!

The last component you need is a button. Let's create a button!:

Button button = new Button("Begin Script");

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:

myframe.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent we){
myframe.setVisible(false);
}});

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.

Please take a look at my code:

public boolean onStart(String[] args)
{
Bot.getEventManager().addListener(PaintListener.cl ass, this);
final Frame myframe = new Frame("User Input");
myframe.setLayout(new FlowLayout(FlowLayout.CENTER,30,10));
myframe.setSize(175,175);
myframe.setResizable(false);
myframe.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent we){
myframe.setVisible(false);
}});
Label lb1 = new Label("Logs type");
Label lb2 = new Label("Bow type");
final TextField input1 = new TextField();
final TextField input2 = new TextField();
Button button = new Button("Begin Script");
button.addActionListener(new ActionListener(){public void actionPerformed(ActionEvent event){logtype = input1.getText();bowtype = input2.getText();myframe.setVisible(false);}});
myframe.add(input1);myframe.add(lb1);
myframe.add(input2);myframe.add(lb2);
myframe.add(button);
myframe.setVisible(true);
return true;
}

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).

Pretty boring, huh? Well that's scripting for ya.



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:

boolean maybegin = false;
public boolean onStart(String[] args)
{
Bot.getEventManager().addListener(PaintListener.cl ass, this);
final Frame myframe = new Frame("User Input");
myframe.setLayout(new FlowLayout(FlowLayout.CENTER,30,10));
myframe.setSize(175,175);
myframe.setResizable(false);
myframe.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent we){
myframe.setVisible(false);
}});
Label lb1 = new Label("Logs type");
Label lb2 = new Label("Bow type");
final TextField input1 = new TextField();
final TextField input2 = new TextField();
Button button = new Button("Begin Script");
button.addActionListener(new ActionListener(){public void actionPerformed(ActionEvent event){logtype = input1.getText();bowtype = input2.getText();myframe.setVisible(false); maybegin = true;}});
myframe.add(input1);myframe.add(lb1);
myframe.add(input2);myframe.add(lb2);
myframe.add(button);
myframe.setVisible(true);
return true;
}

public int loop() {
if(maybegin)
{
//all my code.
}
return 1000;
}

Here is my full GUI-starter-model script (modify it as you wish!):

import java.awt.*;

import com.speljohan.rsbot.bot.Bot;
import com.speljohan.rsbot.event.listeners.PaintListener;
import com.speljohan.rsbot.script.Script;
import com.speljohan.rsbot.script.wrappers.*;
import java.awt.*;
import java.awt.event.*;

public class testscript extends Script implements PaintListener {
String logtype;
String bowtype;
public void onRepaint(Graphics g)
{
Bot.getEventManager().addListener(PaintListener.cl ass, this);
}
public double getVersion()
{
return 1.0;
}
public String getScriptCategory()
{
return "Ben's Scripts";
}
public String getName()
{
return "Test Script";
}
public String getAuthor()
{
return "Ben B (Hunterbdb)";
}
boolean maybegin = false;
public boolean onStart(String[] args)
{
Bot.getEventManager().addListener(PaintListener.cl ass, this);
final Frame myframe = new Frame("User Input");
myframe.setLayout(new FlowLayout(FlowLayout.CENTER,30,10));
myframe.setSize(175,175);
myframe.setResizable(false);
myframe.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent we){
myframe.setVisible(false);
}});
Label lb1 = new Label("Logs type");
Label lb2 = new Label("Bow type");
final TextField input1 = new TextField();
final TextField input2 = new TextField();
Button button = new Button("Begin Script");
button.addActionListener(new ActionListener(){public void actionPerformed(ActionEvent event){logtype = input1.getText();bowtype = input2.getText();myframe.setVisible(false); maybegin = true;}});
myframe.add(input1);myframe.add(lb1);
myframe.add(input2);myframe.add(lb2);
myframe.add(button);
myframe.setVisible(true);
return true;
}
public void onFinish() {

}
public int loop() {
if(maybegin)
{
//all my code.
}
return 1000;
}
}

You should see something like this if you use the above script^:

---------- Post added at 03:53 AM ---------- Previous post was at 03:52 AM ----------

topic 3: player movement

In just about any script, you are going to want to move you character. Even in something that is not at first sight a movement-intensive script like a fletching script will at least need to move your character for antiban purposes. Luckily, rsBot provides a means of easily moving your character with programming. Let's take a look.

In runescape, everything has a number value. every scimitar, fish, and animation has a number specific to that item. In runescape, a player's location is recorded by which square tile he is standing on (the ground in rs is made of tiles, by the way). when you click to move your character, you are clicking on a tile location, and character walks to that tile. The first ability you need to have to move your character is the ability to see which tiles your character is on and which ones he needs to move to. To do this, please follow these instructions:

1. Open your rsbot client and log in.

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:



3. Please click Player position:





















Why do I block out my name? Because there are actually fags in this world that will report me.

















4. You will now see green text in the upper left hand corner of your runescape window. This is your x and y position in runescape. Try walking around and see how it changes!

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.

To make an array of tiles, try this code:

RSTile[] path = new RSTile[]{new RSTile(1215,1418), new RSTile(1215,1425)};

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:

RSTile[] path = new RSTile[2];

path[0] = new RSTile(1215,1418);

path[1] = new RSTile(1215,1425);

The first method of making arrays is much much faster^

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);

What the hell! there are 3 arguments to randomizePath(RSTile[],int,int)! Chill out, it's not that bad. take a deep breath. have a smoke. The second argument to this method is the maximum "x" deviation (or distance from the original RSTile "x" values) you want to randomize. the third argument is the maximum "y" deviation. for example, in my code, the tile range for path[0] is (1213 to 1217, 1416 to 1420). Why? because I set the x and y maximum deviation in the randomizePath method to 2,2.

well, that's about as detailed as I possibly can get on Player movement. I think the next topic will be a bit more fun than this one, but still boring.
This is outdated by years.
Quote Originally Posted by pjrat111 View Post
This is outdated by years.
this, just copying a guide doesnt mean that it has to be correct.
Posts 13 of 3 · Page 1 of 1
This thread is closed for replies.

Similar Threads

Tags for this Thread

None

Need help?