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 can i run another local script from my current local script?


    MrBigBertil

    Recommended Posts

    So ive been doing a few scripts and im thinking about making an account builder of some sort, im just wondering if its possible to run another local script from the one i currently am running. For example if im in my "woodcutter" can i then make it so that when i reach a certain level i open the next script for example "fishing".  Its just so i wont have to make a large script basicly, it would be easier to read etc.

    ps Im trying to run the files in the picture after eachother. im mostly wondering how i can call them from a "Main" script

    Thanks in advance

    problem.png

    Link to comment
    Share on other sites

    I use threads and ScriptManager class to accomplish this. I do it by starting a new thread, and inside of the thread I get the instance of the script manager, wait for the current script to stop, then start new script. As soon as the 1st script starts the new thread, the 1st script returns -1 to stop itself. But thread isn't killed on 1st script stop so 2nd script starts after 1000 ms (u should give DreamBot a second or two to finish script stopping / loading activities).


    Call this anywhere in your Main class you want to switch

    QuestScriptStarter questStarter = new QuestScriptStarter();
    Logger.log("Attempting to stop current script and start tmp's Ten QP");
    Thread t1 = new Thread(questStarter);
    t1.start();
    return -1;


    and this is the class that implements Runnable

    package script.unlock.quests;
    import org.dreambot.api.script.ScriptManager;
    
    public class QuestScriptStarter implements Runnable{
        @Override
        public void run() {
            ScriptManager manager = ScriptManager.getScriptManager();
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            manager.start("tmp\'s Ten QP");
        }
    }


    Also, I think that using this method to automatically switch scripts requires each startable Script to override the Quickstart method onStart(String[] args) in order for them to be started this way (not sure tbh)

    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.