Jump to content

Some questions for the devs


Cheff

Recommended Posts

New to the scene of scripting for oldschool and I have a couple of questions I have encountered during the development of my first script that I can't find an answer to on the site.

1) Is there a way for the script to detect when a random event kicks in? Example BreakManager started

2) When saving screenshots, is there a way to get a file stream of the saved image or the file name of the image? (method returns a bool only and cannot rely on the last image saved in folder if there are multiple bots running)

3) More of a suggestion to follow up on 1), but I have the script fighting some NPCs which could take some time to kill, sometimes the break manager kicks in while the player is fighting and of course he cannot logout, after a few seconds it looks like the break manager is canceled, if I am able to detect when the script tried to fire the break manager, is there a way I can manually tell the script to trigger a break after the NPC died and I looted?

 

Link to comment
Share on other sites

On ‎8‎/‎21‎/‎2018 at 4:04 PM, Cheff said:

New to the scene of scripting for oldschool and I have a couple of questions I have encountered during the development of my first script that I can't find an answer to on the site.

1) Is there a way for the script to detect when a random event kicks in? Example BreakManager started

2) When saving screenshots, is there a way to get a file stream of the saved image or the file name of the image? (method returns a bool only and cannot rely on the last image saved in folder if there are multiple bots running)

3) More of a suggestion to follow up on 1), but I have the script fighting some NPCs which could take some time to kill, sometimes the break manager kicks in while the player is fighting and of course he cannot logout, after a few seconds it looks like the break manager is canceled, if I am able to detect when the script tried to fire the break manager, is there a way I can manually tell the script to trigger a break after the NPC died and I looted?

 

joins 36 minutes ago, starts asking some questions directed at the Dev's without even knowing who they are. I'm gunna meme this and chock you up to:

 

Edited by Knuckolls
Link to comment
Share on other sites

4 minutes ago, Knuckolls said:

joins 36 minutes ago, starts asking some questions directed at the Dev's without even knowing who they are. I'm gunna meme this and chock you up to:crown_gold.gif.44562d88e66cda63b7dda5023ef48fd3.gifwhen-jagex-bans-your-entire-bot-farm-spooky-runescape-memes-3204301.png.989c2f310145b4f0cb82340d5da93f24.png

Had to create an account for me to post a thread, also by devs I mean other scripters (those developing a script) as well, dunno who the developers of Osbot are and didn't ask.

Link to comment
Share on other sites

6 minutes ago, Cheff said:

Had to create an account for me to post a thread, also by devs I mean other scripters (those developing a script) as well, dunno who the developers of Osbot are and didn't ask.

I'm literally just pulling your chain check the Help and FAQ sections

which your in but check out Apaec's and Explv's guides on Scripting

Edited by Knuckolls
Link to comment
Share on other sites

8 hours ago, Cheff said:

New to the scene of scripting for oldschool and I have a couple of questions I have encountered during the development of my first script that I can't find an answer to on the site.

1) Is there a way for the script to detect when a random event kicks in? Example BreakManager started

2) When saving screenshots, is there a way to get a file stream of the saved image or the file name of the image? (method returns a bool only and cannot rely on the last image saved in folder if there are multiple bots running)

3) More of a suggestion to follow up on 1), but I have the script fighting some NPCs which could take some time to kill, sometimes the break manager kicks in while the player is fighting and of course he cannot logout, after a few seconds it looks like the break manager is canceled, if I am able to detect when the script tried to fire the break manager, is there a way I can manually tell the script to trigger a break after the NPC died and I looted?

 

To answer my own question:

1)

@Override
    public void pause() {
        if(bot.getRandomExecutor().forEvent(RandomEvent.BREAK_MANAGER).shouldActivate()) {
            isTakingABreak = true;
        }
    }

2)

getBot().getCanvas().getGameBuffer()

3) Unsolved

Link to comment
Share on other sites

9 minutes ago, Cheff said:

To answer my own question:

1)


@Override
    public void pause() {
        if(bot.getRandomExecutor().forEvent(RandomEvent.BREAK_MANAGER).shouldActivate()) {
            isTakingABreak = true;
        }
    }

2)


getBot().getCanvas().getGameBuffer()

3) Unsolved

There's no way to use the inbuilt break handler when using combat scripts.

Best write you own.

Link to comment
Share on other sites

5 hours ago, Cheff said:

To be sure we are on the same page, I am able to detect when the break manager failed to start. I want to be able to start it manually later when player is moved to a safe spot.

I'd recommend creating a new class extending the default BreakManager, override shouldActivate with super.shouldActivate() && yourOwnCondition

Then use RandomExecutor#overrideOSBotRandom to register your custom break manager.
A few things to note when doing this:
- It seems you must also override RandomSolver#getName
- You should only attempt to override the break manager when the user has breaks enabled
- You should remember to exchange contexts with your custom breakmanager instance before overriding

Breaks are enabled when

getRandomExecutor().forEvent(RandomEvent.BREAK_MANAGER)

is not null

Link to comment
Share on other sites

40 minutes ago, FrostBug said:

I'd recommend creating a new class extending the default BreakManager, override shouldActivate with super.shouldActivate() && yourOwnCondition

Then use RandomExecutor#overrideOSBotRandom to register your custom break manager.
A few things to note when doing this:
- It seems you must also override RandomSolver#getName
- You should only attempt to override the break manager when the user has breaks enabled
- You should remember to exchange contexts with your custom breakmanager instance before overriding

Breaks are enabled when


getRandomExecutor().forEvent(RandomEvent.BREAK_MANAGER)

is not null

Thanks for the reply, I have tried this but I keep getting this error when I stop the script. (Should activate is never called in the logs and only called once on stop before error trace)

java.lang.NullPointerException
	at org.osbot.rs07.randoms.BreakManager.shouldActivate(nk:108)
	at CustomBreakManager.shouldActivate(CustomBreakManager.java:24)
	at Runner.pause(Runner.java:205)
	at org.osbot.rs07.event.ScriptExecutor.suspend(kl:433)
	at org.osbot.rs07.event.ScriptExecutor.stop(kl:396)
	at org.osbot.rs07.event.ScriptExecutor.stop(kl:324)
	at org.osbot.Mb.run(rz:204)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
	at java.lang.Thread.run(Unknown Source)

Also what do you mean by exchanging contexts? Perhaps it is related to this issue?

This is my custom handler:

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

@ScriptManifest(
        name = "TestBreakManager",
        author = "Cheff",
        version = 1.1D,
        info = "Takes breaks",
        logo = ""
)
public class CustomBreakManager extends BreakManager {

    private Bot bot;

    public CustomBreakManager(Bot iIiiiiiiIiii) {
        super(iIiiiiiiIiii);
        this.bot = iIiiiiiiIiii;
    }

    @Override
    public boolean shouldActivate() {
        bot.getLogger().info("Pass");
        return super.shouldActivate() && true; //todo put logic here
    }

    @Override
    public String getName() {
        return "TestManager";
    }
}

and setting it up on start first thing like so:

getBot().getRandomExecutor().overrideOSBotRandom(new CustomBreakManager(getBot()));

 

Link to comment
Share on other sites

1 hour ago, Cheff said:

Thanks for the reply, I have tried this but I keep getting this error when I stop the script. (Should activate is never called in the logs and only called once on stop before error trace)

Also what do you mean by exchanging contexts? Perhaps it is related to this issue?

This is my custom handler:

and setting it up on start first thing like so:


getBot().getRandomExecutor().overrideOSBotRandom(new CustomBreakManager(getBot()));

 

By exchanging contexts I mean:

CustomBreakManager customManager = new CustomBreakManager(getBot());
customManager.exchangeContext(getBot());
getBot().getRandomExecutor().overrideOSBotRandom(customManager);

Remember that you should still only override it if they have breaks enabled; otherwise it will throw an error as well.

EDIT: exchanging contexts is something you must do when creating new instances of classes that inherit from MethodProvider, and BreakManager does inherit from that. This also means that there is no need to store the reference to Bot in your custom break manager, as you can simply use the getBot() method exposed by MethodProvider once context has been exchanged.

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