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.

Webwalk with threaded eat.

Featured Replies

So I wrote this code to make a webwalk that could be used for Webwalk and drink stamina potion, turn on prayers , alch, eating. Im wondering if there is a better way to doing threading becuase I hate having a while loop with a thread sleep .

 

 

My code.

        (x, y, z) -> {


            PathPreferenceProfile profile = PathPreferenceProfile.DEFAULT;
            int run = 20;
            boolean cameraMove = true;
            Procedure threadTask = null;
            WebWalkEvent walkEvent = null;
            boolean done = false;
			//This can take args in any order 
            while (first(x) != null || !(first(x) instanceof Area) || !(first(x) instanceof Area)) {
                if (first(x) instanceof Procedure) {
                    threadTask = (Procedure) first(x);
                    x = rest(x);
                }

                if (first(x) instanceof PathPreferenceProfile) {
                    profile = (PathPreferenceProfile) first(x);
                    x = rest(x);
                }

                if (first(x) instanceof Long || first(x) instanceof Integer) {
                    run = Math.toIntExact(num(first(x)));
                    x = rest(x);
                }
                if (first(x) instanceof Boolean) {
                    cameraMove = truth(first(x));
                    x = rest(x);
                }

            }


            if (first(x) instanceof Area) {
                walkEvent = new WebWalkEvent(listToAreaArry(x));
            }

            if (first(x) instanceof Position) {
                walkEvent = new WebWalkEvent(listToPositionArry(x));
            }


            if (walkEvent != null) {
                ExecutorService executor = Executors.newSingleThreadExecutor();
              
              	//this is the code
              	//That I would like input on.
                if (threadTask != null) {
                    final Procedure finalthreadTask = threadTask;
                    Runnable task = () -> {
                        while (true) {

                            try {
                                scemeBot.getScheme().eval(finalthreadTask);
                                Thread.sleep(1000);
                            } catch (InterruptedException e) {
                                e.printStackTrace();
                            }
                        }
                    };
                    executor.submit(task);

                }
              
                walkEvent.setPathPreferenceProfile(profile);
                walkEvent.setEnergyThreshold(run);
                walkEvent.setMoveCameraDuringWalking(cameraMove);

                done = scemeBot.walking.execute(walkEvent).hasFinished();

                if (threadTask != null) {
                    executor.shutdownNow();

                }
            
 				return done;
            }

         

            return null;
        }

 

Edited by Nbacon

  • Author
44 minutes ago, Camaro said:

Execute an async event instead

So I looked on git hub for async events and there are not alot of them.

But I can up with these I have no idea how it works.

if (walkEvent != null) {
                walkEvent.setPathPreferenceProfile(profile);
                walkEvent.setEnergyThreshold(run);
                walkEvent.setMoveCameraDuringWalking(cameraMove);
                Event event =null;

                if (threadTask != null) {

                    final Procedure finalThreadTask = threadTask;
                    event = new Event() {
                        @Override
                        public int execute() throws InterruptedException {

                            scemeBot.getScheme().eval(finalThreadTask);


                            return 1000;
                        }
                    };
                    event.setAsync();
                    scemeBot.execute(event);
                }

                boolean  done = scemeBot.execute(walkEvent).hasFinished();
                if (event !=null){
                    event.setFinished();
                }
                return done;
            }

or 

   if (walkEvent != null) {
                walkEvent.setPathPreferenceProfile(profile);
                walkEvent.setEnergyThreshold(run);
                walkEvent.setMoveCameraDuringWalking(cameraMove);
                Event event =null;

                if (threadTask != null) {

                    final Procedure finalThreadTask = threadTask;
                    event = new Event() {
                        @Override
                        public int execute() throws InterruptedException {

                            scemeBot.getScheme().eval(finalThreadTask);


                            return 1000;
                        }
                    };
                    event.setAsync();
                    walkEvent.addChild(event);
                    
                }

                boolean  done = scemeBot.execute(walkEvent).hasFinished();

                return done;
            }

 

 

 

 

 

 

 

 

First one should work fine. I've never used the add/remove children methods, so not too sure about the second one, but looks like it should work.

  • Author

Thanks man for your time. 

Last problem, priority?

In this video you can see him run and eat but he goes for the food no eating then goes back to running.

 

 

 

 

2 hours ago, Nbacon said:

Thanks man for your time. 

Last problem, priority?

In this video you can see him run and eat but he goes for the food no eating then goes back to running.

Well, that just comes down to the fact that you have multiple threads trying to take control of the mouse at the same time. For this situation, its probably better to just break from the webwalk event to eat.

  • Author
10 hours ago, Khaleesi said:

Or just break the webwalk event when you need to eat :D
continue after ... 

 

This is the hack i came up with is there something better?

this.setBlocking();
scemeBot.getScheme().eval(finalThreadTask);
this.setAsync();

 

Also tryed (does not work)

synchronized (webwalk) {
    webwalk.wait();
}
scemeBot.getScheme().eval(finalThreadTask);
webwalk.notify();

 

 

 

 

 

Edited by Nbacon

3 hours ago, Nbacon said:

 

This is the hack i came up with is there something better?


this.setBlocking();
scemeBot.getScheme().eval(finalThreadTask);
this.setAsync();

 

Also tryed (does not work)


synchronized (webwalk) {
    webwalk.wait();
}
scemeBot.getScheme().eval(finalThreadTask);
webwalk.notify();

 

 

 

 

 

I just stop the whole webwalkerevent with a breakcondition when i have to eat and then eat myself... :D
Then just start a new webwalk event... ^^

There 50 ways of doing the same thing, whatever works for you is good :D

Edited by Khaleesi

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.