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.

Instantiating separate event executor

Featured Replies

I'm creating a framework for one script with multiple tasks.

Is it feasible to instantiate a separate event executor to run events?

1 hour ago, camaro 09 said:

I'm creating a framework for one script with multiple tasks.

Is it feasible to instantiate a separate event executor to run events?

What kind of other tasks are you trying to run while running the main task?

 

You could multi-thread: More Info Here

Class

Spoiler

class HelperThread implements Runnable {
    private volatile boolean run = true;
    private volatile Script script;

    public HelperThread(Script script) {
        this.script = script;
    }

    @Override
    public void run() {
        while (run) {
            if (conditionalSleep(() -> script.myPlayer().isAnimating(), 10000, 500)) {
                if (conditionalSleep(() -> !script.myPlayer().isAnimating(), 10000, 500)) {
                    script.log("No Longer Animating");
                }
            }
        }
    }

    private boolean conditionalSleep(BooleanSupplier condition, int maxTime, int checkTime) {
        long startTime = System.currentTimeMillis();
        while (!condition.getAsBoolean() && (System.currentTimeMillis() - startTime) < maxTime) {
            try {
                Thread.sleep(checkTime);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        return condition.getAsBoolean();
    }

    public void stop() {
        this.run = false;
    }
}

Usage

Spoiler

import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;

@ScriptManifest(name = "@Test", author = "BravoTaco", version = 0, info = "", logo = "")
public class Main extends Script {

    private HelperThread helperThread;

    @Override
    public void onStart() throws InterruptedException {
        helperThread = new HelperThread(this);
        new Thread(helperThread).start();
    }

    @Override
    public int onLoop() throws InterruptedException {

        log("Main Thread Running!");

        return random(1300, 2300);

    }

    @Override
    public void onExit() throws InterruptedException {
        helperThread.stop();
    }
}

 

Edited by BravoTaco

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.