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.

Practical uses for MultiThreading

Featured Replies

I am trying to understand the uses of multithreading for OSBot. My idea is that I make a thread that runs async and monitors the player's health, stats, poison,... And when a certain action is required, for example eating a piece of food, does so. 

 

I created a (very) simple script demonstrating what I would like to accomplish with the multithreading. Is this the way to accomplish such a task?

 

PS: I am new to the OSBot API so I don't know if everything I wrote is correct :D 

import org.osbot.rs07.script.MethodProvider;

public class SupplyThread extends MethodProvider implements Runnable {

    private volatile boolean run = true;

    @Override
    public void run() {
        while(run) {
            try {
                if(myPlayer().getHealthPercent() < (75 * (Math.random())) || myPlayer().getHealthPercent() < 20){
                    if (getInventory().contains("Tuna")) {
                        if (getInventory().getSelectedItemName() == null) {
                            getInventory().getItem("Tuna").interact("Eat");
                        } else {
                            getInventory().deselectItem();
                        }
                    }
                    new ConditionalSleep(2000,1000) {
                        @Override
                        public boolean condition() throws InterruptedException {
                            return myPlayer().getAnimation() == 829;
                        }
                    }.sleep();
                }
                Thread.sleep(random(400, 650));
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }

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

 

1. I know I have volatile (for boolean) added to my own guide for multithreading but I don't think it's needed.

2. This will interfere with 'main' bot since this interaction is async. 

  • Author
1 hour ago, dreameo said:

1. I know I have volatile (for boolean) added to my own guide for multithreading but I don't think it's needed.

2. This will interfere with 'main' bot since this interaction is async. 

Thank you for the response @dreameo. So if I understand making a thread to take care of supplies and running that thread async is not the way to accomplish such a task? Should I put all supply logic in the main thread then?

I think async is fine but you need to be able to freeze all other running threads when a 'task' needs to be executed (only in some cases)

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.