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
  • Starting Script with GUI Options + Paint


    pharaoh

    Recommended Posts

    hey botters and scripters, coming back with another round of questions for concepts that i do not fully understand yet

    issue 1 - Starting the script with GUI options

    goal 1start the script with the proper tasks added for the selected GUI option from the combobox

    i have made the switch to a tree framework and my GUI is like so:

    GUI Code vv

    also the frame is not disposing after selecting start?

    public class DyeMakerUI extends JFrame {
        public DyeMakerUI() {
            initComponents();
        }
    
        private void startBtn(ActionEvent e) {
            if (startButton.isSelected()) {
                DyeMakerConfig.startScript = true;
                dispose();
            }
        }
    
        private void comboBox1(ActionEvent e) {
            int i = comboBox1.getSelectedIndex();
            switch (i) {
                case 0:
                    DyeMakerConfig.chosenActivity = "Buy woad leafs";
                    Logger.log(comboBox1.getSelectedItem());
                    Logger.log(comboBox1.getSelectedIndex());
                    break;
    
            }
        }

     

    T14MjfW.png

     

    Main script file

    private long startTime;
        private long runTime;
        private Image image;
        public static Tree tree = new Tree();
    
        private void initTasks() {
           if (DyeMakerUI.comboBox1.getSelectedIndex() == 0) {
               tree.addBranches(
                       new BuyWoadLeavesBranch().addLeafs(new BuyWoadLeavesLeaf()));
           }
    
            log("Tasks instantiated");
        }
    
        public void start() {
           initTasks();
        }
    
        @Override
        public void onStart() {
            SwingUtilities.invokeLater(() -> new DyeMakerUI().setVisible(true));
            try {
                image = ImageIO.read(new URL("https://i.imgur.com/Ygl1IGt.png"));
            } catch (IOException e) {
                log("Failed to load image");
            }
    
            start();
            startTime = System.currentTimeMillis();
        }
    
        @Override
        public int onLoop() {
            if (!DyeMakerConfig.startScript) return 600;
            return tree.onLoop();
        }

     

    issue 2i remembering see a post about Antialiasing with rendering keyhints to make the drawn text look a bit sharper but i cannot find that snippet on the forums or discord. i know its not a necessity but i would just like to find out how to do it again

    goal 2: add antialiasing keyhints to the script paint 

     

    thank you to those that provide input and help, it is much appreciated 

    Link to comment
    Share on other sites

    On 12/16/2022 at 3:18 PM, pharaoh said:

    hey botters and scripters, coming back with another round of questions for concepts that i do not fully understand yet

    issue 1 - Starting the script with GUI options

    goal 1start the script with the proper tasks added for the selected GUI option from the combobox

    i have made the switch to a tree framework and my GUI is like so:

    GUI Code vv

    also the frame is not disposing after selecting start?

    public class DyeMakerUI extends JFrame {
        public DyeMakerUI() {
            initComponents();
        }
    
        private void startBtn(ActionEvent e) {
            if (startButton.isSelected()) {
                DyeMakerConfig.startScript = true;
                dispose();
            }
        }
    
        private void comboBox1(ActionEvent e) {
            int i = comboBox1.getSelectedIndex();
            switch (i) {
                case 0:
                    DyeMakerConfig.chosenActivity = "Buy woad leafs";
                    Logger.log(comboBox1.getSelectedItem());
                    Logger.log(comboBox1.getSelectedIndex());
                    break;
    
            }
        }

     

    T14MjfW.png

     

    Main script file

    private long startTime;
        private long runTime;
        private Image image;
        public static Tree tree = new Tree();
    
        private void initTasks() {
           if (DyeMakerUI.comboBox1.getSelectedIndex() == 0) {
               tree.addBranches(
                       new BuyWoadLeavesBranch().addLeafs(new BuyWoadLeavesLeaf()));
           }
    
            log("Tasks instantiated");
        }
    
        public void start() {
           initTasks();
        }
    
        @Override
        public void onStart() {
            SwingUtilities.invokeLater(() -> new DyeMakerUI().setVisible(true));
            try {
                image = ImageIO.read(new URL("https://i.imgur.com/Ygl1IGt.png"));
            } catch (IOException e) {
                log("Failed to load image");
            }
    
            start();
            startTime = System.currentTimeMillis();
        }
    
        @Override
        public int onLoop() {
            if (!DyeMakerConfig.startScript) return 600;
            return tree.onLoop();
        }

     

    issue 2i remembering see a post about Antialiasing with rendering keyhints to make the drawn text look a bit sharper but i cannot find that snippet on the forums or discord. i know its not a necessity but i would just like to find out how to do it again

    goal 2: add antialiasing keyhints to the script paint 

     

    thank you to those that provide input and help, it is much appreciated 

    Hey Pharoah, 

    Instead of comboBox1.getSelectedIndex(), try (field) String example = String.valueOf(comboBox1.getSelectedItem()) in your start button onActionEvent. This will return a string you can use when the start button is clicked to determine the run method. Try removing the if statement in the actionEvent for the start button - that method should only get called if the button is clicked, and I don't think the isSelected() is what you're looking for. I think since DyeMakerUI() is a separate class, you may need to use DyeMakerUI.dispose() instead of just dispose(), but test it your way first.  Edit: Since you're instantiating the new GUI instance from your main class, you may need this.dispose() instead. I am not too familiar with this way of doing it since I put my GUI method inside of my main class.

    Let me know if you need more help and I can do some digging. I'd be happy to help you set it up in your main class as well. It is still easy to maintain and keep separate this way, and I could give you definitive answers.

    Hope this helps :)

    Edited by Genius
    Added this.dispose() suggestion.
    Link to comment
    Share on other sites

    57 minutes ago, Genius said:

    DyeMakerUI.dispose() instead of just dispose(), but test it your way first.  Edit: Since you're instantiating the new GUI instance from your main class, you may need this.dispose() instead

    dispose is an instance method that wouldnt compile, this is implicit in what hes doing now.

     

    On 12/17/2022 at 6:18 AM, pharaoh said:
        public void start() {
           initTasks();
        }

    this method is pointless & you are calling initTasks right after starting the gui, there is no time to even make a selection before you are analysing it

    seeing as your tree is static you can probably just populate your combo box with leaves, then add the selected item on button press. 

     

    im pretty sure the reason its not disposing the window is because those methods are never called by anything ever. same reason u cant start the script

    Link to comment
    Share on other sites

    On 12/17/2022 at 9:16 PM, Genius said:

    Hey Pharoah, 

    Instead of comboBox1.getSelectedIndex(), try (field) String example = String.valueOf(comboBox1.getSelectedItem()) in your start button onActionEvent. This will return a string you can use when the start button is clicked to determine the run method. Try removing the if statement in the actionEvent for the start button - that method should only get called if the button is clicked, and I don't think the isSelected() is what you're looking for. I think since DyeMakerUI() is a separate class, you may need to use DyeMakerUI.dispose() instead of just dispose(), but test it your way first.  Edit: Since you're instantiating the new GUI instance from your main class, you may need this.dispose() instead. I am not too familiar with this way of doing it since I put my GUI method inside of my main class.

    Let me know if you need more help and I can do some digging. I'd be happy to help you set it up in your main class as well. It is still easy to maintain and keep separate this way, and I could give you definitive answers.

    Hope this helps :)

     

    On 12/17/2022 at 10:26 PM, camalCase said:

    dispose is an instance method that wouldnt compile, this is implicit in what hes doing now.

     

    this method is pointless & you are calling initTasks right after starting the gui, there is no time to even make a selection before you are analysing it

    seeing as your tree is static you can probably just populate your combo box with leaves, then add the selected item on button press. 

     

    im pretty sure the reason its not disposing the window is because those methods are never called by anything ever. same reason u cant start the script

    hi guys 

    i have fixed the GUI disposing properly but I am still stuck on finding resources on how to make the GUI selection... I have done this before but i have not really stuck with coding so that knowledge fades fast

    i have found 1-3 script sources on github demonstrating a GUI and the starting options but they are not really updated for DB3 methods. 

    i realize the code below is pointless as you said onStart is called once when the user presses it - makes sense, there is no time for any configuration to be set

        public void start() {
           initTasks();
        }

     

    so if onStart runs once when the script is started from pressing play, what is a optimal way to set the starting/proper settings since the GUI is open and configured after starting the script? 

    I can somewhat understand the logic process on paper but i am not sure where to look online for something like this.

    Link to comment
    Share on other sites

    3 hours ago, pharaoh said:

    so if onStart runs once when the script is started from pressing play, what is a optimal way to set the starting/proper settings since the GUI is open and configured after starting the script? 

     

    On 12/18/2022 at 2:26 PM, camalCase said:

    seeing as your tree is static you can probably just populate your combo box with leaves, then add the selected item on button press. 

     

    Link to comment
    Share on other sites

    On 12/22/2022 at 12:44 PM, pharaoh said:

     

    hi guys 

    i have fixed the GUI disposing properly but I am still stuck on finding resources on how to make the GUI selection... I have done this before but i have not really stuck with coding so that knowledge fades fast

    i have found 1-3 script sources on github demonstrating a GUI and the starting options but they are not really updated for DB3 methods. 

    i realize the code below is pointless as you said onStart is called once when the user presses it - makes sense, there is no time for any configuration to be set

        public void start() {
           initTasks();
        }

     

    so if onStart runs once when the script is started from pressing play, what is a optimal way to set the starting/proper settings since the GUI is open and configured after starting the script? 

    I can somewhat understand the logic process on paper but i am not sure where to look online for something like this.

    Hey Pharaoh,

    A good way to do this is to call the GUI in your onStart(), then in the startBtn Action event method, grab all of the variables that can be changed in your GUI. For your purposes, they may need to be defined in your main class as fields (in the same spot as private long runTime, etc) as protected/public String activity;  and so on for other items you may add. 

    To reference the main class activity string in the subclass (gui), you will need to instantiate an instance of the gui class in main class' context like so (then you can use this main-class variable in your GUI class). Please also see the simplified startbutton ActionEvent method. String activity will have to be defined as a field in your main class for this to compile.

    MainClassName ctx;
    
    public class DyeMakerUI extends JFrame {
    
    	public DyeMakerUI(MainClassName ctx) {
    		this.ctx = ctx;
        }
    
        private void startBtn(ActionEvent e) {
            ctx.activity = comboBox1.getSelectedItem.toString();
    		//Also dispose the JFrame here
        }
    }

    You do not need the onActionEvent for the combo box in this example. There are several ways to do this, but this should do the trick. Please let us know if it gives you any more trouble.

     

    Edited by Genius
    Verbiage
    Link to comment
    Share on other sites

    On 12/22/2022 at 2:58 PM, camalCase said:

     

     

    tried to do this but my brain does not have knowledge yet i will have to study java thank you

    On 12/25/2022 at 3:14 PM, Genius said:

    Hey Pharaoh,

    A good way to do this is to call the GUI in your onStart(), then in the startBtn Action event method, grab all of the variables that can be changed in your GUI. For your purposes, they may need to be defined in your main class as fields (in the same spot as private long runTime, etc) as protected/public String activity;  and so on for other items you may add. 

    To reference the main class activity string in the subclass (gui), you will need to instantiate an instance of the gui class in main class' context like so (then you can use this main-class variable in your GUI class). Please also see the simplified startbutton ActionEvent method. String activity will have to be defined as a field in your main class for this to compile.

    MainClassName ctx;
    
    public class DyeMakerUI extends JFrame {
    
    	public DyeMakerUI(MainClassName ctx) {
    		this.ctx = ctx;
        }
    
        private void startBtn(ActionEvent e) {
            ctx.activity = comboBox1.getSelectedItem.toString();
    		//Also dispose the JFrame here
        }
    }

    You do not need the onActionEvent for the combo box in this example. There are several ways to do this, but this should do the trick. Please let us know if it gives you any more trouble.

     

    thanks for the help but i think i figured it out a day ago by doing this

    i have a DyeMakerConfig (static?) class with some variables like

    public class DyeMakerConfig {
    
        private static final DyeMakerConfig dyeMakerConfig = new DyeMakerConfig();
    
        private DyeMakerConfig() {}
    
        public static Area AGGIES_HOUSE = new Area(3083, 3261, 3088, 3256);
        public static Area REDBERRY_AREA = new Area(3278, 3375, 3267, 3367);
        public static Area WYSON_AREA = new Area(
                new Tile(3031, 3375, 0),
                new Tile(3023, 3375, 0),
                new Tile(3023, 3384, 0),
                new Tile(3030, 3384, 0));
    
        public String dyeToMake;
        public String dyeIngredient;
        public static String activity = "";
        public static String status = "";
        public String REDBERRIES = "Redberries";
        public static String WOAD_LEAVES = "Woad leaf";
        public static String ONION = "Onion";
    
        private boolean startScript = false;

    from there in my DyeMakerUI class which holds the scripts GUI

    i have removed the ActionEvent from the combobox and moved the events to the Start Button instead 

    the code below was just a quick test to see if i was actually able to run different activities based on the selected option from the combobox, it seems to be working!

    DyeMakerConfig config = DyeMakerConfig.getDyeMakerConfig();
    
    private void startBtn(ActionEvent e) {
            if (comboBox1.getSelectedItem().toString().equals("Make blue dye")) {
                config.setActivity(comboBox1.getSelectedItem().toString());
                config.setDyeToMake("Blue dye");
                config.setDyeIngredient(config.WOAD_LEAVES);
                config.setIngredientPrice(LivePrices.get(config.WOAD_LEAVES));
                Logger.log("Dye ingredient: " + config.getDyeIngredient());
    
            } else if (comboBox1.getSelectedItem().toString().equals("Collect redberries")) {
                config.setActivity(comboBox1.getSelectedItem().toString());
                config.setDyeIngredient(config.REDBERRIES);
                config.setDyeToMake("Red dye");
                config.setIngredientPrice(LivePrices.get(config.REDBERRIES));
                Logger.log("Dye ingredient: " + config.getDyeIngredient());
            }
    
            Logger.log("[GUI] Chosen activity: " + config.getActivity());
            config.setStartScript(true);
            Logger.log("script started: " + config.isStartScript());
            this.dispose();
        }

    i ended up also adding all the branches and leafs for each activity on the script start

    i can probably rewrite a bit of banking/handling leafs to make them more general/abstract but since i am still learning, everything right now seems to be working.

    private void initTasks() {
           tree.addBranches(
                   new WalkToRedberriesBranch().addLeafs(new WalkToRedberriesLeaf()),
                   new CollectRedberriesBranch().addLeafs(new CollectRedberriesLeaf()),
                   new WalkToVarrockBankBranch().addLeafs(new WalkToVarrockBankLeaf()),
                   new ShouldVarrockBankBranch().addLeafs(new DoVarrockBankLeaf()),
                   new BuyWoadLeavesBranch().addLeafs(new BuyWoadLeavesLeaf()),
                   new WalkToAggieBranch().addLeafs(new WalkToAggieLeaf()),
                   new MakeBlueDyeBranch().addLeafs(new MakeBlueDyeLeaf()),
                   new WalkToDraynorBankBranch().addLeafs(new WalkToDraynorBankLeaf()),
                   new ShouldDraynorBankBranch().addLeafs(new DoDraynorBankLeaf()));

     

    Link to comment
    Share on other sites

    3 hours ago, pharaoh said:

    tried to do this but my brain does not have knowledge yet i will have to study java thank you

    thanks for the help but i think i figured it out a day ago by doing this

    i have a DyeMakerConfig (static?) class with some variables like

    public class DyeMakerConfig {
    
        private static final DyeMakerConfig dyeMakerConfig = new DyeMakerConfig();
    
        private DyeMakerConfig() {}
    
        public static Area AGGIES_HOUSE = new Area(3083, 3261, 3088, 3256);
        public static Area REDBERRY_AREA = new Area(3278, 3375, 3267, 3367);
        public static Area WYSON_AREA = new Area(
                new Tile(3031, 3375, 0),
                new Tile(3023, 3375, 0),
                new Tile(3023, 3384, 0),
                new Tile(3030, 3384, 0));
    
        public String dyeToMake;
        public String dyeIngredient;
        public static String activity = "";
        public static String status = "";
        public String REDBERRIES = "Redberries";
        public static String WOAD_LEAVES = "Woad leaf";
        public static String ONION = "Onion";
    
        private boolean startScript = false;

    from there in my DyeMakerUI class which holds the scripts GUI

    i have removed the ActionEvent from the combobox and moved the events to the Start Button instead 

    the code below was just a quick test to see if i was actually able to run different activities based on the selected option from the combobox, it seems to be working!

    DyeMakerConfig config = DyeMakerConfig.getDyeMakerConfig();
    
    private void startBtn(ActionEvent e) {
            if (comboBox1.getSelectedItem().toString().equals("Make blue dye")) {
                config.setActivity(comboBox1.getSelectedItem().toString());
                config.setDyeToMake("Blue dye");
                config.setDyeIngredient(config.WOAD_LEAVES);
                config.setIngredientPrice(LivePrices.get(config.WOAD_LEAVES));
                Logger.log("Dye ingredient: " + config.getDyeIngredient());
    
            } else if (comboBox1.getSelectedItem().toString().equals("Collect redberries")) {
                config.setActivity(comboBox1.getSelectedItem().toString());
                config.setDyeIngredient(config.REDBERRIES);
                config.setDyeToMake("Red dye");
                config.setIngredientPrice(LivePrices.get(config.REDBERRIES));
                Logger.log("Dye ingredient: " + config.getDyeIngredient());
            }
    
            Logger.log("[GUI] Chosen activity: " + config.getActivity());
            config.setStartScript(true);
            Logger.log("script started: " + config.isStartScript());
            this.dispose();
        }

    i ended up also adding all the branches and leafs for each activity on the script start

    i can probably rewrite a bit of banking/handling leafs to make them more general/abstract but since i am still learning, everything right now seems to be working.

    private void initTasks() {
           tree.addBranches(
                   new WalkToRedberriesBranch().addLeafs(new WalkToRedberriesLeaf()),
                   new CollectRedberriesBranch().addLeafs(new CollectRedberriesLeaf()),
                   new WalkToVarrockBankBranch().addLeafs(new WalkToVarrockBankLeaf()),
                   new ShouldVarrockBankBranch().addLeafs(new DoVarrockBankLeaf()),
                   new BuyWoadLeavesBranch().addLeafs(new BuyWoadLeavesLeaf()),
                   new WalkToAggieBranch().addLeafs(new WalkToAggieLeaf()),
                   new MakeBlueDyeBranch().addLeafs(new MakeBlueDyeLeaf()),
                   new WalkToDraynorBankBranch().addLeafs(new WalkToDraynorBankLeaf()),
                   new ShouldDraynorBankBranch().addLeafs(new DoDraynorBankLeaf()));

     

    Good to hear! Let us know if you run into any other issues.

    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.