Jump to content
View in the app

A better way to browse. Learn more.

OSBot :: 2007 OSRS Botting

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

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

Featured Replies

 

localWalker.walkPath(Position[] path);

 

 

To get this to work what api do i have to import?

 

i currently have:

import org.osbot.rs07.api.model.Entity;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;
import org.osbot.rs07.api.map.Area;

import java.awt.*;

I also have the postions set up i read through osbot.org/api and couldn't find it. Thanks for your help biggrin.png

 

Edited by potatoer

  • Author

 

To get this to work what api do i have to import?

 

i currently have:

import org.osbot.rs07.api.model.Entity;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;
import org.osbot.rs07.api.map.Area;

import java.awt.*;

I also have the postions set up i read through osbot.org/api and couldn't find it. Thanks for your help biggrin.png

 

 

Uh, i'm not sure. If you try writing postition, it should underline in red and it will give you the option to import the relevant import. 

 

apa

Uh, i'm not sure. If you try writing postition, it should underline in red and it will give you the option to import the relevant import. 

 

apa

It worked but i had to create a new project for some reason :D thank you for all the help. My script is just getting the finishing touches.

  • Author

It worked but i had to create a new project for some reason biggrin.png thank you for all the help. My script is just getting the finishing touches.

 

glad you got it sorted :D

 

would be awesome to see a screenshot of the script in action!

apa

glad you got it sorted biggrin.png

 

would be awesome to see a screenshot of the script in action!

apa

It appears i didn't get it sorted :( i've compiled the code with no errors or warnings but when i run it i get 

[ERROR][Bot #1][10/25 09:03:35 PM]: Error in script executor!
java.lang.NullPointerException
	at Main.onLoop(Main.java:52)
	at org.osbot.rs07.event.ScriptExecutor$InternalExecutor.run(em:109)
	at java.lang.Thread.run(Unknown Source)
[INFO][Bot #1][10/25 09:03:35 PM]: Thanks for running my Garlic Grabber!
[INFO][Bot #1][10/25 09:03:35 PM]: Script Garlic Grabber has exited!

source code: here 

 

i hope i'm not pestering you :]

  • Author

It appears i didn't get it sorted sad.png i've compiled the code with no errors or warnings but when i run it i get 

[ERROR][Bot #1][10/25 09:03:35 PM]: Error in script executor!
java.lang.NullPointerException
	at Main.onLoop(Main.java:52)
	at org.osbot.rs07.event.ScriptExecutor$InternalExecutor.run(em:109)
	at java.lang.Thread.run(Unknown Source)
[INFO][Bot #1][10/25 09:03:35 PM]: Thanks for running my Garlic Grabber!
[INFO][Bot #1][10/25 09:03:35 PM]: Script Garlic Grabber has exited!

source code: here

 

i hope i'm not pestering you :]

 

Don't worry about pestering me!: )

 

As for the code, FORMAT IT! 

 

From first glance it looks like you've got the bracket alignment wrong in the getState() switch. It's quite hard to read tho as it's all over the place. but generally, an NPE is an easy error to fix. It just means you forgot to null check something - in this case specifically on line 52 (as it says in the stacktrace). Take a look at that line and see if you can figure out what's wrong! :) (hint - nullcheck the cupboard :D)

 

apa

Don't worry about pestering me!: )

 

As for the code, FORMAT IT! 

 

From first glance it looks like you've got the bracket alignment wrong in the getState() switch. It's quite hard to read tho as it's all over the place. but generally, an NPE is an easy error to fix. It just means you forgot to null check something - in this case specifically on line 52 (as it says in the stacktrace). Take a look at that line and see if you can figure out what's wrong! smile.png (hint - nullcheck the cupboard biggrin.png)

 

apa

Thanks it got the script running and more problems show up tongue.png it doesn't seem to follow any order i have put in the script i put some labeling in this paste after starting in the bank it just wants to go up the stairs for some reason :s if i start in the room with cupboard it will pick and walk back until it gets close to the bank which has a house across from it with stairs but it doesn't always make it down the stairs after picking :s.

Edited by potatoer

  • Author

Thanks it got the script running and more problems show up tongue.png it doesn't seem to follow any order i have put in the script i put some labeling in this paste after starting in the bank it just wants to go up the stairs for some reason :s if i start in the room with cupboard it will pick and walk back until it gets close to the bank which has a house across from it with stairs but it doesn't always make it down the stairs after picking :s.

 

The best way for you to learn is to figure this one out for yourself. That being said, i'll point you in the right direction :)

 

By all means ask more questions if you get stuck btw!

 

So.

 

Looking at your code, you're writing it like a recipe. While in theory this should work, due to a range of the osbot api's structure and general good coding form, writing like a recipe is a bad way to do it.

 

What you want is more if statements.

 

So for example, in your walk to bank state, you're instantly telling it to walk path4 (whatever that is). But perhaps add a check to see if it should / needs to walk this path.

 

If you add this kind of system for every section of the journey and make sure that there's no overlapping, you should be good to go :)

 

apa

The best way for you to learn is to figure this one out for yourself. That being said, i'll point you in the right direction smile.png

 

By all means ask more questions if you get stuck btw!

 

Thanks, i appreciate you not just giving me the answer. I solved the problem while taking a break, making another script biggrin.png now i got two working scripts.

  • Author

Thanks, i appreciate you not just giving me the answer. I solved the problem while taking a break, making another script biggrin.png now i got two working scripts.

 

Wooooo! :) glad you got this issues sold. By all means feel free to ask more questions tho, feel free to pm me too

 

gl!

apa

  • 2 weeks later...

Bro! Thanks for this. I'm quite skilled in Java, but this was just what i needed! Made this tea picking bot just by typing everything. No copy pasta. Just to analyze what everything is. Finished this tutorial, and now making an advanced woodcutting script!

I watched hoppyc0ding's video, but was very upset that his video is outdated. But then i tried this, and works like a charm.

Sir, you have just created another programmer!

Thanks bro, and you will see me posting scripts!

- Sebastian.

can someone help me?

 

i tried to make this script to a woodcutting script,

 

but the character doesnt chop....

 

tell me what im doing wrong please,

 

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

import java.awt.*;

@ScriptManifest(author = "Sgt.Roadkill", info = "My first woodcutting script", name = "Woodcutter", version = 0.1, logo = "")
public class main extends Script{
    
    @Override
    public void onStart(){
        log("Welcome to my First script for WOODCUTTING.");
        log("If you experience any issues with the script, please report them to me ;)");
        log("Enjoy the script, gain some WOODCUTTING levels.");
        }
    
    private enum State {
        CHOP, DROP, WAIT
    };
    private State getState() {
        Entity Willow = objects.closest("Willow");
        if (!inventory.isEmpty())
            return State.DROP;
        if (Willow != null)
            return State.CHOP;
        return State.WAIT;
    }
    
    @Override
    public int onLoop() throws InterruptedException {
        switch (getState()) {
        case CHOP:
            Entity Willow = objects.closest("Willow");
            if (Willow != null) {
                Willow.interact("Chop down");
            }
            break;
        case DROP:
            inventory.dropAll("Willow logs");
            break;
        case WAIT:
            sleep(random(500, 700));
            break;
        }
        return random(200, 300);
    }
    @Override
    public void onExit(){
        log("Thanks for running my WOODCUTTING script");
        }
    @Override
    public void onPaint(Graphics2D g){
        
    }
}
 

  • Author

can someone help me?

 

i tried to make this script to a woodcutting script,

 

but the character doesnt chop....

 

tell me what im doing wrong please,

 

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

import org.osbot.rs07.script.Script;

import org.osbot.rs07.script.ScriptManifest;

import java.awt.*;

@ScriptManifest(author = "Sgt.Roadkill", info = "My first woodcutting script", name = "Woodcutter", version = 0.1, logo = "")

public class main extends Script{

    

    @Override

    public void onStart(){

        log("Welcome to my First script for WOODCUTTING.");

        log("If you experience any issues with the script, please report them to me ;)");

        log("Enjoy the script, gain some WOODCUTTING levels.");

        }

    

    private enum State {

        CHOP, DROP, WAIT

    };

    private State getState() {

        Entity Willow = objects.closest("Willow");

        if (!inventory.isEmpty())

            return State.DROP;

        if (Willow != null)

            return State.CHOP;

        return State.WAIT;

    }

    

    @Override

    public int onLoop() throws InterruptedException {

        switch (getState()) {

        case CHOP:

            Entity Willow = objects.closest("Willow");

            if (Willow != null) {

                Willow.interact("Chop down");

            }

            break;

        case DROP:

            inventory.dropAll("Willow logs");

            break;

        case WAIT:

            sleep(random(500, 700));

            break;

        }

        return random(200, 300);

    }

    @Override

    public void onExit(){

        log("Thanks for running my WOODCUTTING script");

        }

    @Override

    public void onPaint(Graphics2D g){

        

    }

}

 

 

are you sure the name is 'Willow' not 'Willow tree'?

 

if you get the name wrong, it will always be null and hence won't get into the chop  state.

apa

Replace this:

 

            if (Willow != null) {
                Willow.interact("Chop down");
            }
       

 

With this:

		if (Willow != null) {
				if (Willow.isVisible()) {
					Willow.interact("Chop down");
				} else {
					sleep(random(500, 700));
				}
			}

The Willow.isVisible will check if the willow actually is visible. If it's visible, then chop. Else, it's gonna sleep for 500 till 700 milliseconds. Randomly. Hope that works buddy.

 

 

are you sure the name is 'Willow' not 'Willow tree'?

 

if you get the name wrong, it will always be null and hence won't get into the chop  state.

apa

 

 

 

Nope, the name for a willow tree is Willow. But i'm sure you already knew that.

Edited by OSRS Sebastian

Create an account or sign in to comment

Recently Browsing 0

  • No registered users viewing this page.

Account

Navigation

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.