Jump to content

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


Recommended Posts

Posted
2 minutes ago, lfcandy said:

@Apaec I get the same error now for RS2Object  now. I have the OSBot 2.4.118 jar in referenced libraries. Eclipse quick-fixed it for me when I clicked on RS2Object  and selected import RS2Object(or something similar). not sure what was going on

Can you send me a screenshot of the exact error you're getting perhaps?

  • 2 weeks later...
Posted (edited)

Alright so I'm trying to make a basic powerfisher using my very limited knowledge.

Here's what I have
 


 

Quote

 

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

@ScriptManifest(name = "skeetfish", author = "skeetballs", version = 1.0, info = "", logo = "") 

public class Todfish extends Script {

private enum State {
    FISH, DROP, WAIT
};

private State getState() {
    NPC fishspot = (NPC) objects.closest("Fishing Spot");
    if (!inventory.isEmptyExcept("Feather","Fly fishing rod"))
        return State.DROP;
    if (fishspot != null)
        return State.FISH;
    return State.WAIT;
}

@Override

public int onLoop() throws InterruptedException {

switch (getState()) {

case FISH:

NPC fishspot = (NPC) objects.closest("Fishing spot");

if (fishspot != null) {

fishspot.interact("Lure");

}

break;

case DROP:

inventory.dropAll("Trout","Salmon");

break;

case WAIT:

sleep(random(500, 700));

break;

}

return random(200, 300);

}
}
 

 

 

Edited by skeetballs
  • 1 month later...
  • 3 weeks later...
  • 2 weeks later...
Posted
37 minutes ago, osrs_pvm said:

Thanks for the guide, this will probably be me

To answer your previous question, you will see that our script extends Script. This is an abstract class in the OSBot API and since we are extending it, we have access to all of its attributes. An example of an attribute is inventory, whereby we are calling the super inventory object attribute and using the methods that it provides. As for the stall, you will find that that is initialised just above the snippet you quoted, we're creating an instance of an RS2Object which is an API object describing an ingame object. 

Hope that makes sense, let me know if you're still unsure. Since you edited the post I would assume you figured this out yourself but I just thought i'd drop a quick reply in to clear it up if you didn't!

-Apa

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

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