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.

Chop Drop Repeat - First Script

Featured Replies

So it seems to be a reoccurring pattern that everyone's first script is a simple wood cutter. So here is my attempt.

 

All critique is appreciated.

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

import java.awt.*;
import java.text.DecimalFormat;

@ScriptManifest(author = "Exponential", info = "A simple tree cutting script", name = "Chop Drop Repeat", version = 1.0, logo = "<==>")
public class Main extends Script {

    private long startTime;

    private int startXP;
    private int gainedXP;
    private int startLevel;
    private int currentLevel;

    private double XPPerHour;

    /* To reduce paint refresh rate */
    private int paintCount = 10;

    /* Formatting output to paint */
    private DecimalFormat df = new DecimalFormat("#.#");

    @Override
    public void onStart() {
        log("Welcome to Exponential's Chop Drop Repeat");
        startTime = System.currentTimeMillis();

        startXP = skills.getExperience(Skill.WOODCUTTING);
        startLevel = skills.getStatic(Skill.WOODCUTTING);
    }

    /**
     * Represents the states within the script
     */
    private enum State {
        CHOP, DROP, WAIT
    }

    private State getState() {
        if (inventory.isFull()) {
            return State.DROP;
        }
        if (myPlayer().isAnimating()) {
            return State.WAIT;
        }
        /* Current targets willow trees */
        Entity tree = objects.closest("Willow");
        if (tree != null) {
            return State.CHOP;
        }
        return State.WAIT;
    }

    @Override
    public int onLoop() throws InterruptedException {
        switch (getState()) {
            case CHOP:
                Entity tree = objects.closest("Willow");
                /* Check if there is a tree, and we're not running
                *  towards it already. */
                if (tree != null && !myPlayer().isMoving()) {
                    if (tree.isVisible()) {
                        tree.interact("Chop down");
                    } else {
                        camera.toEntity(tree);
                    }
                }
                break;
            case DROP:
                /* Axe must be wielded, else it will be dropped */
                inventory.dropAll();
                if (getInventory().isItemSelected()) getMouse().click(false);
                break;
            case WAIT:
                break;
        }
        return random(700, 900);
    }

    @Override
    public void onExit() {
        log("Thanks for running the script");
        log("You ran the script for " + ((System.currentTimeMillis() - startTime)/1000) + "seconds.");
    }

    @Override
    public void onPaint(Graphics2D g) {

        g.setColor(Color.WHITE);

        long runTime = System.currentTimeMillis() - startTime;
        g.drawString("Runtime - " + timeConversion(runTime), 20, 50);

        g.drawString("WC Level: (" +  currentLevel + ") + " + (currentLevel - startLevel), 20, 70);

        gainedXP = (skills.getExperience(Skill.WOODCUTTING) - startXP);
        currentLevel = skills.getStatic(Skill.WOODCUTTING);

        g.drawString("XP gained: " + gainedXP, 20, 90);

        /* Not necessary to update this every tick*/
        paintCount++;
        if (paintCount % 10 == 0) {
            XPPerHour = ((3600.0 / runTime) * gainedXP);
            XPPerHour = Double.valueOf(df.format(XPPerHour));
            /* Prevents this int getting to large */
            if (paintCount > 9000) paintCount = 0;
        }

        g.drawString("XP/hour: " + XPPerHour + "K", 20, 110);

        double perHour = XPPerHour * 1000;
        int nextLevelXP = skills.getExperienceForLevel(currentLevel + 1);
        int reqToLevel = nextLevelXP - (startXP + gainedXP);
        g.drawString("XP to level: " + reqToLevel, 20, 130);

        double ratio = reqToLevel/perHour;
        long timeTo = (long) (ratio * 60.0 * 60.0 * 1000);
        g.drawString("Time to level: " + timeConversion(timeTo), 20, 150);
    }

    /**
     * Converts the millis time to a readable h:m:s format
     *
     * @param runTime current runtime in millis
     *
     * @return h:m:s string
     */
    private String timeConversion(long runTime) {

        int totalSeconds = (int)runTime/1000;
        int seconds = totalSeconds % 60;
        int totalMinutes = totalSeconds / 60;
        int minutes = totalMinutes % 60;
        int hours = totalMinutes / 60;

        return hours + ":" + minutes + ":" + seconds;
    }

}

I added the line:

if (getInventory().isItemSelected()) getMouse().click(false);

to try and prevent a bug from happening when the bot selects a log, but doesn't drop it, and then fails to continue dropping any more logs as the item is still selected. Any ideas?

Edited by Exponential

Nice bot, here is some tips...

 

Here is how you only drop Willow logs insted of dropping all in the inventory

inventory.dropAll("Willow logs");

The

 if (getInventory().isItemSelected()) getMouse().click(false); 

will will no needed in the new API realse, for now use it. It is only a bug

Post from Android.

Edited by hajar424

Nice bot, here is some tips...

 

Here is how you only drop Willow logs insted of dropping all in the inventory

inventory.dropAll("Willow logs");

The

 if (getInventory().isItemSelected()) getMouse().click(false); 

will will no needed in the new API realse, for now use it. It is only a bug

Post from Android.

Teach me too :D 

Yea that's like reading another language to me but gl with ur script might as well get mirror while ur at it to decrease chance of bans

Edited by daamurda

goodluck on release 


Nice bot, here is some tips...

 

Here is how you only drop Willow logs insted of dropping all in the inventory

inventory.dropAll("Willow logs");

The

 if (getInventory().isItemSelected()) getMouse().click(false); 

will will no needed in the new API realse, for now use it. It is only a bug

Post from Android.

 

It doesn't matter if it's a bug now and won't be in a few days time, it should still be addressed.

 

A few things OP:

  • In the getState method, you search for a willow tree (much like in the onLoop method) - this means you search for a willow tree twice in rapid succession, and you may get different results.
  • for the drop method, you should have a loop instead: (this will give you more control for example if the getInventory().dropAll() gets stuck because the use button is clicked instead)
for (Item i : getInventory().getItems()) {
    if (i != null && i.getName().equals("Willow log")) {
        i.interact("Drop");
    }
}

Good luck! :)

  • Author

Thanks for the advice :D What exactly do I need to do to make the script work with mirror mode?

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.