Jump to content

A Beginners Guide to Writing OSBot Scripts (where to get started!) by Apaec


Apaec

Recommended Posts

On 8/15/2014 at 2:21 PM, Apaec said:

This tutorial will cover everything required to write your own OSBot scripts. Although it is quite lengthy, don't let this put you off - it shouldn't take more than a couple of hours to follow through, at the end of which you will have learned the scripting basics and will have your very own tea thieving script which you can modify to your liking. Good luck! :)

Previous required knowledge:

  • None
  • Knowledge of basic java helps but is not required!

What this guide covers:

  • Downloading your code editor (IDE)
  • Basic programming concepts
  • A quick guide to java
  • Writing a script with the OSBot API
  • Running your script

Downloading Eclipse:

  Reveal hidden contents

Eclipse is a powerful integrated development environment (IDE) which will help ease the syntactic learning curve. Broadly speaking, it contains features such as syntax prediction, code generation, project organisation, syntax highlighting and more. Additionally, as Eclipse is industry standard software, there are a suite of helpful plug-ins that can be installed to improve work efficiency, such as WindowBuilderPro for UI development and E-git for integrated git functionality.

Eclipse is downloadable here:

http://www.eclipse.org/downloads/

You will also need the latest JDK (Java Development Kit):

http://www.oracle.com/technetwork/java/javase/downloads/jre8-downloads-2133155.html

Setting up your project:

  Reveal hidden contents

A java project is a directory in your file system where your raw code files are stored. Within a project, you can have packages, and within packages you can have classes. Packages are equivalent to folders in your project directory, and classes are just the raw code files (.java).

Let's create a new project for our script:

t3N2oPp.png

https://i.imgur.com/t3N2oPp.png

Give the project the name:

BcZAQRh.png

https://i.imgur.com/BcZAQRh.png

Click finish and you've successfully created your workspace project!

Now we must add a class - this is where the code will go:

2RI6Oln.png

https://i.imgur.com/2RI6Oln.png

Set which package this class is in. Since the project does not yet have any packages, create one. Call it 'core' for now. Next, give the class a name - I suggest 'Main' for the tutorial, but you could call it 'Cabbages' if you wanted, it doesn't matter! By convention, classes start with a capital letter. Hit finish.

Now all we need is to attach OSBot to this directory, so we can utilise the API:

oImFPjn.png

https://i.imgur.com/oImFPjn.png

dUrgzD0.png

https://i.imgur.com/dUrgzD0.png

fhyPcuI.png

https://i.imgur.com/fhyPcuI.png

Your eclipse should then look like this:

VAtzW7f.png

https://i.imgur.com/VAtzW7f.png

Language basics:

  Reveal hidden contents

Most programming languages are compiled. This is the process of taking your text file and converting it into a meaningful executable file. Without going into too much detail, this process involves 'parsing' your text to form an internal data structure (this process usually is multiple layers deep and very complex, luckily we need not worry about this). In the case of Java, this process is slightly different, whereby source code compiles to java byte-code, which is in turn manipulated to machine code at run time with a secondary compiler.

Java basics:

  Reveal hidden contents

We will be writing our code in Java. You may have heard of this before (or even used it!), it is a very powerful Object-Oriented programming language. Note that JavaScript is a completely different thing, despite its seemingly related name! So, what does Object-Oriented mean? It's too hard to explain in just a couple of lines, but I will try! While we won't end up practicing or exploring the full power of object orientation (OO) in this tutorial, loosely speaking it means 'Objects' encapsulate behaviour and can interact with one another to accomplish a pre-defined task. Sounds confusing, right? Luckily we don't have to worry about that stuff for now since we will be working with one class, and can for basic operation rely on the OSBot API to do that all for us.

This is the point where I would ask you to check out this tutorial about Java, but then again I know you don't want to spend all day reading boring web pages and really you just want to jump right in. So let's do just that! I can't claim to do a better job at teaching the basics, but I can certainly try!

In Java (and for that matter almost every other programming language), you are just asking the computer to manipulate some data. In order to 'label' this data, we use what are called variables. I know that is a big word, but it's very simple. A variable contains data. Alongside that, a variable also has a type - this too is simple, it is just the 'flavour' of data contained in the variable. An example of a type could be, arbitrarily, a whole number (e.g 1, 5, 1234, 89213017), known as an Integer, or perhaps a Boolean value (true or false), or even your own custom data type! Let's define some Integers:

Please note that all code in this spoiler is taken out of context. This means running it may not work; in some cases additional code body may be required.



int aNumber = 5;
int anotherNumber = 17;

Simple enough, eh? Notice how we defined the variable - we used the format 'type' 'name' '=' 'value' ';'. ';' just symbolises the end of an expression. We know that the value inside 'aNumber' is 5, and the value inside 'anotherNumber' is 17. What if we want to change the value? That too is simple:



int changeMe = 5;
changeMe = 12;

As you can see, we have changed the value of 'changeMe' to 12.

You can also manipulate variables:



int a = 10;
int b = 20;
int c = a + b;

// c = 30

What does '//' mean? It is just a comment - if you write '//' in your code, anything after that on the same line will be ignored by the compiler.

We don't just have integers though, otherwise our life would be pretty boring. Here's how we can represent text, again storing it in a variable:



String exampleMessage = "Hello world!";

'String' is just a synonym for 'some text', or 'a string of characters'. In this case, our variable stores 'Hello world!'. 

______________

Nice, so we've covered variables and types to a very basic level. Next, let's take a quick look at methods. A method is just a 'block' of code that ideally does something - when you call a method, the script executor will proceed line by line through the method until it reaches the end, where it will return to the line after the method call. Additionally, like variables, methods can also have a type. A method can even have parameters/arguments which can be referenced locally. This may all sound pretty confusing, but trust me it's not! Let's take a look at some examples.



private void emptyMethod() {
  
}

Above is an empty method. You can see the structure of the method quite clearly. Here's a description of the structure:

  • We start with the keyword 'private' - this is known as the method Access Modifier and controls the visibility of the method to the rest of your project. Access Modifiers tend to confuse people to begin with, so in the interests of keeping this tutorial quick, let's ignore them for now. As a rule of thumb, put private, and if that causes errors, switch it to public.
  • Second comes the keyword void. This is the type of the method; what it returns. void simply means that this method does not return anything. We will see later examples where the type is not void.
  • Third comes the method name. By convention, this is written in camelCase (google it!) starting with a lower case letter.
  • Fourth comes some voodoo brackets. No, they aren't actually called voodoo brackets, but they look pretty voodoo if you're only just starting! Inside those brackets is where we put the arguments to the method, but in this case we have no arguments so we just leave them empty.
  • Fifth comes the method body. This is where the code goes.

 Now that we have that out of the way, maybe let's write some methods which are useful? Adding one is useful, right (:P)?



private int addOne(int value) {
	return value + 1;
}

We can then call this method:



int someValue = 36;
int newValue = addOne(someValue);
// (newValue is 37)

Wow... what?! Let me explain what just happened...

As before, we defined a number and set it's value to 36. Then, we defined a new number, called 'newValue', and set the value to the result of calling our method 'addOne' on the number we initially defined. How can we set the value of an integer to... a method? Well, as I said before, methods can have types. This means that the method returns a value of the specified type, and as such can be used in place of a hard coded value as the method is evaluated.

What if our method was void, what then? Well, since a void method does not return anything, the method has no type and as such the compiler will refuse to compile your code as your types don't match up.

Consider this code:



private void addOne(int value) {
	value + 1;
}

As you can see, it is the same as before however it is now a void method, and returns nothing. Yet it still has arguments and 'does stuff' in the method body. The question is, does it change what you give it, i.e in the following example, is someValue 11 or 12?



int someValue = 11;
addOne(someValue);

The answer is 11. The reason for this is that Java is a pass by value language and as such when you provide arguments to a method, the method works with an independent instance of the variable - the value of the variable outside the method is not affected by what happens inside. In a language such as C, this is not always the case.

________

Awesome, so variables and methods covered! How does this relate to scripting? Well, it's a starting point! Variables are used all the time and form the basis for many other features of Java, and you will be using methods a huge amount to minimise repetition of your code. With this basic understanding of variables and methods, let's now actually try to write some code!

Script backbone:

  Reveal hidden contents

To start you will need to paste the following framework from which we will start writing the code:



package core;

import java.awt.Graphics2D;

import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;

@ScriptManifest(author = "You", info = "My first script", name = "Tea thiever", version = 0, logo = "")
public class Main extends Script {

	@Override
	public void onStart() {
		log("Let's get started!");
	}

	@Override
	public int onLoop() throws InterruptedException {
		return random(200, 300);
	}

	@Override
	public void onExit() {
		log("Thanks for running my Tea Thiever!");
	}

	@Override
	public void onPaint(Graphics2D g) {

	}

}

What does all that mean? Unfortunately it is too much to explain without you getting bored, so rather than explaining it for now, you just have to know how to use it. If you want the technical jargon, here it is. Script is an abstract class as part of the OSBot API. Since it is abstract, you must provide implementations for some of the body-less methods defined in the Script class. In fact, the only body-less method of this class is int onLoop(), however we will also provide implementations for onStart, onExit and eventually onPaint. The @Override annotation simply helps the compiler, telling it that these new methods override the parent's counterparts.

... Anyway, if you didn't understand that, luckily for you, you didn't need to just yet! In short, this is the basic starting point from which all scripts are made (the 'backbone' of the script). 

Go ahead and paste that in, and your eclipse should look like so: (again, you don't need to know how to write this from scratch!)

4pYbfVg.png

https://i.imgur.com/4pYbfVg.png

If you're getting lots of red underlines, you've probably forgotten attach the OSBot jar to the build path (or you've done something else wrong, go back and take a look at the setting up stage again!). In eclipse, when there is even a single red underline, the script will fail to compile. This means your code cannot be converted into its binary counterpart and hence will not run.

I will break down each part of this backbone to give you an understanding of what they do and how you use them.

_____________________________________________________________________________________________

onStart:



@Override
public void onStart() {
	log("Let's get started!");
}

This code block is called only once when you press the start button on the script while running the client. You could use this block to log information to the user, to initialise variables, load your GUI (eventually!), etc.

As you can see, I wrote 'log("Let's get started!");'. If you ran the script now, when you pressed play, it would simply print that message to the OSBot console (opened via. the options menu), then sit in an endless loop iterating through the onLoop block which I will cover later on.

Let's talk about printing some messages to the user.

Strings can be concatenated (appended to one another) using either the '+' operator, or Java's StringBuilder class. (When you use the plus operator, the Java compiler actually initialises a StringBuilder instance and works from there) - let's not worry about the StringBuilder class for now though!



// Concatenating strings with the '+' operator
log("You mined " + 300  + " rocks");

You can see, in the above example, we have concatenated two strings and an integer. This will show in the OSBot logger as "You mined 300 rocks". In context, you could imagine that in this situation you might use a variable instead of a hard-coded number (300), so as to print the number of rocks mined in a script.

_____________________________________________________________________________________________

onLoop:



@Override
public int onLoop() throws InterruptedException {
	return random(200, 300);
}

This is the heart of the script, and continuously loops until the script is interrupted with the stop button in the bot. As you can see, the type of the onLoop function is int. So what is a continuously looping method doing returning an Integer?! Well - as it so happens, this return value is the loop delay, i.e the time the script will idle after a loop is successfully completed.

At the moment, the onLoop method is returning:



return random(200,300);

This means the delay between every loop is a random number of milliseconds between 200 and 300. Simple enough! You can use the random(int a, int b) method elsewhere in your program when you get around to writing it yourself, but for now, let's move on!

onExit:



@Override
public void onExit() {
	log("Thanks for running my Tea Thiever!");
}

Similar to onStart, this loop runs only once when you press the red stop button at the top of the bot (or when you stop the script in code). You can use this method to log details of the script for example how many teas you thieved, or how long you ran the script for. Since java is a garbage collected language (essentially, there is a system in place which clears unused variables from memory), this method is not as useful as the onStart method since you do not need to free memory / manually deconstruct objects. This method can still usefully be used to send usage data to a database (although ideally if you were doing this, it would be during run-time!) or perhaps log messages to the user.

In this example, I've simply included a 'thank you' message which will be logged to the console when the script terminates.

onPaint:



@Override
public void onPaint(Graphics2D g) {

}

Ever wondered how scripts manage to get those annoying and often unsightly boxes and images placed all over the game canvas? Well, this is the culprit.

This is where the code for your paint goes - I will not cover how to make a paint in this tutorial as it is somewhat intuitive and there are plenty of other tutorials here. If you want to experiment, perhaps try putting this line into the onPaint:



// Drawing a simple message to the screen canvas
g.drawString("Hello World", 50, 50);

 

Compiling the script:

  Reveal hidden contents

As learned in the 'language basics' section, we must compile scripts before running them. Here's how:

Open the export interface by right clicking the project:

0YstWrN.png

https://i.imgur.com/0YstWrN.png

Select JAR file, then press next:

PabvBaf.png

https://i.imgur.com/PabvBaf.png

Save to your OSBot scripts folder:

qomCpGr.png

https://i.imgur.com/qomCpGr.png

Done!

Writing the script:

  Reveal hidden contents

With the backbone explained, let's get into the actually coding. After all, that's what you came here for! This section is a little longer than the previous ones, but it is where stuff starts to get interesting. Stick around!

We are going to combine our knowledge of Java with that of the OSBot API to create a tea thieving script. Let's first learn how to reference an in-game object. In the example below, we are using the Varrock east tea stall:



// ...
RS2Object stall = getObjects().closest("Tea Stall");
// ...

Just like in the 'Java basics' section, we are defining a variable, although this time not just an integer or string. Here, we are defining an 'RS2Object' (or, RuneScape 2 Object). This is a data type specified in the OSBot API - Again, we don't need to know exactly how this works for now, only how to use it. We are naming this RS2Object 'stall', and are defining it as 'getObjects().closest("Tea Stall");'

Huh?

We can read this in english as: "get all nearby RS2Objects, then find the closest one with the name 'Tea Stall'. Give me that one!".

After having defined this, we can then interact with it. But first, we have to 'null check' it. If, for example, there are no objects with the name 'tea stall' nearby, the variable will be set to 'null'. So we need to make sure that the object is not null, i.e present, before interacting. We can do that with our friend, the 'if' statement!



// ...
RS2Object stall = getObjects().closest("Tea Stall");
if (stall != null) {
  log("Stall is present!");
}
// ...

This will log 'Stall is present!' in the console if the stall is there. So this is where we want to interact with the stall. We would do that as follows:



// ...
RS2Object stall = getObjects().closest("Tea Stall");
if (stall != null) {
  stall.interact("Steal-from");
}
// ...

There we go! Tea thieving script!

Here's what the full code would look like:



import java.awt.Graphics2D;

import org.osbot.rs07.api.model.RS2Object;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;

@ScriptManifest(author = "You", info = "My first script", name = "Tea thiever", version = 0, logo = "")
public class Main extends Script {

	@Override
	public void onStart() {
		log("Let's get started!");
	}

	@Override
	public int onLoop() throws InterruptedException {
		RS2Object stall = getObjects().closest("Tea Stall");
		if (stall != null) {
		  stall.interact("Steal-from");
		}
		return random(200, 300);
	}

	@Override
	public void onExit() {
		log("Thanks for running my Tea Thiever!");
	}

	@Override
	public void onPaint(Graphics2D g) {

	}

}

You can give this a go. There are however a couple of problems:

  1. The script spam-clicks the tea stall, and
  2. When your inventory is full, the script will continue to try and steal, but will fail.

Let's solve these, starting with point 1:

We can solve this particular problem with additional checks. If you notice, when clicking on the tea stall, your player initiates the stealing animation. This animation is something that we can track. You can perhaps already see where this is going - we only want to interact with the tea stall if we are not animating. Here's how:



// ...
RS2Object stall = getObjects().closest("Tea Stall");
if (stall != null && !myPlayer().isAnimating()) {
	stall.interact("Steal-from");
}
// ...

The "isAnimating()" method from the player class has the type boolean. This means it returns either true or false. Subsequently, we can perform boolean manipulation on this. In this case, we are negating the value - you can see that this will result in a false value when animating, and a true value otherwise. This is then combined with the null check with an infix '&&' (and) logical operator which will only return true if both the left and right conditions evaluate to true. Thus the script will only attempt to interact if the stall exists and your player is not currently animating.

Now that point 1 is solved, we can move on to point 2:

This will require us to work outside of the if statement which we composed in the previous part. Now, we want to check if your inventory contains tea. If it does, then we want to drop that tea before trying to steal more. Implementing this will introduce us to some basic inventory API - let's get started:



// ...
RS2Object stall = getObjects().closest("Tea Stall");
if (getInventory().contains("Cup of tea")) {
	getInventory().drop("Cup of tea");
} else if (stall != null && !myPlayer().isAnimating()) {
	stall.interact("Steal-from");
}
// ...

Neat! The best part about the API is it reads off like English. Hopefully because of this, you already understand what the code does, but if not then let me explain. Firstly, as before, we are defining our stall - nothing new there. After this, we run into our first check - here we are testing if the inventory has any tea. If you are carrying a cup of tea at the time, then the script will enter that if block. Otherwise, the script will continue to evaluate the second check, as before. If it enters the first block, the script will drop the cup of tea, then proceed to after the else/if block. You should now be able to see that, with every onLoop iteration, the script will either drop a cup of tea or steal a cup of tea - never both in the same loop. This is good practice; I will get onto this later in the guide. For now, let's integrate this update with the rest of the code, and give it a test run:



import java.awt.Graphics2D;

import org.osbot.rs07.api.model.RS2Object;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;

@ScriptManifest(author = "You", info = "My first script", name = "Tea thiever", version = 0, logo = "")
public class Main extends Script {

	@Override
	public void onStart() {
		log("Let's get started!");
	}

	@Override
	public int onLoop() throws InterruptedException {
		RS2Object stall = getObjects().closest("Tea Stall");
		if (getInventory().contains("Cup of tea")) {
		  getInventory().drop("Cup of tea");
		} else if (stall != null && !myPlayer().isAnimating()) {
		  stall.interact("Steal-from");
		}
		return random(200, 300);
	}

	@Override
	public void onExit() {
		log("Thanks for running my Tea Thiever!");
	}

	@Override
	public void onPaint(Graphics2D g) {

	}

}

Great! Now we have a reliable, functional tea thiever. If you run the script now, you will see that it works quite well, however there is still a bit of tuning to be done. Here's what can be changed to smooth out the running of the script a little:

  1. The script spam clicks on the stall or when dropping
  2. Edge cases need consideration

To solve the first point, it is important to note exactly why this happens. The reason is because of the return value of the onLoop method. We are currently looping every 200-300 milliseconds which is very quick, on each loop the script will likely attempt to interact with the game in some way. You may thing 'well, let's just slow it down a bit by changing the onLoop value' but this is the wrong methodology (you could consider this a plaster (or band-aid for you Americans) fix to the issue). Rather, it is better to integrate some sleeps into the code where needed. There are two kinds of sleeps - static and conditional. Static sleeps are for a fixed duration, conditional sleeps are those which terminate only when a condition is met, or a timeout elapses. Conditional sleeps are beyond the scope of this beginners guide so we will use static sleeps for now, but as you progress (especially if you hope to have scripts on the SDN), you will need to migrate solely to conditional sleeps. Let's add some static sleeps:



// ...
RS2Object stall = getObjects().closest("Tea Stall");
if (getInventory().contains("Cup of tea")) {
	getInventory().drop("Cup of tea");
	sleep(500);
} else if (stall != null && !myPlayer().isAnimating()) {
	stall.interact("Steal-from");
	sleep(500);
}
// ...

Cool! Remember, the duration of a sleep is in milliseconds, so setting a value of 500 results in a 0.5 second flat sleep. When sleeping, the script will not do anything and will simply be 'stuck' at the sleep statement until the time elapses, after which it will proceed to execute more code.

Let's now move onto point number 2, edge cases. Edge cases are exceptional flows in the execution of a script which are uncommon, but must be catered for. Let me give you some examples:

  • What if your inventory is full, but are carrying no tea?
  • What if the script misclicks to the other side of the stall and you get caught by the store owner?
  • What happens if the script misclicks 'Attack' on a guard, and the player dies? (... perhaps a little extreme, but nonetheless possible)
  • And so on...

You can see from the above examples that each of them will disrupt the flow of the script and cause it to get stuck. Fixing these is perhaps a good activity to work on following this guide - I will not cover solutions here.

Perhaps the hardest part of writing a script is 'bullet-proofing' it. You have to consider and cater for all of these points. You can imagine the number of edge cases in more complex scripts will increase dramatically, keep this in mind.

This is as far as this guide will go in demonstrating script code - you can proceed to run the completed script at your leisure. A good activity to pursue would be to customise the script further - add a paint, perhaps expand to include banking, fix edge cases etc. Good luck!

Best practices and conventions:

  Reveal hidden contents

When writing code, it is best practice to adhere to conventions. This is helpful for a number of reasons:

  • Makes your code more readable
  • Makes it easier for other users to assist you
  • Helps you determine the nature of a reference without checking
  • Increases your likelihood that your SDN application is accepted
  • And so on...

For some cases, there may be more than one intersection convention - in these cases, it is important to be consistent.

Here's some information about naming conventions for variables from oracle:

JG1fKgC.png

With regards to OSBot scripting, maintaining a continuously looping structure is paramount. This can reduce the number of surprising bugs, and supports a more flexible structure which can welcome updates in the future. This means you should avoid while loops and long sleeps, and only execute one interaction for every iteration of your onLoop. Keep in mind that OSRS is a live game - fluctuations in latency can mean the script mislicks or interactions could fail. Subsequently, never stack interactions on top of one another (e.g when banking) - this is a very common mistake with beginners.

Also, I would strongly suggest commenting your code. This will help you understand what the script is doing where, and will test your own understanding of what is going on! It is also useful when returning to old projects.

Completed Tea thieving source code:

  Reveal hidden contents


import java.awt.Graphics2D;

import org.osbot.rs07.api.model.RS2Object;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;

@ScriptManifest(author = "You", info = "My first script", name = "Tea thiever", version = 0, logo = "")
public class Main extends Script {

	@Override
	public void onStart() {
		log("Let's get started!");
	}

	@Override
	public int onLoop() throws InterruptedException {
		RS2Object stall = getObjects().closest("Tea Stall");
		if (getInventory().contains("Cup of tea")) {
		  getInventory().drop("Cup of tea");
		} else if (stall != null && !myPlayer().isAnimating()) {
		  stall.interact("Steal-from");
		}
		return random(200, 300);
	}

	@Override
	public void onExit() {
		log("Thanks for running my Tea Thiever!");
	}

	@Override
	public void onPaint(Graphics2D g) {

	}

}

 

That's the end of this tutorial, hopefully it was useful and concise enough. As I mentioned earlier, remember to ask LOTS OF QUESTIONS!

Also remember that google is your friend! ? Although it may seem OSBot scripting is a niche use of java, many questions can translate to more widely adopted counterparts - use this to your advantage.

If you have any questions do not hesitate to post as a reply below. Since I follow this thread, I will receive a notification if you do and will do my best to get back to you ASAP!

- Apaec

made my first script with this guide, very well written ?

Link to comment
Share on other sites

23 hours ago, Marsman19 said:

Thanks for this! Will certainly help out for basic scripts.

Do you need an IT background for really advanced scripts?
I assume it takes months to write one?

You don't need any IT background to write scripts, although naturally it helps a bit. Writing advanced scripts simply requires knowledge of the OSBot API and Java, both of which can be learned via writing basic scripts. Big projects don't necessarily take a long time to make, but can take a long time depending on how thoroughly they are tested, how efficiently they are written, etc.

Good luck!

17 hours ago, Furious 7 said:

Insane guide dude!

Cheers

16 hours ago, JioMy said:

made my first script with this guide, very well written ?

Thanks, congrats :)

  • Heart 1
Link to comment
Share on other sites

  • 1 month later...
1 hour ago, mitsuki said:

Don't suppose you can help me with something else? what asset package are all of the referenced functions in? Like Rock id, Tree id, stall? i've been looking in the rs2object sub classes, and can't find them. Cheers in advance dude

Check out the API: https://osbot.org/api/org/osbot/rs07/api/model/RS2Object.html

-Apa

Link to comment
Share on other sites

On 8/23/2018 at 5:33 PM, Apaec said:

I can't find the "stall" object anywhere. What would i use for a fishing spot? would i just put "fishing spot"? and where it says "steal-from", would it be "fish-from"?

Edited by mitsuki
added more info
Link to comment
Share on other sites

10 hours ago, mitsuki said:

I can't find the "stall" object anywhere. What would i use for a fishing spot? would i just put "fishing spot"? and where it says "steal-from", would it be "fish-from"?

stall is just the variable name which you've assigned the object (of type RS2Object) to. You're correct in saying that you would just put 'fishing spot' and 'fish-from' or whatever the action is if you wanted to use a fishing spot. 

Good luck

Apa

Link to comment
Share on other sites

Any idea why this won't work? I'm trying to get it to find the closest Fishing spot, and fish from it, then drop the anchovies or shrimp. But when i run the script, it does nothing?

package core;

import java.awt.Graphics2D;

import org.osbot.rs07.api.model.RS2Object;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;

@ScriptManifest(author = "Mitsuki", info = "AutoShrimper", name = "AutoShrimper", version = 0, logo = "")
public class AutoFisher extends Script 
{

    @Override
    public void onStart() 
    {
        log("Let's get started!");
    }

    @Override
    public int onLoop() throws InterruptedException 
    {
        RS2Object FishingSpot = getObjects().closest("Net Fishing spot");
        
        if (getInventory().contains("Raw shrimps")) 
        {
            getInventory().drop("Raw shrimps");
        }
        
        if (getInventory().contains("Raw anchovies")) 
        {
            getInventory().drop("Raw anchovies");
        }
        
        
        else if (FishingSpot != null && !myPlayer().isAnimating()) 
        {
            FishingSpot.interact("Net-Fishing-spot");
        }
        
        return random(200, 300);
    }

    @Override
    public void onExit() 
    {
        log("Thanks for running my AutoShrimper!");
    }

    @Override
    public void onPaint(Graphics2D g) {

    }

}

 

Link to comment
Share on other sites

On 8/27/2018 at 3:30 PM, mitsuki said:

Any idea why this won't work? I'm trying to get it to find the closest Fishing spot, and fish from it, then drop the anchovies or shrimp. But when i run the script, it does nothing?


package core;

import java.awt.Graphics2D;

import org.osbot.rs07.api.model.RS2Object;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;

@ScriptManifest(author = "Mitsuki", info = "AutoShrimper", name = "AutoShrimper", version = 0, logo = "")
public class AutoFisher extends Script 
{

    @Override
    public void onStart() 
    {
        log("Let's get started!");
    }

    @Override
    public int onLoop() throws InterruptedException 
    {
        RS2Object FishingSpot = getObjects().closest("Net Fishing spot");
        
        if (getInventory().contains("Raw shrimps")) 
        {
            getInventory().drop("Raw shrimps");
        }
        
        if (getInventory().contains("Raw anchovies")) 
        {
            getInventory().drop("Raw anchovies");
        }
        
        
        else if (FishingSpot != null && !myPlayer().isAnimating()) 
        {
            FishingSpot.interact("Net-Fishing-spot");
        }
        
        return random(200, 300);
    }

    @Override
    public void onExit() 
    {
        log("Thanks for running my AutoShrimper!");
    }

    @Override
    public void onPaint(Graphics2D g) {

    }

}

 

Are you sure the string interactions are correct? They don't look right to me at first glance!

Apa

  • Like 1
Link to comment
Share on other sites

Spoiler

package core;

 

import java.awt.Graphics2D;

 

import org.osbot.rs07.api.model.RS2Object;

import org.osbot.rs07.script.Script;

import org.osbot.rs07.script.ScriptManifest;

 

@ScriptManifest(author = "Mitsuki", info = "AutoShrimper", name = "AutoShrimper", version = 0, logo = "")

public class AutoFisher extends Script

{

 

                @Override

                public void onStart()

                {

                                log("Let's get started!");

                }

 

                @Override

                public int onLoop() throws InterruptedException

                {

                                RS2Object fishingSpot = getObjects().closest("Fishing Spot");

                               

                                if (getInventory().contains("Raw shrimps"))

                                {

                                                getInventory().drop("Raw shrimps");

                                }

                               

                                if (getInventory().contains("Raw anchovies"))

                                {

                                                getInventory().drop("Raw anchovies");

                                }

                               

                               

                                else if (fishingSpot != null && !myPlayer().isAnimating())

                                {

                                                fishingSpot.interact("Net");

                                }

                               

                                return random(200, 300);

                }

 

                @Override

                public void onExit()

                {

                                log("Thanks for running my AutoShrimper!");

                }

 

                @Override

                public void onPaint(Graphics2D g) {

 

                }

 

}

still no luck after making amendments. All of the functions are correct aren't they? I would call upon getObject() still for a fishing spot, wouldn't i?

Link to comment
Share on other sites

6 hours ago, mitsuki said:
  Hide contents

package core;

 

import java.awt.Graphics2D;

 

import org.osbot.rs07.api.model.RS2Object;

import org.osbot.rs07.script.Script;

import org.osbot.rs07.script.ScriptManifest;

 

@ScriptManifest(author = "Mitsuki", info = "AutoShrimper", name = "AutoShrimper", version = 0, logo = "")

public class AutoFisher extends Script

{

 

                @Override

                public void onStart()

                {

                                log("Let's get started!");

                }

 

                @Override

                public int onLoop() throws InterruptedException

                {

                                RS2Object fishingSpot = getObjects().closest("Fishing Spot");

                               

                                if (getInventory().contains("Raw shrimps"))

                                {

                                                getInventory().drop("Raw shrimps");

                                }

                               

                                if (getInventory().contains("Raw anchovies"))

                                {

                                                getInventory().drop("Raw anchovies");

                                }

                               

                               

                                else if (fishingSpot != null && !myPlayer().isAnimating())

                                {

                                                fishingSpot.interact("Net");

                                }

                               

                                return random(200, 300);

                }

 

                @Override

                public void onExit()

                {

                                log("Thanks for running my AutoShrimper!");

                }

 

                @Override

                public void onPaint(Graphics2D g) {

 

                }

 

}

still no luck after making amendments. All of the functions are correct aren't they? I would call upon getObject() still for a fishing spot, wouldn't i?

Fishing spots may be a little odd - use the entity debugger to see if they are objects or NPCs. They could well be NPCs, in which case getObject() won't work!

-Apa

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...