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.

dynamic task selection

Featured Replies

Hey guys!

 

Newbie here. I'm writing my first chopper script using a standard node/task based framework, and I want to introduce a way to dynamically select a task (position, target, endconditions) when my script starts.

 

More specifically, I'm looking for some code magic that will run once on start, hold a few pieces of data, and be referable from within any of my node classes. Unfortunately I'm new to programming, so I'm clueless as to where I would even start searching for such a thing.

 

I attempted coding a task object which held static variables and was instantiated in my main script class, but I ran into goofy runtime errors that have me thinking there's a better way to accomplish my goal.

 

 

 

I did create a similar framework.

I'm not quite sure if I understand you right however.

Do you mean you want to add / pause / remove tasks / nodes on conditions from any other task you're running at the moment?

If so, I can help you.

 

I attempted coding a task object which held static variables and was instantiated in my main script class, but I ran into goofy runtime errors that have me thinking there's a better way to accomplish my goal.

 

Not sure if I fully understand you or not, but I am assuming you are trying to make an AIO chopper, where the user can select different locations etc.

 

This is a very simple example, which you can build upon.

 

You start by having an enum for each Tree, which contains an Area in which the trees can be found:

public enum Tree {

    NORMAL (new Area(0, 0, 0, 0)),
    OAK (new Area(0, 0, 0, 0));

    Area area;

    Tree(final Area area){
        this.area = area;
    }

    @Override
    public String toString(){
        char[] name = name().toLowerCase().toCharArray();
        name[0] = Character.toUpperCase(name[0]);
        return new String(name);
    }
}

Then when the script starts, have the user select what tree they want to chop:

import org.osbot.rs07.script.Script;

import javax.swing.*;

public class Woodchopper extends Script {

    @Override
    public void onStart() {

        Tree selectedTree = (Tree) JOptionPane.showInputDialog(null,
                "Select a Tree",
                "Woodchopper",
                JOptionPane.INFORMATION_MESSAGE,
                null,
                Tree.values(),
                Tree.values()[0]
        );
    }

    @Override
    public int onLoop() throws InterruptedException {
        return 0;
    }
}

Your Chop Node can then take the selected tree as a constructor parameter:

import org.osbot.rs07.script.Script;

public class ChopNode extends Node {

    private final Tree tree;

    public ChopNode(final Script S, final Tree tree) {
        super(S);
        this.tree = tree;
    }

    @Override
    public boolean validate() {
        return !S.getInventory().isFull();
    }

    @Override
    public void execute() {
        if(!tree.area.contains(S.myPosition())){
            S.getWalking().webWalk(tree.area);
        } else{
            chop();
        }
    }

    private void chop(){
        // chop the trees
    }
}

So now in your onStart, when you create the nodes, you can pass the selected Tree:

import org.osbot.rs07.script.Script;

import javax.swing.*;

public class Woodchopper extends Script {

    @Override
    public void onStart() {

        Tree selectedTree = (Tree) JOptionPane.showInputDialog(null,
                "Select a Tree",
                "Woodchopper",
                JOptionPane.INFORMATION_MESSAGE,
                null,
                Tree.values(),
                Tree.values()[0]
        );

        Node chopNode = new ChopNode(this, selectedTree);
    }

    @Override
    public int onLoop() throws InterruptedException {
        return 0;
    }
}

Hope that helps

  • Author
Hope that helps

 

Perfect! Your example was well structured and easy to understand, and is equivalent to what I'm attempting to accomplish. Thanks homie! 

 

Sorry for my garbled example tongue.png it seems you understood. You guessed correctly about the AIO; this is a nicely generalizable construction, so I'm thinking things will work out nicely smile.png

 

 

Edited by Jachos

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.