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