CrashBandiboob Posted October 9, 2019 Share Posted October 9, 2019 (edited) This is the first time I have ever really coded anything (apart from HTML for my Neopets guild about 20 years ago), thought I would give it a crack and have made a woodcutting script. What this does at the moment is just powercuts the closest trees, I just wanted some feedback on where I'm going wrong/what could be improved/things I've missed. Most of what I have done has been guess work, trial & error and reading a lot of other peoples code, but it seems to be working alright! Some things I would like some help with: 1. I'd like to put something that enables run when energy goes beyond a certain value, can someone point me in the right direction for this? 2. My axe check needs to contain all of the axes not just bronze axe. How would I do this? I've tried doing a string array but EquipmentSlot doesn't seem to like this 3. Something probably a bit too advanced for me right now - How do I create a little pop up before the script kicks in so the user can choose a different tree type? Here's the compiled (is that even the right term?) jar file: https://www.mediafire.com/file/kpgbnkfnemx3u9d/FirstScript.jar/file And here's the source code: https://pastebin.com/57neLNcJ Edited October 9, 2019 by CrashBandiboob Added images 1 Quote Link to comment Share on other sites More sharing options...
Gunman Posted October 9, 2019 Share Posted October 9, 2019 (edited) 1 hour ago, CrashBandiboob said: This is the first time I have ever really coded anything (apart from HTML for my Neopets guild about 20 years ago), thought I would give it a crack and have made a woodcutting script. What this does at the moment is just powercuts the closest trees, I just wanted some feedback on where I'm going wrong/what could be improved/things I've missed. Most of what I have done has been guess work, trial & error and reading a lot of other peoples code, but it seems to be working alright! Some things I would like some help with: 1. I'd like to put something that enables run when energy goes beyond a certain value, can someone point me in the right direction for this? 2. My axe check needs to contain all of the axes not just bronze axe. How would I do this? I've tried doing a string array but EquipmentSlot doesn't seem to like this 3. Something probably a bit too advanced for me right now - How do I create a little pop up before the script kicks in so the user can choose a different tree type? Here's the compiled (is that even the right term?) jar file: https://www.mediafire.com/file/kpgbnkfnemx3u9d/FirstScript.jar/file And here's the source code: https://pastebin.com/57neLNcJ 1. Make a method for checking the value and enabling it using the API. Spoiler getSettings().getRunEnergy(); For checking the value of your run energy. getSettings().isRunning(); I think to check if the running is enabled or disabled. If that doesn't work you might need to use Config values to check. getSettings().setRunning(true or false); To set the running to enable(true) or disabled(false). Only one can be in there example being getSettings().setRunning(true); getSettings().setRunning(false); 2. Try using this below instead of isWearingItem. getEquipment().isWieldingWeaponThatContains(axe); 3. Actually number 16. Adding a GUI in this post is I think 95% copy and paste for your current situation lol. Spoiler Edited October 9, 2019 by Gunman 1 1 Quote Link to comment Share on other sites More sharing options...
CrashBandiboob Posted October 9, 2019 Author Share Posted October 9, 2019 7 minutes ago, Gunman said: 1. Make a method for checking the value and enabling it using the API. Hide contents getSettings().getRunEnergy(); For checking the value of your run energy. getSettings().isRunning(); I think to check if the running is enabled or disabled. If that doesn't work you might need to use Config values to check. getSettings().setRunning(true or false); To set the running to enable(true) or disabled(false). Only one can be in there example being getSettings().setRunning(true); getSettings().setRunning(false); 2. Try using this below instead of isWearingItem. getEquipment().isWieldingWeaponThatContains(axe); 3. Actually number 16. Adding a GUI in this post is I think 95% copy and paste for your current situation lol. Reveal hidden contents Amazing! Thank you! Quote Link to comment Share on other sites More sharing options...
BravoTaco Posted October 9, 2019 Share Posted October 9, 2019 Attempt at answering some of your questions. Feel free to pm me if you have any other questions 1. I'd like to put something that enables run when energy goes beyond a certain value, can someone point me in the right direction for this? Spoiler For this you can use an api call to check your current run energy. - getSettings().getRunEnergy() Than To set the running state you can use another api call - getSettings().setRunning() This takes in a boolean parameter || Example - getSettings().setRunning(true) 2. My axe check needs to contain all of the axes not just bronze axe. How would I do this? I've tried doing a string array but EquipmentSlot doesn't seem to like this Spoiler You are on the right track of using a String Array, but what you need to do is loop through it and see if the player has that axe in the inventory or if the player has the axe equipped. Example Spoiler private boolean hasAxe(String[] axeNames) { for (String s : axeNames) { if (getInventory().contains(s) || getEquipment().getForNameThatContains(s) != null) { return true; } } return false; } 3. Something probably a bit too advanced for me right now - How do I create a little pop up before the script kicks in so the user can choose a different tree type? Spoiler If you want something quick here is an example. All though I would recommend looking up tutorials on the use of the Java Swing Library. Quick Method Spoiler import org.osbot.rs07.script.Script; import org.osbot.rs07.script.ScriptManifest; import javax.swing.*; import java.awt.*; @ScriptManifest(name = "@Test", author = "BravoTaco", version = 1.0, info = "", logo = "") public class Main extends Script { private final String[] treeNames = new String[]{"Tree", "Oak tree", "Willow tree", "Maple tree", "Yew tree"}; private boolean isStarted = false; private String treeName; @Override public void onStart() { showTreeSelectionDialog(); } @Override public int onLoop() { if (treeName != null && !isStarted) { log("Started!"); isStarted = true; } else if (!isStarted) { log("Not Started!"); stop(false); } return random(1300, 2300); } private void showTreeSelectionDialog() { //Initialize Dialog JDialog jDialog = new JDialog(); jDialog.setModal(true); jDialog.setModalityType(Dialog.ModalityType.APPLICATION_MODAL); jDialog.setMinimumSize(new Dimension(250, 300)); jDialog.setLocationRelativeTo(null); //Initialize mainPanel and add it to the dialog box JPanel mainPanel = new JPanel(new BorderLayout()); jDialog.add(mainPanel); //Initialize infoPanel and add it to the mainPanel at the center JPanel infoPanel = new JPanel(); mainPanel.add(infoPanel, BorderLayout.CENTER); //Initialize treeNameLabel and add it to the infoPanel JLabel treeNameLabel = new JLabel("Choose A Tree: "); infoPanel.add(treeNameLabel); //Initialize treeNameCB and add it to the infoPanel JComboBox<String> treeNameCB = new JComboBox<>(treeNames); infoPanel.add(treeNameCB); //Initialize startButton with text of Start JButton startButton = new JButton("Start"); //Add an action listener to the start button to close the gui and start the script. startButton.addActionListener(e -> { treeName = (String) treeNameCB.getSelectedItem(); jDialog.dispose(); }); //Add the start button to the main panel at the bottom mainPanel.add(startButton, BorderLayout.SOUTH); jDialog.pack(); jDialog.setVisible(true); } } 1 Quote Link to comment Share on other sites More sharing options...
CrashBandiboob Posted October 9, 2019 Author Share Posted October 9, 2019 3 hours ago, BravoTaco said: Attempt at answering some of your questions. Feel free to pm me if you have any other questions 1. I'd like to put something that enables run when energy goes beyond a certain value, can someone point me in the right direction for this? Reveal hidden contents For this you can use an api call to check your current run energy. - getSettings().getRunEnergy() Than To set the running state you can use another api call - getSettings().setRunning() This takes in a boolean parameter || Example - getSettings().setRunning(true) 2. My axe check needs to contain all of the axes not just bronze axe. How would I do this? I've tried doing a string array but EquipmentSlot doesn't seem to like this Reveal hidden contents You are on the right track of using a String Array, but what you need to do is loop through it and see if the player has that axe in the inventory or if the player has the axe equipped. Example Reveal hidden contents private boolean hasAxe(String[] axeNames) { for (String s : axeNames) { if (getInventory().contains(s) || getEquipment().getForNameThatContains(s) != null) { return true; } } return false; } 3. Something probably a bit too advanced for me right now - How do I create a little pop up before the script kicks in so the user can choose a different tree type? Reveal hidden contents If you want something quick here is an example. All though I would recommend looking up tutorials on the use of the Java Swing Library. Quick Method Reveal hidden contents import org.osbot.rs07.script.Script; import org.osbot.rs07.script.ScriptManifest; import javax.swing.*; import java.awt.*; @ScriptManifest(name = "@Test", author = "BravoTaco", version = 1.0, info = "", logo = "") public class Main extends Script { private final String[] treeNames = new String[]{"Tree", "Oak tree", "Willow tree", "Maple tree", "Yew tree"}; private boolean isStarted = false; private String treeName; @Override public void onStart() { showTreeSelectionDialog(); } @Override public int onLoop() { if (treeName != null && !isStarted) { log("Started!"); isStarted = true; } else if (!isStarted) { log("Not Started!"); stop(false); } return random(1300, 2300); } private void showTreeSelectionDialog() { //Initialize Dialog JDialog jDialog = new JDialog(); jDialog.setModal(true); jDialog.setModalityType(Dialog.ModalityType.APPLICATION_MODAL); jDialog.setMinimumSize(new Dimension(250, 300)); jDialog.setLocationRelativeTo(null); //Initialize mainPanel and add it to the dialog box JPanel mainPanel = new JPanel(new BorderLayout()); jDialog.add(mainPanel); //Initialize infoPanel and add it to the mainPanel at the center JPanel infoPanel = new JPanel(); mainPanel.add(infoPanel, BorderLayout.CENTER); //Initialize treeNameLabel and add it to the infoPanel JLabel treeNameLabel = new JLabel("Choose A Tree: "); infoPanel.add(treeNameLabel); //Initialize treeNameCB and add it to the infoPanel JComboBox<String> treeNameCB = new JComboBox<>(treeNames); infoPanel.add(treeNameCB); //Initialize startButton with text of Start JButton startButton = new JButton("Start"); //Add an action listener to the start button to close the gui and start the script. startButton.addActionListener(e -> { treeName = (String) treeNameCB.getSelectedItem(); jDialog.dispose(); }); //Add the start button to the main panel at the bottom mainPanel.add(startButton, BorderLayout.SOUTH); jDialog.pack(); jDialog.setVisible(true); } } This is all golden, thank you! Quote Link to comment Share on other sites More sharing options...
BuyingHardcores Posted October 9, 2019 Share Posted October 9, 2019 I would be no use for feedback on this as it's not my forte but, good luck on improving at scripting Quote Link to comment Share on other sites More sharing options...