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
  • Try asking for help in the chatbox
  • Local Script Scheduler possible? (DB2)


    LordJashin32
     Share

    Recommended Posts

    Got pretty far on this. Got it to run 2-3 scripts back to back only to run out of memory and freeze. Just want this for local scripts. Be good for a bot farm where u scripted your own local script collection. Saw there was one a couple years ago but don't see any today.

    GUI:

    fbd6c24cb5a74ddfd148830e8fad05d1.png

     

    Main.java

    import java.awt.Graphics;
    import java.awt.event.WindowEvent;
    import java.util.List;
    import java.util.Timer;
    import org.dreambot.api.script.AbstractScript;
    import org.dreambot.api.script.Category;
    import org.dreambot.api.script.ScriptManager;
    import org.dreambot.api.script.ScriptManifest;
    import org.dreambot.api.script.loader.LocalLoader;
    
    @ScriptManifest(author = "LordJashin32", category = Category.UTILITY, name = "ScriptScheduler", description = "Run multiple local scripts in a row nonstop. Daisy Chain your way to victory!", version = 0.1)
    public class Main extends AbstractScript
    {
        private Timer timeRan;
        public ScriptManager mg;
        private MainGUI gui;
        private boolean startScript;
    
        /**
         * Script loop.
         */
        @Override
        public int onLoop()
        {
            if (startScript) {
                if (gui.model1 != null)
                    for(int i = 0; i< gui.model1.getSize();i++){
                        String script1 = gui.model1.getElementAt(i);
                        String[] parts = script1.split("\\^");
                        Integer RunTime = Integer.valueOf(parts[1]);
                        ScriptManager mg = new ScriptManager(getClient().getInstance());
                        log("Running for " + Integer.toString(RunTime) + "m: " + parts[0]);
                        if (parts.length > 2)
                            mg.start(parts[0], parts[2].split(";"));
                        else
                            mg.start(parts[0]);
    
                        sleep((RunTime * 60000));
                        mg.stop();
                        sleep(1000);
                        log("Finished script moving to next");
    
                    }
                stop();
            }
            return 300;
        }
    
        /**
         * Canvas paint call.
         */
        @Override
        public void onPaint(Graphics graphics)
        {
    //        graphics.drawString("drawing muh string", 1, 2);
        }
    
        /**
         * Default on start action. Can be removed if not needed.
         */
        @Override
        public void onStart()
        {
            startScript = false;
            gui = new MainGUI(this);
            for (ScriptManifest script : LocalLoader.getAllScripts()) {
                gui.comboBox1.addItem(script.name());
            }
    
                gui.setVisible(true);
            //timeRan = new Timer();
            log("INFO - Script Started!");
            log("INFO - Default onStart() method called");
        }
    
        /**
         * On start with paramters. Can be removed if not needed.
         */
        @Override
        public void onStart(String... args)
        {
            log("INFO - Parameterized onStart(String... args) method called");
    
            // List all of the script arguments
            log("--- Argument list ---");
            for (int i = 0; i < args.length; i++) {
                log("Argument " + i + " = " + args[i]);
            }
    
            // INSERT ARGUMENT HANDELING HERE
    
            // For actions both onStart methods share place them all in the
            // non-parameterized onStart().
            onStart();
        }
    
        @Override
        public void onExit()
        {
            if ((gui != null) || gui.isVisible())
                gui.dispatchEvent(new WindowEvent(gui, WindowEvent.WINDOW_CLOSING));
            log("INFO - Script Ended!");
        }
    
        public void setStartScript(boolean startScript) {
            this.startScript = startScript;
        }
    
    }

    MainGUI.java

    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.border.*;
    
    /*
     * Created by JFormDesigner on Wed Aug 19 06:10:31 EDT 2020
     */
    
    /**
     * @author unknown
     */
    public class MainGUI extends JFrame {
        private Main ctx;
        public MainGUI(Main main){
            this.ctx = main;
            initComponents();
        }
    
        // Add
        private void button2ActionPerformed(ActionEvent e) {
            model1.addElement(comboBox1.getSelectedItem().toString() + "^" + spinner1.getValue().toString() + "^" + textField1.getText());
        }
    
        // Remove
        private void button1ActionPerformed(ActionEvent e) {
            int index = list1.getSelectedIndex();
            if (index != -1)
                model1.remove(index);
            if (index > 0)
                list1.setSelectedIndex(index - 1);
    
        }
    
        private void button3ActionPerformed(ActionEvent e) {
            ctx.setStartScript(true);
            this.setVisible(false);
        }
    
        private void initComponents() {
            this.addWindowListener(new WindowAdapter(){
                public void windowClosing(WindowEvent e){
                    ctx.stop();
                }
            });
            scrollPane3 = new JScrollPane();
            model1 = new DefaultListModel<>();
            list1 = new JList<>( model1 );
            scrollPane2 = new JScrollPane();
            label4 = new JLabel();
            comboBox1 = new JComboBox();
            label2 = new JLabel();
            spinner1 = new JSpinner();
            label3 = new JLabel();
            textField1 = new JTextField();
            button2 = new JButton();
            button1 = new JButton();
            button3 = new JButton();
            label1 = new JLabel();
            //======== this ========
            setTitle("Script Scheduler");
            Container contentPane = getContentPane();
            contentPane.setLayout(null);
    
            //======== scrollPane3 ========
            {
    
                //---- list1 ----
                list1.setFont(new Font("Times New Roman", Font.BOLD, 16));
                list1.setBorder(new MatteBorder(1, 1, 1, 1, Color.black));
                list1.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
                scrollPane3.setViewportView(list1);
            }
            contentPane.add(scrollPane3);
            scrollPane3.setBounds(20, 15, 465, 162);
            contentPane.add(scrollPane2);
            scrollPane2.setBounds(76, 41, 78, 22);
    
            //---- label4 ----
            label4.setText("Script");
            contentPane.add(label4);
            label4.setBounds(30, 190, 55, label4.getPreferredSize().height);
            contentPane.add(comboBox1);
            comboBox1.setBounds(90, 185, 138, 30);
    
            //---- label2 ----
            label2.setText("Run Time (In Minutes)");
            contentPane.add(label2);
            label2.setBounds(new Rectangle(new Point(245, 190), label2.getPreferredSize()));
            contentPane.add(spinner1);
            spinner1.setValue(Integer.valueOf(300));
            spinner1.setBounds(new Rectangle(new Point(395, 185),spinner1.getPreferredSize()));
    
            //---- label3 ----
            label3.setText("Params");
            contentPane.add(label3);
            label3.setBounds(new Rectangle(new Point(30, 225), label3.getPreferredSize()));
            contentPane.add(textField1);
            textField1.setBounds(90, 220, 395, textField1.getPreferredSize().height);
    
            //---- button2 ----
            button2.setText("Add");
            button2.addActionListener(e -> button2ActionPerformed(e));
            contentPane.add(button2);
            button2.setBounds(90, 260, 100, 30);
    
            //---- button1 ----
            button1.setText("Remove");
            button1.addActionListener(e -> button1ActionPerformed(e));
            contentPane.add(button1);
            button1.setBounds(215, 260, 100, 30);
    
            //---- button3 ----
            button3.setText("Start!");
            button3.addActionListener(e -> button3ActionPerformed(e));
            contentPane.add(button3);
            button3.setBounds(340, 260, 144, button3.getPreferredSize().height);
    
            //---- label1 ----
            label1.setText("v0.1");
            contentPane.add(label1);
            label1.setBounds(30, 270, label1.getPreferredSize().width, 15);
    
            textField1.setText("Arg1;Arg2;Arg3");
            contentPane.setPreferredSize(new Dimension(505, 300));
            pack();
            setLocationRelativeTo(getOwner());
            // JFormDesigner - End of component initialization  //GEN-END:initComponents
        }
        private JScrollPane scrollPane3;
        public DefaultListModel<String> model1;
        public JList<String> list1;
        private JScrollPane scrollPane2;
        private JLabel label4;
        public JComboBox comboBox1;
        private JLabel label2;
        private JSpinner spinner1;
        private JLabel label3;
        private JTextField textField1;
        private JButton button2;
        private JButton button1;
        private JButton button3;
        private JLabel label1;
        // JFormDesigner - End of variables declaration  //GEN-END:variables
    }

    Just wasn't able to get the ScriptManager to play nice with me.

    Edited by LordJashin32
    Link to comment
    Share on other sites

    I'm high and also have never used ScriptManager, but aren't you delcaring 

    ScriptManager mg = new ScriptManager(getClient().getInstance());

    on each for loop? Do you need to call this each time? Also you could declare ScriptManager mg; as a global variable instead of redeclaring it on each loop.

    Link to comment
    Share on other sites

    10 hours ago, Stoned said:

    I'm high and also have never used ScriptManager, but aren't you delcaring 

    ScriptManager mg = new ScriptManager(getClient().getInstance());

    on each for loop? Do you need to call this each time? Also you could declare ScriptManager mg; as a global variable instead of redeclaring it on each loop.

    I tried it both ways and it doesn't change anything for the better so I just left it in there. Whether local or global variable.

    Either way the memory is a problem. Even after running stop it still has the memory stored up.

    Edited by LordJashin32
    Link to comment
    Share on other sites

    125mb at first

    d806b80c2491ffb8b0997c2fbd343207.png

    Then I get the Looter gui. And i hit start. And get this with memory:

    8a6a7ee6af3f0dd43c2aaf2ee88d1326.png

    Then finally it stops it and tries to run McMonk

    d9c19c774806324884aaf5bc6119ff15.png

    Boop freezes with that. And then i can't tell if memory overloaded or not but that has to be the only reason right?

    Link to comment
    Share on other sites

    2 hours ago, Stoned said:

    Have you tried increasing the memory to 1GB instead of 256MB?

    I ran that with 612mb memory. It shouldn't need more memory. Its only supposed to be running at max 2 scripts at once. I can run these scripts solo just fine on 612mb of memory. Heck even on 256mb i can run both of those individually. The problem is something to do with the garbage collection. For some reason when stopping a script with the scriptmanager api, it doesn't clear it from memory or something and so when it tries to run another script it maxes out and freezes the client and i have to force quit it.

    Edited by LordJashin32
    Link to comment
    Share on other sites

    16 minutes ago, LordJashin32 said:

    I ran that with 612mb memory. It shouldn't need more memory. Its only supposed to be running at max 2 scripts at once. I can run these scripts solo just fine on 612mb of memory. Heck even on 256mb i can run both of those individually. The problem is something to do with the garbage collection. For some reason when stopping a script with the scriptmanager api, it doesn't clear it from memory or something and so when it tries to run another script it maxes out and freezes the client and i have to force quit it.

    Fair enough. As I said I haven't used SM so I don't really know what I'm talking about here :D Are you sure you should be calling 

    mg.stop();

    on each loop? I feel like the SM should always been running to manage the scripts. Could it be two instances of SM overlapping that is using up the memory?

    Link to comment
    Share on other sites

    19 minutes ago, Stoned said:

    Fair enough. As I said I haven't used SM so I don't really know what I'm talking about here :D Are you sure you should be calling 

    mg.stop();

    on each loop? I feel like the SM should always been running to manage the scripts. Could it be two instances of SM overlapping that is using up the memory?

    Okay gonna try your suggestion and use mg.getCurrentScript.stop() instead of mg.stop. Gonna run 15 of 2 scripts as a test run. Not gonna run looter. Gonna try two others.

    EDIT: Running the same script twice in a row doesn't seem to work. or atleast this particular one.

    EDIT: Calling stop on currently running script apparently stops my script? lol but the log messages are still coming in from it. i don't understand.

    EDIT: I think my way that i made first works but have to test more. The local scripts i have seem to be the ones that make or break it idk. Gonna have to test more. I tried running McMonk like 7 Times in a row with no problem. 

    Edited by LordJashin32
    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
     Share

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