Jump to content

Gold Bar Smelter (My First Script)


Spazbau5

Recommended Posts

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;
    }

}

 

  • Like 1
Link to comment
Share on other sites

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

  • Like 2
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...