Jump to content

Start a break early.


yfoo

Recommended Posts

I want to start a break early. 
This doesn't work. OSB logs "Started random solver : " then immediately calls onExit, skipping BreakManager's onloop. 

package Util;

import org.osbot.rs07.Bot;
import org.osbot.rs07.randoms.BreakManager;

public class BreakManagerHook extends BreakManager {

    private static boolean breakNow = false;

    public BreakManagerHook(Bot IiIiiiIiiII) {
        super(IiIiiiIiiII);
    }


    @Override
    public boolean shouldActivate() {
        if(super.shouldActivate() || breakNow) {
            breakNow = false;
            return true;
        }
        return false;
    }

    @Override
    public void onExit() {
        super.onExit();
        log("Return from break hook!");
    }

    public static void startBreakNow() {
        breakNow = true;
    }
}
Link to comment
Share on other sites

On 9/3/2024 at 4:43 PM, dubai said:

Are you doing this to have you script break early say, when it's at the bank? Interesting approach if so, I disabled osbots break manager completely and just had it sleep until the break was over then let the login solver log the player back in and continue

Yes, I do not want a break to happen at a certain time. I was working on a blast mining script If there was not enough time remaining before break to do cycle then start the break early. 
 

Link to comment
Share on other sites

10 hours ago, yfoo said:

Yes, I do not want a break to happen at a certain time. I was working on a blast mining script If there was not enough time remaining before break to do cycle then start the break early. 
 

Yeah I gotcha, heaps of reasons to add custom breaks tbh.

 

I started doing this but I never finished it... @Czar Where you at 😛

Link to comment
Share on other sites

4 hours ago, dubai said:

Yeah I gotcha, heaps of reasons to add custom breaks tbh.

 

I started doing this but I never finished it... @Czar Where you at 😛

This was the end result I settled with. I also happened to need a hook to know when the break ended to potentially check if my position was crashed while I was away. The OnExit() allows me to know that. For now I'm not doing anything with it just logging (log("Return from break!");)
 

package Util;

import org.osbot.rs07.Bot;
import org.osbot.rs07.randoms.BreakManager;

public class BreakManagerHook extends BreakManager {

    private volatile boolean breakEarly;
    private volatile boolean shouldActivateCalled;

    private static BreakManagerHook instance;

    public static BreakManagerHook getInstance() {
        if(instance == null) {
            throw new NullPointerException("ExcavatePlantIgnite is null");
        }
        return instance;
    }

    public static BreakManagerHook initInstance(Bot bot) {
        instance = new BreakManagerHook(bot);
        return instance;
    }


    private BreakManagerHook(Bot IiIiiiIiiII) {
        super(IiIiiiIiiII);
    }

    @Override
    public synchronized boolean shouldActivate() {
        if(breakEarly && !shouldActivateCalled) {
            log(String.format("Thread %d notifying...", Thread.currentThread().getId()));
            shouldActivateCalled = true;
            this.notify();
        }

        if(super.shouldActivate() && breakEarly) {
            breakEarly = false;
            log("breakEarly -> false");
        }
        return super.shouldActivate() || breakEarly;
    }

    @Override
    public void onExit() {
        super.onExit();
        log("Return from break!");
    }

    public synchronized void startBreakEarly() throws InterruptedException {
        breakEarly = true;
        shouldActivateCalled = false;
        while (!shouldActivateCalled) {
            log(String.format("Thread %d waiting until shouldActivate() called...", Thread.currentThread().getId()));
            this.wait();
        }
        log("Exited startBreakEarly");
    }
}
Edited by yfoo
Link to comment
Share on other sites

On 9/8/2024 at 4:11 PM, yfoo said:

This was the end result I settled with. I also happened to need a hook to know when the break ended to potentially check if my position was crashed while I was away. The OnExit() allows me to know that. For now I'm not doing anything with it just logging (log("Return from break!");)
 

public class BreakManagerHook extends BreakManager {

This looks like it will work? have you tested it yet?

Link to comment
Share on other sites

On 9/14/2024 at 9:49 PM, dubai said:

This looks like it will work? have you tested it yet?

When I wrote it like 2 weeks ago it worked. 
You need to override the break manager with an instance of the class

Put this in onStart

bot.getRandomExecutor().overrideOSBotRandom(BreakManagerHook.initInstance(bot));

Then use this to start a break early. 

BreakManagerHook.getInstance().startBreakEarly();

 

Edited by yfoo
Link to comment
Share on other sites

On 9/17/2024 at 9:44 AM, yfoo said:

When I wrote it like 2 weeks ago it worked. 
You need to override the break manager with an instance of the class

Put this in onStart

bot.getRandomExecutor().overrideOSBotRandom(BreakManagerHook.initInstance(bot));

Then use this to start a break early. 

BreakManagerHook.getInstance().startBreakEarly();

 

Hope you don't mind if I just copy and paste this :D :D

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...