Cheff Posted August 21, 2018 Share Posted August 21, 2018 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? Quote Link to comment Share on other sites More sharing options...
Knuckolls Posted August 21, 2018 Share Posted August 21, 2018 (edited) 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 September 14, 2018 by Knuckolls Quote Link to comment Share on other sites More sharing options...
Cheff Posted August 21, 2018 Author Share Posted August 21, 2018 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: 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. Quote Link to comment Share on other sites More sharing options...
Knuckolls Posted August 21, 2018 Share Posted August 21, 2018 (edited) 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 August 21, 2018 by Knuckolls Quote Link to comment Share on other sites More sharing options...
Cheff Posted August 21, 2018 Author Share Posted August 21, 2018 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 Quote Link to comment Share on other sites More sharing options...
Rays Posted August 21, 2018 Share Posted August 21, 2018 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. Quote Link to comment Share on other sites More sharing options...
Cheff Posted August 22, 2018 Author Share Posted August 22, 2018 14 hours ago, Rays said: There's no way to use the inbuilt break handler when using combat scripts. Best write you own. 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. Quote Link to comment Share on other sites More sharing options...
FrostBug Posted August 22, 2018 Share Posted August 22, 2018 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 Quote Link to comment Share on other sites More sharing options...
Cheff Posted August 22, 2018 Author Share Posted August 22, 2018 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())); Quote Link to comment Share on other sites More sharing options...
FrostBug Posted August 22, 2018 Share Posted August 22, 2018 (edited) 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 August 22, 2018 by FrostBug Quote Link to comment Share on other sites More sharing options...