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.

Babby's first script

Featured Replies

Hello botters,

 

I made the following script just for practice. It is intended to withdraw bones of any kind from the bank and bury them.


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

import java.awt.*;

@ScriptManifest(author = "Drokle", info = "Babby's first script", name = "DrokleBone", version = 0, logo = "")


public class DrokleBone extends Script {

    @Override
    public void onStart(){
        log("This is it, you're running DrokleBone!");
    }

    private enum State {
        BANK, BONE
    }


    @Override
    public int onLoop() throws InterruptedException {

        Item[] pockets = inventory.getItems();

        for(Item thing: pockets)
        {
            if(thing.hasAction("Bury"))
                thing.interact("Bury");

            sleep(random(500,550));
        }

        RS2Object booth = getObjects().closest("Bank booth");

        bank.open();
        Item[] vault = bank.getItems();

        for(Item thing: vault)
        {
            if(thing.nameContains("Bones")||thing.nameContains("bones"))
                thing.interact("Withdraw-All");
            if(inventory.getEmptySlotCount() == 0)
                break;
            sleep(random(500,700));
        }

        return random(400,800);
    }

    @Override
    public void onExit() {
        log("This is has been DrokleBone, hope you had a good one.");
    }

    @Override
    public void onPaint(Graphics2D g) {
        g.drawString("THIS IS IT, YOU'RE RUNNING DROKLEBONE!! GOOD JOB!!!!", 50,50);
    }

}

 

For some reason, when I run it, the VM eventually becomes unresponsive and I can't shut it down. Could anyone help me figure out why? It happens if I use it to bury bones far away from any bank.

 

Best,

Drokle

First of all, the reason that it is crashing is that the variable "booth" which represents a Bank booth is null if there is no bank booth loaded in the game near you, so when you call bank.open() it will throw a nullpointerexception. Second, you never used your states that you set up in the enum, so on every loop, it buries all bones you have in your inventory and opens the bank to withdraw more. I suggest you follow one of the guides to learn the flow that should be followed. Generally, only one action should be performed per loop of the onloop method. Meaning that each iteration only one interaction should occur in the game that takes place over the course of a tick. In your script, you are doing many.

Hope that helps :)

Edited by TheWind

Hey ! 

Good effort! As @TheWind said, the key is to have one and only one 'action' line execute in one onLoop iteration. The reason for this is that you are programming for a live game and as such issues such as latency fluctuations can result in interactions failing. If you're relying on an interaction to succeed for future lines of code, this can cause horrible errors! A classic example is banking. For example calling:

getBank().open();
getBank().withdraw("Example", 500);

Is a big error - ask yourself, what if the first line fails? The the script will try to withdraw stuff from the bank but it's not open - uh oh! Instead, you want to make it only do what it needs to based on the current situation:

if (getBank().isOpen()) {
  if (getBank().contains("Example") && getBank().getAmount("Example") >= 500) {
    getBank().withdraw("Example", 500);
    //Conditional sleep here
  } else {
    log("Not enough Example in bank");
    stop();
  }
} else {
  getBank().open();
}

-Apa

Edited by Apaec

  • Author

Thanks!

Oh wow, that explains a lot. So does OSbot hang if an invalid command is being used?

Create an account or sign in to comment

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.