Jump to content

Webwalk with threaded eat.


Nbacon

Recommended Posts

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
  • Heart 1
Link to comment
Share on other sites

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

 

 

 

 

 

 

 

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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
  • Like 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...