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.

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

Featured Replies

  • 2 weeks later...

This is so good. Enjoy the free bump, I'm sure other people could also use this. :)

Is it not better to make a instance variable to hold the stall object? And only try to acquire that stall object under certain conditions?

Is it not better to make a instance variable to hold the stall object? And only try to acquire that stall object under certain conditions?

 

I assume you mean a global variable? You could do something like that if you wanted to, by doing so you would only need to find the tea stall once:

import org.osbot.rs07.api.model.Entity;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;
import org.osbot.rs07.utility.ConditionalSleep;

@ScriptManifest(author = "You", info = "My first script", name = "Tea thiever", version = 0.1, logo = "")
public final class TeaThiever extends Script {
    
    private Entity teaStall;

    @Override
    public final int onLoop() throws InterruptedException {
        if(teaStall == null) teaStall = getObjects().closest("Tea stall");
        else if(getInventory().isFull()) getInventory().dropAll();
        else if(teaStall.hasAction("Steal-from")) stealFromStall();
        return random(200, 300);
    }

    private void stealFromStall() {
        if(teaStall.interact("Steal-from")) {
            new ConditionalSleep(5000) {
                @Override
                public boolean condition() throws InterruptedException {
                    return myPlayer().isAnimating();
                }
            }.sleep();
        }
    }
} 

Edited by Explv

But you still make a new object of the steal stall every time you go through the loop, which is a lot. Is not better to do something like this (memory wise)? So you create the object once and use that same object. After all, it's not going to change or move.

private Entity teaStall;
boolean success = false;

public final int onLoop() throws InterruptedException {
    
    if (success == false) {
        teaStall = getObjects().closest("Tea stall");
        success = true;
    }
    if (teastall == null) {
        success false;
    }

}

Edited by Athylus

 

But you still make a new object of the steal stall every time you go through the loop, which is a lot. Is not better to do something like this (memory wise)? So you create the object once and use that same object. After all, it's not going to change or move.

private Entity teaStall;
boolean success = false;

public final int onLoop() throws InterruptedException {
    
    if (success == false) {
        teaStall = getObjects().closest("Tea stall");
        success = true;
    }
    if (teastall == null) {
        success false;
    }

}

 

:???: The code I commented with only gets the stall object once, and then stores it. The code you have written here is just a longer way of writing:

private Entity teaStall;

public final int onLoop() throws InterruptedException {
    
    if (teastall == null) teaStall = getObjects().closest("Tea stall");
}

Which is exactly what my code does. Also I would not concern yourself with memory usage here.

  • 2 weeks later...

The getstate() if's should be looking at the current state and not signals from outside, that should happen inside the if's. Also stall != null is unnecessary checked twice

Edited by piettjan

Got me on the path to programming for OSBot, this is nice to have all of these resources in one place to get going (especially for people who know java already, having a basic thing to look at is great !)

 

Thanks for putting the time in.

Edited by Nebulae

import org.osbot.rs07.api.model.Entity;

import org.osbot.rs07.script.Script;

import org.osbot.rs07.script.ScriptManifest;

 

import java.awt.*;

 

@ScriptManifest(author = "You", info = "My first script", name = "Power Miner", version = 0, logo = "")

public class main extends Script {

 


    public void onStart() {

        log("gonna mine");

    }

    

    private enum State {

    MINE, DROP, WAIT

    };

 

    private State getState() {

    Entity Rocks = objects.closest("Rocks");

    if (!inventory.isEmpty())

    return State.DROP;

    if (Rocks != null)

    return State.MINE;

    return State.WAIT;

    }

    


    public int onLoop() throws InterruptedException {

    switch (getState()) {

    case MINE:

    Entity Rocks = objects.closest("Rocks");

    if (Rocks != null) {

    Rocks.interact("Mine-from");

    }

    break;

    case DROP:

    inventory.dropAll();

    break;

    case WAIT:

    sleep(random(500, 700));

    break;

    }

        return random(200, 300);

    }

 


    public void onExit() {

        log("mining done");

    }

 


    public void onPaint(Graphics2D g) {

 

    }

 

}

 

only hovers over rocks doesnt actually mine

Edited by hariake

  • Author

 

import org.osbot.rs07.api.model.Entity;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;
 
import java.awt.*;
 
@ScriptManifest(author = "You", info = "My first script", name = "Power Miner", version = 0, logo = "")
public class main extends Script {
 
    public void onStart() {
        log("gonna mine");
    }
    
    private enum State {
    MINE, DROP, WAIT
    };
 
    private State getState() {
    Entity Rocks = objects.closest("Rocks");
    if (!inventory.isEmpty())
    return State.DROP;
    if (Rocks != null)
    return State.MINE;
    return State.WAIT;
    }
    
    public int onLoop() throws InterruptedException {
    switch (getState()) {
    case MINE:
    Entity Rocks = objects.closest("Rocks");
    if (Rocks != null) {
    Rocks.interact("Mine-from");
    }
    break;
    case DROP:
    inventory.dropAll();
    break;
    case WAIT:
    sleep(random(500, 700));
    break;
    }
        return random(200, 300);
    }
 
    public void onExit() {
        log("mining done");
    }
 
    public void onPaint(Graphics2D g) {
 
    }
 
}
 
only hovers over rocks doesnt actually mine

 

 

If that happens, you've spelt the interaction wrong. For example, perhaps you spelt 'rocks' wrong, or 'mine-from' incorrectly. And when I say incorrectly I mean based on the ingame object. Hover your mouse over the rock and copy exactly what the option and interaction options are!

If that happens, you've spelt the interaction wrong. For example, perhaps you spelt 'rocks' wrong, or 'mine-from' incorrectly. And when I say incorrectly I mean based on the ingame object. Hover your mouse over the rock and copy exactly what the option and interaction options are!

 

Ive triple checked all spellings, nothing seems wrong. Are you sure there cant be any other causes, script finds the rocks and cycles throgh them all but never clicking on them.

 

Edit: nvm my bad its actually just "mine" not "mine-from"

Edited by hariake

Question, what ever way i do mining. The bot keeps clicking on different ores. How to stop the clicking after bot has started mining and until he has mined the ore?

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.