Jump to content

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


Apaec

Recommended Posts

Thanks :) will definitely try to start something simple. Now with a woodcutting script or mining could I use a similar layout as this script but change some wording around to fit woodcutting. Inside of steal from Tea Stall it'd go to Chop Tree or Mine rock, can't remember what it's actually called in game off the top but my head. 

  • Like 1
Link to comment
Share on other sites

2 hours ago, mike3zx said:

Edit: Figured out pathing, just need to figure out how to search is the player is in a certain location. The video I watched used the method (getLocalPlayer) but it doesn't seem to work for OSBot. Where in the api should I be looking to find this?

 

Here's a link to the OSBot API:

https://osbot.org/api/

To check if you're at a location, i'd take a look at the Area API: https://osbot.org/api/org/osbot/rs07/api/map/Area.html

Then, you can do something like:

Area someArea = new Area(500,600,700,800);
if (someArea.contains(myPlayer())) {
  log("hello!");
}

 

  • Like 1
Link to comment
Share on other sites

I'm stuck with getting my script to work. It just stands still 

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

import java.awt.*;

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


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

    @Override
    public int onLoop() throws InterruptedException
    {
        NPC FishingSpot = this.getNpcs().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) {

    }

}

Anything you notice to be wrong? Cheers

Link to comment
Share on other sites

42 minutes ago, mitsuki said:

I'm stuck with getting my script to work. It just stands still 


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

import java.awt.*;

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


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

    @Override
    public int onLoop() throws InterruptedException
    {
        NPC FishingSpot = this.getNpcs().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) {

    }

}

Anything you notice to be wrong? Cheers

Hey,

That code looks good. I'm not exactly sure about fishing spots, though they may be NPCs rather than RS2Objects, as you assume. I think your problem might be with your definition strings. Are you sure that 'Net Fishing spot' is the interaction action? This is case sensitive and has to be exactly correct. Likewise, are you sure that the object (NPC) is called 'Net Fishing spot'? again, this has to be exactly correct.

-Apa

Link to comment
Share on other sites

I figured it out after. I never checked if the inventory was full, and therefore, the else if statement never ran. Cheers for your speedy response though. Any advice on how to start learning to move the player? like walking to a specific spot, or going to the bank? 

Cheers for all of the help dude, such doge

Link to comment
Share on other sites

3 hours ago, mitsuki said:

I figured it out after. I never checked if the inventory was full, and therefore, the else if statement never ran. Cheers for your speedy response though. Any advice on how to start learning to move the player? like walking to a specific spot, or going to the bank? 

Cheers for all of the help dude, such doge

Hey,

Great, sounds like good progress - baby steps! To learn this stuff, take it one step at a time, e.g. 'how do I walk to a tile'. Then think about areas, recording paths, webwalking. All of these can be learnt about through trial and error, and through reading the API. As ever, let me know if you have any questions or need any help. Always happy to reply; I understand the difficulty of this learning curve so ask as many questions as you can!

-Apa

Link to comment
Share on other sites

Ahh okay, thank you. Just reading the api seems like a nightmare, just trying to work out how to use it.

I found this line of code to create an area:

public Area(int x1,
            int y1,
            int x2,
            int y2)

Would you essentially do this?:

public Area(3000 x1,
            3000 y1,
            3100 x2,
            3100 y2)

and it would make a square area within 3000 x, 3000 y - 3100 x, 3000 y - 3100 x, 3100 y - 3000 x, 3100 y  ?

and I also can't tell how to name the area, or do you do something like:

Lumbridge == public Area(3000 x1,
            			 3000 y1,
            			 3100 x2,
            			 3100 y2)

Is there a tutorial on how to read the api? Thank you dude

Link to comment
Share on other sites

57 minutes ago, mitsuki said:

Ahh okay, thank you. Just reading the api seems like a nightmare, just trying to work out how to use it.

I found this line of code to create an area:


public Area(int x1,
            int y1,
            int x2,
            int y2)

Would you essentially do this?:


public Area(3000 x1,
            3000 y1,
            3100 x2,
            3100 y2)

and it would make a square area within 3000 x, 3000 y - 3100 x, 3000 y - 3100 x, 3100 y - 3000 x, 3100 y  ?

and I also can't tell how to name the area, or do you do something like:


Lumbridge == public Area(3000 x1,
            			 3000 y1,
            			 3100 x2,
            			 3100 y2)

Is there a tutorial on how to read the api? Thank you dude

Hey,

These are methods of the Area class. 'public Area' is the constructor: it's saying that you can construct an Area with four integers.

vNknN0V.png

The description here should be sufficiently explanatory. You would construct an area as follows:

public Area myArea = new Area(100, 200, 300, 400);

where the bottom left tile is (100,200), and the top right tile is (300, 400). Here, 'public' is just the access modifier, public is fine in this context. Alternatives include 'private' and 'protected', but I wouldn't worry about those too much for now.

You can then do handy stuff like checking if you're in the area:

if (myArea.contains(myPlayer())) {
  log("hi!");
}

etc.

There isn't a tutorial on how to read the API (to my knowledge) - it is based on javadocs so the layout is standard, and it just tells you classes and methods, there's not a lot more to it. In general, the left hand pane will list the important classes that you will need. Then, when you select a class (e.g. 'Area'), you will be shown the constructor (if applicable) and the methods belonging to that class.

If you're still struggling with this stuff (which is perfectly natural, this is a lot to take in in one go!), i'd strongly recommend giving this tutorial a read. The official oracle tutorials are great for getting the basics in understanding of this stuff: https://docs.oracle.com/javase/tutorial/java/index.html

Best of luck! And let me know if you need anything else. Always happy to help.

Apa

Link to comment
Share on other sites

13 minutes ago, Apaec said:

Hey,

These are methods of the Area class. 'public Area' is the constructor: it's saying that you can construct an Area with four integers.

vNknN0V.png

The description here should be sufficiently explanatory. You would construct an area as follows:


public Area myArea = new Area(100, 200, 300, 400);

where the bottom left tile is (100,200), and the top right tile is (300, 400). Here, 'public' is just the access modifier, public is fine in this context. Alternatives include 'private' and 'protected', but I wouldn't worry about those too much for now.

You can then do handy stuff like checking if you're in the area:


if (myArea.contains(myPlayer())) {
  log("hi!");
}

etc.

There isn't a tutorial on how to read the API (to my knowledge) - it is based on javadocs so the layout is standard, and it just tells you classes and methods, there's not a lot more to it. In general, the left hand pane will list the important classes that you will need. Then, when you select a class (e.g. 'Area'), you will be shown the constructor (if applicable) and the methods belonging to that class.

If you're still struggling with this stuff (which is perfectly natural, this is a lot to take in in one go!), i'd strongly recommend giving this tutorial a read. The official oracle tutorials are great for getting the basics in understanding of this stuff: https://docs.oracle.com/javase/tutorial/java/index.html

Best of luck! And let me know if you need anything else. Always happy to help.

Apa

You, sir, are a godsend. Thank you for having the patience to explain all of this to me. I actually know a load of basic Java, but never had to try reading an api, or doing anything too creative, other than creating arrays and lists and stuff for uni projects.

Thank you so much dude

Link to comment
Share on other sites

Managed to get it to walk to the area that I want finally! The only problem was that it only walked to the area if it is a 10 second walk away or less. Managed to use webWalking instead, and it seems to work much better

It walks to my area, and nets fish until the inventory is full, then drops them all!

How would I give the user an option, say to choose to bank or not? That way, I could try to add code to walk to the closest bank, and bank it all

 

 

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

1 hour ago, mitsuki said:

You, sir, are a godsend. Thank you for having the patience to explain all of this to me. I actually know a load of basic Java, but never had to try reading an api, or doing anything too creative, other than creating arrays and lists and stuff for uni projects.

Thank you so much dude

 

38 minutes ago, mitsuki said:

Managed to get it to walk to the area that I want finally! The only problem was that it only walked to the area if it is a 10 second walk away or less. Managed to use webWalking instead, and it seems to work much better

Ah great! So you have some experience with Java through university. That'll definitely help in shallowing the learning curve.

Regarding webwalking, as I said, this system is---by nature---much less reliable than a hard-coded sequence of positions which constitute a path. So, if the route you're walking is regular and known, i'd strongly recommend recording a path (there are tools for this on the SDN, or local section I believe. Or, make your own!). Then, you can use the walkPath method which will be more reliable and resource-efficient.

GL!

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