Jump to content

Any snippets for eating/walking while in combat?


saintpaul1

Recommended Posts

Found something you might be able to use. Someone posted this snippet a while back and I had it saved on my PC. If this snippet is yours, lmk so that I can credit you.

Custom class

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

}

Then just set the action here

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

}

 

  • Like 1
Link to comment
Share on other sites

1 hour ago, FushigiBot said:

Found something you might be able to use. Someone posted this snippet a while back and I had it saved on my PC. If this snippet is yours, lmk so that I can credit you.

Custom class

Then just set the action here

 

Thanks might come in useful! Not going to use webwalker though gonna use pathwalk 

Link to comment
Share on other sites

10 minutes ago, saintpaul1 said:

Thanks might come in useful! Not going to use webwalker though gonna use pathwalk 

Keep in mind that anything other than the web walker and you have to write object interactions as well (door opening, etc).


Since pathwalker uses the local walker, make sure to make it break when the position its trying to get to becomes  unreachable. Otherwise it will get stuck trying to reach it from, say, lumby or death's office, if you get pked.

Link to comment
Share on other sites

7 hours ago, FushigiBot said:

Keep in mind that anything other than the web walker and you have to write object interactions as well (door opening, etc).


Since pathwalker uses the local walker, make sure to make it break when the position its trying to get to becomes  unreachable. Otherwise it will get stuck trying to reach it from, say, lumby or death's office, if you get pked.

thanks mate

Link to comment
Share on other sites

  • 1 month later...
On 4/19/2023 at 2:29 PM, FushigiBot said:

Found something you might be able to use. Someone posted this snippet a while back and I had it saved on my PC. If this snippet is yours, lmk so that I can credit you.

Custom class

Then just set the action here

 

How can i execute the customwebwalk from my main class?

 


import org.osbot.rs07.api.map.Position;
import org.osbot.rs07.script.Script;

import org.osbot.rs07.script.ScriptManifest;



@ScriptManifest(name = "Skeleton", author = "Alek", version = 1.0, info = "", logo = "")

public class Main extends Script {

    CustomWebWalk customWebWalk;
    @Override
    public void onStart() {
        //Code here will execute before the loop is started
        Position destination = new Position(3144, 3485, 0); // Replace with desired destination coordinates
        customWebWalk = new CustomWebWalk(destination);
        customWebWalk.exchangeContext(getBot());
        customWebWalk.onStart();
    }

    @Override
    public int onLoop() throws InterruptedException {
        if (customWebWalk != null) {
            execute(customWebWalk);
        } else {
            log("Web walk null");
        }
        return 100; //The amount of time in milliseconds before the loop starts over

    }

}

Something like this?

 

edit: i got it to execute but in asyncwalkevent class canperformaction is false.

 

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

Im trying to walk to edgeville from grand exchange.

Final edit: got it to work :)

Edited by shaba123
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...