ElChapoJr 15 Share Posted August 1, 2017 Hello Everyone! I am brand new to scripting so don't mind my nooby-ness But I have a question, In my GUI the player is able to select 3 locations. And the goal is whenever they select the location the bot walks to that area. So the script would need the input from the GUI However i'm not entirely sure how to put that into code. Any help is appreciated. Im assuming it has something to do with getters and setters. Heres what I have so far. (Dont judge im stilll learning ) The VictimType is working fine. But the Location is where im having the issues. Thanks! public int onLoop() { if (startScript) { if (gui.Location().contains(getLocalPlayer())) { pickPocket(gui.getVictimType()); } else { if (getWalking().walk(gui.Location().getRandomTile())) { } } } return 600; } Link to comment Share on other sites More sharing options...
Just Chill 26 Share Posted August 1, 2017 https://dreambot.org/forums/index.php/topic/8530-scripting-101/?hl=scriptingHe has a good gui section in there. Link to comment Share on other sites More sharing options...
Pyth 127 Share Posted August 1, 2017 public int onLoop() { if (startScript) { if (gui.Location().contains(getLocalPlayer())) { pickPocket(gui.getVictimType()); } else { if (getWalking().walk(gui.Location().getRandomTile())) { } } } return 600; } Since you are newish to coding I'll show you an easy but not the cleanest way to do what you want done. It's very easy to follow along and will work for what you need done. What you need to do is implement a ActionListener in your GUI. For example here is a ComboBox action listener in a Gui class npcComboBox.addActionListener(e -> selectedNPC = npcComboBox.getSelectedItem().toString()); What this does is set my variable "String selectedNPC" in my gui class to a String that of the players choice For reference here is how I set my ComboBox npcComboBox.setModel(new DefaultComboBoxModel(new String[] {"Giant rat", "Scorpion", "Skeleton"})); So selectedNPC will change each time the user selects a new option in the ComboBox Now that we have information of what the player chose we need to convert the string into the location of what we selected, we do so by going to your Start button action listener (You should already have this implemented and your script shouldn't loop until your gui has been set.) Inside our Start button action listener we add if(selectedNPC == "Scorpion") { main.TaskArea = main.scorpionArea; } else if(selectedNPC =="Giant rat") { main.TaskArea = main.ratArea; } else if(selectedNPC == "Skeleton") { main.TaskArea = main.skeletonArea; } We check which String our user selected and change our Area in our Main class to the Area of the selected NPC, if your GUI is not in a separate class then you don't need to add "main." Link to comment Share on other sites More sharing options...
ElChapoJr 15 Author Share Posted August 1, 2017 Thanks Noodle! Do you mind if I pm you if I have any other questions? public int onLoop() { if (startScript) { if (gui.Location().contains(getLocalPlayer())) { pickPocket(gui.getVictimType()); } else { if (getWalking().walk(gui.Location().getRandomTile())) { } } } return 600; } Since you are newish to coding I'll show you an easy but not the cleanest way to do what you want done. It's very easy to follow along and will work for what you need done. What you need to do is implement a ActionListener in your GUI. For example here is a ComboBox action listener in a Gui class npcComboBox.addActionListener(e -> selectedNPC = npcComboBox.getSelectedItem().toString()); What this does is set my variable "String selectedNPC" in my gui class to a String that of the players choice For reference here is how I set my ComboBox npcComboBox.setModel(new DefaultComboBoxModel(new String[] {"Giant rat", "Scorpion", "Skeleton"})); So selectedNPC will change each time the user selects a new option in the ComboBox Now that we have information of what the player chose we need to convert the string into the location of what we selected, we do so by going to your Start button action listener (You should already have this implemented and your script shouldn't loop until your gui has been set.) Inside our Start button action listener we add if(selectedNPC == "Scorpion") { main.TaskArea = main.scorpionArea; } else if(selectedNPC =="Giant rat") { main.TaskArea = main.ratArea; } else if(selectedNPC == "Skeleton") { main.TaskArea = main.skeletonArea; } We check which String our user selected and change our Area in our Main class to the Area of the selected NPC, if your GUI is not in a separate class then you don't need to add "main." Link to comment Share on other sites More sharing options...
Pyth 127 Share Posted August 1, 2017 Thanks Noodle! Do you mind if I pm you if I have any other questions? Sure, although you'll probably get a faster response if you message me on Discord. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.