Jump to content

Making a custom interaction event break condition


Hayase

Recommended Posts

Hello,

Currently I'm trying to make a InteractionEvent break condition and so far it works 50% of the time, the other 50% of the time it fights itself with some kind of event queue?

import org.osbot.rs07.event.Event;

import java.util.function.BooleanSupplier;

class InteractionBreaker {
    private InteractionBreaker() {

    }

    static Event setBreakCondition(Event event, BooleanSupplier breakCondition) {
        return new Event() {
            @Override
            public void onStart() {
                try {
                    super.onStart();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                event.setAsync();
                execute(event);
            }

            @Override
            public int execute() throws InterruptedException {
                boolean failed = breakCondition.getAsBoolean();
                log("InterationBreaker status: " + event.getStatus());//debug never prints this
                if (failed) {
                    log("InterationBreaker failed? " + event.getStatus());//never shows up in debug
                    event.setFailed();
                    setFailed();
                }
                return 100;
            }

            @Override
            public boolean isWorking() {
                log("InteractionBreaker is working");//debug never prints this
                return event.isWorking();
            }

            @Override
            public boolean isQueued() {
                log("InteractionBreaker is queued!");//debug never prints this
                return event.isQueued();
            }

            @Override
            public boolean hasFailed() {
                log("InteractionBreaker hasFailed? " + event.getStatus());//debug never prints this
                boolean failed = breakCondition.getAsBoolean();
                if (failed) {
                    event.setFailed();
                    setFailed();
                }
                return failed || event.hasFailed();
            }

            @Override
            public boolean hasFinished() {
                log("InteractionBreaker hasFinished? " + event.getStatus()); //prints QUEUED for the event status everytime
                event.setFinished();
                setFinished();
                return event.hasFinished();
            }
        };
    }
}

And to use it you would do:

InteractionEvent escape = new InteractionEvent(path);
execute(InteractionBreaker.setBreakCondition(escape.setAction(), () -> escapedAbyss.contains(myPlayer())));

When I'm inside the abyss I spam click the object with a 1 second delay. This usually works unless it's the mine object then it sometimes fights itself when it DOES escape. If I get through the object the script will continue on to the next task, but sometimes it fights itself by running back and fourth between going to the next task and trying to reach an object to interact with. I suspect something is stuck in the queue and I don't know how to proceed.

Link to comment
Share on other sites

 

8 hours ago, Hayase said:

Hello,

Currently I'm trying to make a InteractionEvent break condition and so far it works 50% of the time, the other 50% of the time it fights itself with some kind of event queue?

And to use it you would do:


InteractionEvent escape = new InteractionEvent(path);
execute(InteractionBreaker.setBreakCondition(escape.setAction(), () -> escapedAbyss.contains(myPlayer())));

When I'm inside the abyss I spam click the object with a 1 second delay. This usually works unless it's the mine object then it sometimes fights itself when it DOES escape. If I get through the object the script will continue on to the next task, but sometimes it fights itself by running back and fourth between going to the next task and trying to reach an object to interact with. I suspect something is stuck in the queue and I don't know how to proceed.


I'm confused as to why you need a break condition. Could you try to explain it more clearly?

What is the InteractionEvent(path) for?

What exactly is your use case here, what are you trying to achieve? There is a probably a simpler way to achieve it

Edited by Explv
  • Like 1
Link to comment
Share on other sites

7 hours ago, Explv said:

 


I'm confused as to why you need a break condition. Could you try to explain it more clearly?

What is the InteractionEvent(path) for?

What exactly is your use case here, what are you trying to achieve? There is a probably a simpler way to achieve it

Escaping the abyss.

It's because when you are inside the abyss, you want to spam objects if you are in combat so that you don't die. I'm basically trying to click objects to escape and when I escape I want the interaction to end. However with normal interactions it gets "stuck" on reaching an interaction it cannot reach. So interaction events comes in and it works. However I still get "hung up" on interacting because it still wants to go back to interact with some shit it can't reach. It's not like I'm spamming the objects at 1ms ticks I'm just clicking them if I'm in combat at a 1 second delay. It's nothing hardcore.

When I finish Mining through for example, sometimes the script will still be stuck in the interaction and will not want to proceed to the next step of getting inside a rift to craft runes. So normal interactions don't work, I've tried them.

 

if (path != null) {
	status = "Escaping via " + path.getName();
	InteractionEvent escape = new InteractionEvent(path);
	execute(InteractionBreaker.setBreakCondition(escape.setAction(), () -> escapedAbyss.contains(myPlayer())));
	log("Clicked: " + path.getName() + " action(s): " + Arrays.toString(path.getActions()) + " canReach: " + getMap().canReach(path));
	log("Started sleeping");
	if (myPlayer().isUnderAttack() || escapedAbyss.contains(myPlayer()))
		afk(720, 1080);
	new ConditionalSleep(5000) {
		@Override
		public boolean condition() throws InterruptedException {
			return myPlayer().isUnderAttack() || escapedAbyss.contains(myPlayer());
		}
	}.sleep();
	log("Stopped sleeping");
}

 

Edited by Hayase
Link to comment
Share on other sites

12 hours ago, Hayase said:

Escaping the abyss.

It's because when you are inside the abyss, you want to spam objects if you are in combat so that you don't die. I'm basically trying to click objects to escape and when I escape I want the interaction to end. However with normal interactions it gets "stuck" on reaching an interaction it cannot reach. So interaction events comes in and it works. However I still get "hung up" on interacting because it still wants to go back to interact with some shit it can't reach. It's not like I'm spamming the objects at 1ms ticks I'm just clicking them if I'm in combat at a 1 second delay. It's nothing hardcore.

When I finish Mining through for example, sometimes the script will still be stuck in the interaction and will not want to proceed to the next step of getting inside a rift to craft runes. So normal interactions don't work, I've tried them.

 


if (path != null) {
	status = "Escaping via " + path.getName();
	InteractionEvent escape = new InteractionEvent(path);
	execute(InteractionBreaker.setBreakCondition(escape.setAction(), () -> escapedAbyss.contains(myPlayer())));
	log("Clicked: " + path.getName() + " action(s): " + Arrays.toString(path.getActions()) + " canReach: " + getMap().canReach(path));
	log("Started sleeping");
	if (myPlayer().isUnderAttack() || escapedAbyss.contains(myPlayer()))
		afk(720, 1080);
	new ConditionalSleep(5000) {
		@Override
		public boolean condition() throws InterruptedException {
			return myPlayer().isUnderAttack() || escapedAbyss.contains(myPlayer());
		}
	}.sleep();
	log("Stopped sleeping");
}

 

Just making an InteractionEvent around a MouseDestination rather than an Entity will probably get your desired result, since it can't verify reachability.

Edited by FrostBug
  • 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...