Jump to content
Frequently Asked Questions
  • Are you not able to open the client? Try following our getting started guide
  • Still not working? Try downloading and running JarFix
  • Help! My bot doesn't do anything! Enable fresh start in client settings and restart the client
  • How to purchase with PayPal/OSRS/Crypto gold? You can purchase vouchers from other users
  • How to Restart a script from within the script?


    Recommended Posts

    I make lots of little changes to my code and would just like to apply them and see the effect immediately until it's satisfactory then broadcast these changes to multiple clients running. Usually I have to manually click each client's restart button to update them but I would like to just write a command in a text file to update all of them. I think  if the script checks for this command every loop and then when it sees it, restarts the currently running script, it would be a good way. I know there is a script on the SDN that can start/stop other scripts in a supervisory way so I was wondering if I need to create a launcher script that stays running and will automatically restart the actual script when the command is present?

    Link to comment
    Share on other sites

    There are run() and stop() methods within AbstractScript class. I don't think these will help you load a new artifact though.


    You could instead aim to automate the loading of the jar from outside the script. Below is a high level example:

    Have your Java detect when a new jar file has appeared on the system through a check on the modified date for example. If found, call stop(). Then a shell script either spawned by Java or acting independently could terminate all Dreambot processes at OS level, followed by spawning new processes with CLI arguments specifying the accounts and new jar file..

    Someone more versed with Dreambot behaviour can sanity check my CLI thinking. I think it has that functionality, but at work so can't check.

    Edited by Robosoldier2
    Link to comment
    Share on other sites

    Thanks, yes I can restart all clients with a built-in call in my script to system.exit(0) so I can write in the text file the command to system.exit(0) and all the clients will close, then I can re-launch all of them. But I was mostly wanting to restart the script rather than re-launch all clients because it's much faster that way. I know Bun's Automation Tool does it in it's own script (Bun's Automation Tool is the script you run on the DB client, then that script loads / runs another specified script and when that script is detected to be stopped, the Bun's Automation Tool script kicks back in and is able to load more again etc):


    Script Queueing

    Scripts can be run under specific conditions, and stopped when certain goals are met or a certain amount of time has elapsed.

    @Bunnybun pls open source just these calls thx :D

    Link to comment
    Share on other sites

    I mean, there is a ScriptManager class that is in the API with stop(), run(), pause(), resume(), but I am failing to properly implement it somehow 😞 https://dreambot.org/javadocs/org/dreambot/api/script/ScriptManager.html

    Should I grab Instance.getInstance().getScriptManager() to actually see that class in effect? Or ScriptManager.getScriptManager() ? Do I have to run this code in the Main class of my .jar project (the script files)? In a static way??? etc

    Link to comment
    Share on other sites

    11 hours ago, 420x69x420 said:

    Should I grab Instance.getInstance().getScriptManager() to actually see that class in effect? Or ScriptManager.getScriptManager() ? Do I have to run this code in the Main class of my .jar project (the script files)? In a static way??? etc

    to get an instance of ScriptManager you would ScriptManager manager = ScriptManager.getManager()

    once you use ScriptManager#stop the script will stop and wont execute ScriptManager#start, if you do it in the other order you wont be able to start a script because your current script is still running, for this reason you have to make a new thread to start a different script. heres what i do


    public class ScriptStarter implements Runnable{
        public void run() {
            ScriptManager manager = ScriptManager.getScriptManager();
            try {
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            manager.start("cCCannonballs", null);

    and then in my script when i wanted to change script i do

                ScriptStarter scriptStarter = new ScriptStarter();
                log("trying to start cCCannonballs");
                Thread t1 = new Thread(scriptStarter);


    Link to comment
    Share on other sites

    Aces mate! Thanks so much because that's exactly what I was looking to do! :D


    Edit: And also, you want to tell the initial script to exit prior to the thread sleep ending. For example return -1 in the Main onLoop() function of the initial script immediately after starting the new thread so the script is stopped before another one is started by the still-running thread.

    Edited by 420x69x420
    Link to comment
    Share on other sites

    Create an account or sign in to comment

    You need to be a member in order to leave a comment

    Create an account

    Sign up for a new account in our community. It's easy!

    Register a new account

    Sign in

    Already have an account? Sign in here.

    Sign In Now
    • Create New...

    Important Information

    We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.