Jump to content

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


Apaec

Recommended Posts

Great Quickstart guide, thanks!

I did have to change .entity to .RS2Object in my code for some reason - I'm sure I will work out why as I read into the API more!
Also there have been some interface changes in newer versions of eclipse (since your screenshots), adding the osbot jar file to your library is in a different interface in eclipse neon.

Link to comment
Share on other sites

4 minutes ago, thatguycalledrob said:

Great Quickstart guide, thanks!

I did have to change .entity to .RS2Object in my code for some reason - I'm sure I will work out why as I read into the API more!
Also there have been some interface changes in newer versions of eclipse (since your screenshots), adding the osbot jar file to your library is in a different interface in eclipse neon.

Cheers (:

Yes, this guide is look overdue a re-write. Hopefully I can find time in the coming weeks to work on it!

Apa

Link to comment
Share on other sites

  • Alek unpinned this topic
  • 2 weeks later...
10 hours ago, BeefWellington said:

I am trying to compile this script and I get the .jar file into the scripts folder, but when I open OSBot it does not show up. How to fix this?

Are you sure the script successfully compiled, you didn't re-use the same name for a different jar, and the manifest is correct?

Otherwise there's no reason it shouldn't show up! Also make sure you have the build path set up correctly!

Link to comment
Share on other sites

I tried to make a simple power chopping script, building off of your tea thiever. However, it empties the inventory of logs and not the axe, like its supposed to, then it hovers over the tree and never attempts to chop. I think the issue is in using !inventory.isEmptyExcept 

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

import java.awt.*;

@ScriptManifest(author = "broker12", info = "Power chops", name = "OakChopper", version = 0, logo = "")
public class Main extends Script {

    @Override
    public void onStart() {
        log("OakChopper status: Started");
    }

    private enum State {
         CHOP, DROP, WAIT,
    };

    private State getState() {
        RS2Object tree = getObjects().closest("Oak");
        if (!inventory.isEmptyExcept("Rune axe"))
            return State.DROP;
        if (tree != null)
            return State.CHOP;
        return State.WAIT;
    }

    @Override
    public int onLoop() throws InterruptedException {
        switch (getState()) {
        case CHOP:
            RS2Object tree = getObjects().closest("Oak");
            if (tree != null) {
                tree.interact("Chop-down");
            }
            break;
        case DROP:
            inventory.dropAllExcept("Rune axe");
            break;
        case WAIT:
            sleep(random(400, 700));
            break;
        }
        return random(200, 300);
    }

    @Override
    public void onExit() {
        log("OakChopper status: Ended");
    }

    @Override
    public void onPaint(Graphics2D g) {

    }


Link to comment
Share on other sites

15 minutes ago, Broker12 said:

I tried to make a simple power chopping script, building off of your tea thiever. However, it empties the inventory of logs and not the axe, like its supposed to, then it hovers over the tree and never attempts to chop. I think the issue is in using !inventory.isEmptyExcept 


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

import java.awt.*;

@ScriptManifest(author = "broker12", info = "Power chops", name = "OakChopper", version = 0, logo = "")
public class Main extends Script {

    @Override
    public void onStart() {
        log("OakChopper status: Started");
    }

    private enum State {
         CHOP, DROP, WAIT,
    };

    private State getState() {
        RS2Object tree = getObjects().closest("Oak");
        if (!inventory.isEmptyExcept("Rune axe"))
            return State.DROP;
        if (tree != null)
            return State.CHOP;
        return State.WAIT;
    }

    @Override
    public int onLoop() throws InterruptedException {
        switch (getState()) {
        case CHOP:
            RS2Object tree = getObjects().closest("Oak");
            if (tree != null) {
                tree.interact("Chop-down");
            }
            break;
        case DROP:
            inventory.dropAllExcept("Rune axe");
            break;
        case WAIT:
            sleep(random(400, 700));
            break;
        }
        return random(200, 300);
    }

    @Override
    public void onExit() {
        log("OakChopper status: Ended");
    }

    @Override
    public void onPaint(Graphics2D g) {

    }


That sounds like you might have got the interaction name wrong; double check what the exact (case sensitive) interaction is by overing over the oak tree and looking at the tool tip!

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