Jump to content

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


Apaec

Recommended Posts

 

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
Link to comment
Share on other sites

 

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

  • Like 1
Link to comment
Share on other sites

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 :]

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

  • Like 2
Link to comment
Share on other sites

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

  • Like 1
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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
  • Like 1
Link to comment
Share on other sites

  • Alek unpinned this topic

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