Here's a custom webwalk event class that I use to perform actions while walking without delays
import org.osbot.rs07.api.map.Position;
import org.osbot.rs07.event.WebWalkEvent;
import org.osbot.rs07.utility.ConditionalSleep2;
public class CustomWebWalk extends WebWalkEvent {
private AsyncWalkEvent asyncWalkEvent;
public CustomWebWalk(Position position) {
super(position);
}
@Override
public void onStart() {
asyncWalkEvent = new AsyncWalkEvent();
execute(asyncWalkEvent);
}
@Override
public int execute() throws InterruptedException {
if (asyncWalkEvent.isLooping()) {
// Async is still looping, dont let the web walker execute
return 600;
}
return super.execute();
}
@Override
public void onEnd() throws InterruptedException {
// End the async event and wait for it to finish
asyncWalkEvent.setFinished();
ConditionalSleep2.sleep(5000, asyncWalkEvent::hasCompleted);
}
}
And the action that executes in a separate thread
import org.osbot.rs07.api.map.Position;
import org.osbot.rs07.event.Event;
public class AsyncWalkEvent extends Event {
private volatile boolean finished = false;
private volatile boolean isLooping = false;
public AsyncWalkEvent() {
setAsync();
}
@Override
public int execute() throws InterruptedException {
if (canPerformAction()) {
// Map destination is far enough away, we can perform some actions
isLooping = true;
if (shouldDoAction()) {
// do action
} else {
// any other necessary action
}
isLooping = false;
}
return 600;
}
@Override
public void onEnd() throws InterruptedException {
finished = true;
}
public boolean isLooping() {
return isLooping;
}
public boolean hasCompleted() {
return finished;
}
private boolean canPerformAction() {
// Only allow the actions to start if the map destination is far enough away
Position dest = getMap().getDestination();
if (dest == null) return false;
int dist = getMap().distance(dest);
return dist < 20 && dist > 7;
}
}