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.

Gold Bar Smelter (My First Script)

Featured Replies

Here is the first script I've ever made. I happened to be in Port Phasmatys at the time and had gold ore in my bank lol. All feedback is very appreciated.

 

import org.osbot.rs07.api.map.Area;
import org.osbot.rs07.api.model.RS2Object;
import org.osbot.rs07.api.ui.RS2Widget;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;
import org.osbot.rs07.utility.ConditionalSleep;

import java.awt.*;

@ScriptManifest(name = "Gold Smelter", author = "Spazbau5", version = 0.1, info = "Smelts gold bars in Port Phasmatys", logo = "")
public class main extends Script {

    private final Area FORGE_AREA = new Area(3689, 3481, 3682, 3477);
    private final Area BANK_AREA = new Area(3691, 3471, 3686, 3466);

    @Override
    public void onStart() {
        log(getName() + " v" + getVersion() + " has started!");
    }

    @Override
    public void onExit() {
        log(getName() + " v" + getVersion() + " has stopped!");
    }

    @Override
    public int onLoop() throws InterruptedException {
        switch (getState()) {
            case SMELT:
                log("Current state: SMELT");
                RS2Object forge = getObjects().closest("Furnace");

                if (forge != null) {
                    if (!myPlayer().isAnimating()) {
                        RS2Widget smeltButton = getWidgets().get(270, 19);

                        if (smeltButton != null) {
                            smeltButton.interact("Smelt");
                            getMouse().moveOutsideScreen();
                        } else {
                            sleep(1000);
                            if (!myPlayer().isAnimating()) {
                                forge.interact("Smelt");
                                return random(4000, 5000);
                            }
                        }
                    }
                }
                break;

            case WALK_TO_FORGE:
                log("Current state: WALK_TO_FORGE");
                getWalking().webWalk(FORGE_AREA);
                break;

            case WALK_TO_BANK:
                log("Current state: WALK_TO_BANK");
                getWalking().webWalk(BANK_AREA);
                break;

            case DEPOSIT:
                log("Current state: DEPOSIT");
                if (bank.isOpen()) {
                    bank.depositAll();
                } else {
                    RS2Object bankBooth = getObjects().closest("Bank booth");

                    if (bankBooth != null && bankBooth.interact("Bank")) {
                        new ConditionalSleep(10000) {
                            @Override
                            public boolean condition() {
                                return bank.isOpen();
                            }
                        }.sleep();
                    }
                }
                break;

            case WITHDRAW:
                log("Current state: WITHDRAW");
                if (bank.isOpen()) {
                    bank.withdrawAll("Gold ore");
                } else {
                    RS2Object bankBooth = getObjects().closest("Bank booth");

                    if (bankBooth != null && bankBooth.interact("Bank")) {
                        new ConditionalSleep(10000) {
                            @Override
                            public boolean condition() {
                                return bank.isOpen();
                            }
                        }.sleep();
                    }
                }
                break;

            case IDLE:
                log("Current state: IDLE");
        }
        return random(700, 2300);
    }

    @Override
    public void onPaint(Graphics2D g) {

    }

    enum State {
        WALK_TO_BANK, DEPOSIT, WITHDRAW, WALK_TO_FORGE, SMELT, IDLE
    }

    private State getState() {

        if (!getInventory().contains("Gold ore")) {
            if (getInventory().isEmpty()) {
                log("Entering state: WITHDRAW");
                return State.WITHDRAW;
            } else {
                log("Entering state: DEPOSIT");
                return State.DEPOSIT;
            }
        }

        if (getInventory().contains("Gold ore")) {
            if (!FORGE_AREA.contains(myPlayer())) {
                log("Entering state: WALK_TO_FORGE");
                return State.WALK_TO_FORGE;
            } else {
                log("Entering state: SMELT");
                return State.SMELT;
            }
        } else if (getInventory().contains("Gold bar")) {
            if (!BANK_AREA.contains(myPlayer())) {
                log("Entering state: WALK_TO_BANK");
                return State.WALK_TO_BANK;
            } else {
                log("Entering state: DEPOSIT");
                return State.DEPOSIT;
            }
        }

        log("Entering state: IDLE");
        return State.IDLE;
    }

}

 

Looks good! Thanks for sharing (:

Just a few comments about the code, it looks like you've got a good conditional structure - well done on that!

  • I would recommend against static sleeps (e.g your 'sleep(1000)')
  • I'd say an early return in a case statement is probably not the best idea - if you need a sleep, put a conditional one there!
  • I would advise against using webwalker for any situation other than when your starting point is unknown in relation to your destination. For short back & forth journeys, stick to path walking! (:

Best

Apa

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.