Jump to content

[Open source] Dubai's OakBanker


dubai

Recommended Posts

Dubai's OakBanker

Oak-Banker8hours.png

Chops and banks Oak logs north of falador.

-Will only bank logs, not axes.

 

HOW TO RUN:

-Start at falador west bank.

 

I wrote this quickly for a farm I was working on so it's kinda messy but it works really well, I've had some huge runtimes on it so thought I'd release it. I plan to start adding mule support into my scripts now so I might come back to this one for that.

 

------------------------------------------------------------------

DOWNLOAD (Add to your OSBot\Scripts folder)

------------------------------------------------------------------

 

SOURCE:

Spoiler
package Scripts;

import org.osbot.rs07.api.map.Area;
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 org.osbot.rs07.api.ui.Message;

import java.awt.*;
import antiban.basicAB;
import ExtraFeatures.EnableRun;

@ScriptManifest(author = "Dubai", info = "Chops Oak Trees and Banks", name = "Oak Banker", version = 1.0, logo = "")
public class OakBanker extends Script {

    private static final String OAK_LOGS = "Oak logs";
    private static final int OAK_TREE_ID = 10820;
    private static final int ANTIBAN_THRESHOLD = 20; // Adjust this threshold as needed

    private EnableRun enableRun;
    private basicAB antibanInstance; // Create an instance of basicAB

    private final Area bankArea = new Area(2944, 3368, 2947, 3371);
    private final Area treeArea = new Area(2946, 3397, 2958, 3411);

    private enum State {
        CHOPPING, WALKING_TO_BANK, DEPOSITING, WALKING_TO_TREE
    }

    private State currentState;
    private long startTime;
    private int startLevel;
    private int logsChopped;

    @Override
    public void onStart() {
        currentState = State.WALKING_TO_TREE;
        startTime = System.currentTimeMillis();
        startLevel = getSkills().getStatic(Skill.WOODCUTTING);
        logsChopped = 0;
        enableRun = new EnableRun(this);
        antibanInstance = new basicAB(this); // Instantiate basicAB with `this` script instance
        log("Script started.");
    }

    @Override
    public int onLoop() throws InterruptedException {
        triggerAntiban();
        enableRun.enableRunMode();

        log("Current state: " + currentState);

        switch (currentState) {
            case CHOPPING:
                chopTree();
                break;
            case WALKING_TO_BANK:
                walkToBank();
                break;
            case DEPOSITING:
                depositLogs();
                break;
            case WALKING_TO_TREE:
                walkToTree();
                break;
        }
        return random(1200, 1400);
    }

    @Override
    public void onMessage(Message message) {
        if (message.getMessage().contains("You get some oak logs.")) {
            logsChopped++;
        }
    }

    @Override
    public void onPaint(Graphics2D g) {
        long runTime = System.currentTimeMillis() - startTime;
        int currentLevel = getSkills().getStatic(Skill.WOODCUTTING);
        int levelsGained = currentLevel - startLevel;

        g.setColor(Color.WHITE);
        g.drawString("Runtime: " + formatTime(runTime), 10, 30);
        g.drawString("Woodcutting Level: " + currentLevel + " (+" + levelsGained + ")", 10, 45);
        g.drawString("Logs Chopped: " + logsChopped, 10, 60);
    }

    private State getState() {
        if (getInventory().isFull() && currentState != State.DEPOSITING) {
            return State.WALKING_TO_BANK;
        }
        return currentState;
    }
    private boolean isInventoryFull() {
        // Implement the actual inventory full check logic here
        // This is a placeholder implementation, replace it with your actual logic
        return getInventory().isFull();
    }
    private void chopTree() throws InterruptedException {
        if (isInventoryFull()) {
            currentState = State.WALKING_TO_BANK;
            return;
        }

        Entity tree = getClosestReachableTree();
        if (tree != null) {
            if (tree.interact("Chop down")) {
                currentState = State.CHOPPING;
                waitForChop(tree);
            } else {
                log("Unable to interact with the tree.");
                currentState = State.WALKING_TO_TREE;
            }
        } else {
            log("Tree not found.");
            currentState = State.WALKING_TO_TREE;
        }
    }

    private void waitForChop(Entity tree) throws InterruptedException {
        while (tree.exists() && !getInventory().isFull()) {
            sleep(random(1000, 1500));
            triggerAntiban(); // Trigger antiban during chopping
        }
    }

    private void walkToBank() throws InterruptedException {
        if (bankArea.contains(myPosition())) {
            if (currentState != State.DEPOSITING) {
                currentState = State.DEPOSITING;
                log("Arrived at bank area. Switching state to DEPOSITING.");
            }
        } else {
            log("Walking to bank area...");
            getWalking().webWalk(bankArea);
        }
    }

    private void depositLogs() throws InterruptedException {
        final String bankBoothAction = "Bank";
        Entity bankBooth = getObjects().closest(obj -> obj.hasAction(bankBoothAction));

        if (bankBooth == null) {
            log("No bank booth found nearby.");
            return;
        }

        if (!getBank().isOpen()) {
            log("Trying to open the bank booth...");
            if (bankBooth.interact(bankBoothAction)) {
                sleepUntil(() -> getBank().isOpen(), 5000);

                if (!getBank().isOpen()) {
                    log("Failed to open the bank after 5 seconds.");
                    currentState = State.WALKING_TO_BANK;
                    return;
                }
            } else {
                log("Failed to interact with the bank booth.");
                return;
            }
        }

        if (getBank().isOpen()) {
            log("Bank is open. Attempting to deposit Oak logs...");
            if (getBank().depositAll(OAK_LOGS)) {
                sleep(random(300, 600));
                log("All Oak logs deposited successfully.");
                getBank().close();
                sleep(random(300, 600));
                log("Bank closed. Switching state to WALKING_TO_TREE.");
                currentState = State.WALKING_TO_TREE;
            } else {
                log("Failed to deposit Oak logs.");
            }
        }
    }

    private void walkToTree() throws InterruptedException {
        if (treeArea.contains(myPosition())) {
            currentState = State.CHOPPING;
            log("Arrived at tree area. Switching state to CHOPPING.");
        } else {
            log("Walking to tree area...");
            getWalking().webWalk(treeArea);
        }
    }

    private Entity getClosestReachableTree() {
        return getObjects().closest(obj -> obj.getId() == OAK_TREE_ID && obj.hasAction("Chop down") && obj.isVisible());
    }

    private void triggerAntiban() throws InterruptedException {
        if (random(0, 100) < ANTIBAN_THRESHOLD) {
            antibanInstance.performAntiBan(); // Call the non-static method on the instance
        }
    }

    private String formatTime(long ms) {
        long seconds = (ms / 1000) % 60;
        long minutes = (ms / (1000 * 60)) % 60;
        long hours = (ms / (1000 * 60 * 60)) % 24;
        return String.format("%02d:%02d:%02d", hours, minutes, seconds);
    }

    // Utility method to wait until a certain condition is met or a timeout is reached
    private boolean sleepUntil(BooleanSupplier condition, long timeoutMillis) throws InterruptedException {
        long start = System.currentTimeMillis();
        while (System.currentTimeMillis() - start < timeoutMillis) {
            if (condition.getAsBoolean()) {
                return true;
            }
            sleep(100);
        }
        return false;
    }

    // Functional interface for the sleepUntil method
    @FunctionalInterface
    private interface BooleanSupplier {
        boolean getAsBoolean();
    }
}

 

 

Edited by dubai
Fixed download link
Link to comment
Share on other sites

Nice script!

Just a thought, but maybe an area of improvement might be to make a custom sleep class/function, with optional "antiban", although I must say, I haven't found that the addition of antiban type features actually does reduce ban rate

private void waitForChop(Entity tree) throws InterruptedException {
        while (tree.exists() && !getInventory().isFull()) {
            sleep(random(1000, 1500));
            triggerAntiban(); // Trigger antiban during chopping
        }
    }

Here for example, you are waiting a fairly fixed amount of time, then performing an antiban action

It would be better to write a class hosting a function that runs a while loop that sleeps every 50ms or so, and boolean checks for the tree to be chopped, however, unlike conditionalsleep function that already exists, you can add antiban into the loop such as changing tabs, examining a random nearby object, etc

You would have to refactor the % chance though to accomodate for the while loop running so often

Link to comment
Share on other sites

13 minutes ago, Fanny said:

Nice script!

Just a thought, but maybe an area of improvement might be to make a custom sleep class/function, with optional "antiban", although I must say, I haven't found that the addition of antiban type features actually does reduce ban rate

private void waitForChop(Entity tree) throws InterruptedException {
        while (tree.exists() && !getInventory().isFull()) {
            sleep(random(1000, 1500));
            triggerAntiban(); // Trigger antiban during chopping
        }
    }

Here for example, you are waiting a fairly fixed amount of time, then performing an antiban action

It would be better to write a class hosting a function that runs a while loop that sleeps every 50ms or so, and boolean checks for the tree to be chopped, however, unlike conditionalsleep function that already exists, you can add antiban into the loop such as changing tabs, examining a random nearby object, etc

You would have to refactor the % chance though to accomodate for the while loop running so often

To be honest I dont think this method of anti ban stratagy is effective at all after testing 😛 I think the real magic is when AI is baught into bots to bring them to life. Something I really want to start looking into.

Link to comment
Share on other sites

On 9/9/2024 at 7:26 PM, Fanny said:

What use cases are you thinking?

Ultimately LLMs that can complete the game from; account creation to maxing while beating bot detection. I think thats the end game anyway. With input spoofing, how can we truly detect AI? I mean ethically of course...

 

On 9/10/2024 at 5:41 AM, Dextrell said:

Clean and straightforward great work!

Thank you!

Link to comment
Share on other sites

  • 3 weeks later...
14 minutes ago, dubai said:

It looks like what you are sharing are one-time links. I got it downloaded, but upon revisiting the link it's no longer available. Using Mediafire or something else you should have unlimited downloads automatically allowed. 
The below screenshot was taken before downloading:

G3T2y1p.png

 

Also FYI that's the class / source files, not a .jar. I can't use that unfortunately haha. Might be good to learn some coding myself with it though!

Edited by tmanowen
not a .jar
  • Sad 1
Link to comment
Share on other sites

3 hours ago, tmanowen said:

Also FYI that's the class / source files, not a .jar. I can't use that unfortunately haha. Might be good to learn some coding myself with it though!

If you extract the .class files into your osbot scripts folder, it will show up in your osbot client.

Also I had no idea the default for file.io was to delete after downloading... oops

I'll update the link in the OP to mediafire: https://www.mediafire.com/file/9i1d7yip816i59h/OakBanker$1.zip/file

Edited by dubai
Link to comment
Share on other sites

8 hours ago, dubai said:

If you extract the .class files into your osbot scripts folder, it will show up in your osbot client.

Also I had no idea the default for file.io was to delete after downloading... oops

I'll update the link in the OP to mediafire: https://www.mediafire.com/file/9i1d7yip816i59h/OakBanker$1.zip/file

Oh haha, cool! Thanks for educating me on that.

Edit: I unfortunately haven't been able to get it to work either having the class files or the 'Oak Banker$1' folder within my C:\Users\MYNAME\OSBot\Scripts folder
This is the error in general I'm receiving within the client:

[ERROR][10/29 10:56:39 AM]: Failed to load local script : C:\Users\MYNAME\OSBot\Scripts\OakBanker$1\OakBanker$1.class
[ERROR][10/29 10:56:39 AM]: Failed to load local script : C:\Users\MYNAME\OSBot\Scripts\OakBanker$1\OakBanker$BooleanSupplier.class
[ERROR][10/29 10:56:39 AM]: Failed to load local script : C:\Users\MYNAME\OSBot\Scripts\OakBanker$1\OakBanker$State.class
[ERROR][10/29 10:56:39 AM]: Failed to load local script : C:\Users\MYNAME\OSBot\Scripts\OakBanker$1\OakBanker.class

I even tried changing the folder name to not have the $'s and alternatively tried the .class names to not contain the $. No iteration of the files appeared to have it working for me. 

Link to comment
Share on other sites

On 10/30/2024 at 1:59 AM, tmanowen said:

Edit: I unfortunately haven't been able to get it to work either having the class files or the 'Oak Banker$1' folder within my C:\Users\MYNAME\OSBot\Scripts folder
This is the error in general I'm receiving within the client:

Hmm strange, I was running my scripts like this for a while..
Not to worry, when I get back to my workstation I'll create a new .jar for this if you're still keen to try it.

  • Heart 1
Link to comment
Share on other sites

  • 2 weeks later...

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...