Computor 178 Posted July 15, 2015 (edited) Hey guys, I've decided to make a little video tutorial series for dreambot scripting. If you enjoy these tutorials, please let me know, otherwise I won't continue making more videos. If you want me to make a video on something specific, request them here. My IDE: https://www.jetbrains.com/idea/download/ All videos are in 1080p, be sure to watch them in HD. ______________________________________________________________________________________________________ Series 1 - Basic Dreambot Scripting. Creating your first script (woodcutter): Part 1/3: Part 2/3: Part 3/3: Series 1 final code: package BasicWoodcutter; import org.dreambot.api.methods.Calculations; import org.dreambot.api.methods.filter.Filter; import org.dreambot.api.methods.map.Area; import org.dreambot.api.script.AbstractScript; import org.dreambot.api.script.Category; import org.dreambot.api.script.ScriptManifest; import org.dreambot.api.wrappers.interactive.GameObject; import org.dreambot.api.wrappers.interactive.NPC; import java.awt.*; /** * Created by Computor on 7/8/2015. */ @ScriptManifest(category = Category.WOODCUTTING, name = "Basic WoodCutter", author = "Computor", version = 1.0) public class MainClass extends AbstractScript{ Area bankArea = new Area(3092, 3240, 3097, 3246, 0); Area treeArea = new Area(3091, 3290, 3072, 3310, 0); @Override public void onStart(){ log("Hi"); } @Override public int onLoop() { /** * Chopping trees: Time to chop some trees, our inventory isn't full. We want to fill it up. */ if(!getInventory().isFull()){ if(treeArea.contains(getLocalPlayer())){ chopTree("Tree"); //change "Tree" to the name of your tree. }else{ if(getWalking().walk(treeArea.getRandomTile())){ sleep(Calculations.random(3000, 5500)); } } } /** * Banking: Time to bank our logs. Our inventory is full, we want to empty it. */ if(getInventory().isFull()){ //it is time to bank if(bankArea.contains(getLocalPlayer())){ bank(); }else{ if(getWalking().walk(bankArea.getRandomTile())){ sleep(Calculations.random(3000, 6000)); } } } return 600; } @Override public void onExit() { log("Bye"); } @Override public void onPaint(Graphics graphics) { } private void chopTree(String nameOfTree){ GameObject tree = getGameObjects().closest(gameObject -> gameObject != null && gameObject.getName().equals(nameOfTree)); if(tree != null && tree.interact("Chop down")){ int countLog = getInventory().count("Logs"); sleepUntil(() -> getInventory().count("Logs") > countLog, 12000); } } private void bank(){ NPC banker = getNpcs().closest(npc -> npc != null && npc.hasAction("Bank")); if(banker != null && banker.interact("Bank")){ if(sleepUntil(() -> getBank().isOpen(), 9000)){ if(getBank().depositAllExcept(item -> item != null && item.getName().contains("axe"))){ if(sleepUntil(() -> !getInventory().isFull(), 8000)){ if(getBank().close()){ sleepUntil(() -> !getBank().isOpen(), 8000); } } } } } } } ______________________________________________________________________________________________________ Series 2 - Basic Dreambot Scripting. Basic GUI and paint: Song list: Galantis - Gold Dust (East & Young Remix)Galantis - Runaway (U & I)The Chainsmokers - RosesMadeon - Pop CultureDillon Francis - I.D.G.A.F.O.S.Tiësto - Red LightsTristam & Braken - Frame of Mind Part 1/3: Part 2/3: Part 3/3: Series 2 final code: Main code: package BasicGUIandPaint; import org.dreambot.api.methods.Calculations; import org.dreambot.api.methods.map.Area; import org.dreambot.api.script.AbstractScript; import org.dreambot.api.script.Category; import org.dreambot.api.script.ScriptManifest; import org.dreambot.api.utilities.Timer; import org.dreambot.api.utilities.impl.Condition; import org.dreambot.api.wrappers.interactive.GameObject; import org.dreambot.api.wrappers.interactive.NPC; import org.dreambot.api.wrappers.widgets.message.Message; import javax.imageio.ImageIO; import java.awt.*; import java.io.IOException; import java.net.URL; /** * Created by Computor on 8/1/2015. */ @ScriptManifest(category = Category.MISC, name = "Basic GUI and Paint tutorial", author = "Computor", version = 1.0) public class BasicGUIandPaint extends AbstractScript{ private Area bankArea = new Area(3092, 3240, 3097, 3246, 0); private Area treeArea = new Area(3091, 3290, 3072, 3310, 0); private boolean startScript; private BasicWoodcutterGUI gui; private Image mainPaint = getImage("http://i.imgur.com/qbyHTS8.png"); private int logsCut; private Timer timeRan; @Override public void onStart() { gui = new BasicWoodcutterGUI(this); gui.setVisible(true); timeRan = new Timer(); } @Override public void onMessage(Message message) { if(message.getMessage().contains("You get")){ logsCut++; } } @Override public int onLoop() { /** * Chopping trees: Time to chop some trees, our inventory isn't full. We want to fill it up. */ if(startScript) { if (!getInventory().isFull()) { if (treeArea.contains(getLocalPlayer())) { chopTree(gui.getTreeType()); //change "Tree" to the name of your tree. } else { if (getWalking().walk(treeArea.getRandomTile())) { sleep(Calculations.random(3000, 5500)); } } } /** * Banking: Time to bank our logs. Our inventory is full, we want to empty it. */ if (getInventory().isFull()) { //it is time to bank if (bankArea.contains(getLocalPlayer())) { bank(); } else { if (getWalking().walk(bankArea.getRandomTile())) { sleep(Calculations.random(3000, 6000)); } } } } return 200; //Sleeps for 200 milliseconds (0.2 seconds) } @Override public void onPaint(Graphics2D g) { Font font = new Font("Times new roamn", Font.PLAIN, 19); g.setFont(font); g.setColor(Color.BLACK); g.drawImage(mainPaint, 0, 340, null); g.drawString("" + timeRan.formatTime(), 121, 371); g.drawString("" + logsCut, 121, 400); g.drawString("" + logsCut * (int)(3600000D / (timeRan.elapsed())),121, 430); } /** * --------Methods-------- */ /** * **************************************************************************************** * Function: chopTree * Description: A simple way to interact with a tree gameObject. * @param nameOfTree The name of the tree we want to cut down. * **************************************************************************************** */ private void chopTree(String nameOfTree){ GameObject tree = getGameObjects().closest(gameObject -> gameObject != null && gameObject.getName().equals(nameOfTree)); if(tree != null && tree.interact("Chop down")){ log("Sleeping for tree"); sleepUntil(new Condition() { int animationCount = 0; int sleepTimer = Calculations.random(300,550); public boolean verify() { if (getLocalPlayer().getAnimation() != -1) { //We're actually animating with the tree. animationCount = 0; //Reset the count back to 0 } else { //We're sitting still, or lagging-out animationCount++; //Add 1 to the count. If we go over our sleepTimer count, it's time to move on, or re-interact. } return !tree.exists() || animationCount > sleepTimer || getDialogues().canContinue(); //Will kick out of the sleep method if we're idle for over 7-10 seconds and the tree is still present } },100000); log("Done sleeping for tree"); } } /** * **************************************************************************************** * Function: bank * Description: A simple method which finds the nearest banker NPC to the local * player, interacts with it, and sleeps until the bank is open, then * precedes to deposit all items except for the axe. * **************************************************************************************** */ private void bank(){ NPC banker = getNpcs().closest(npc -> npc != null && npc.hasAction("Bank")); if(getBank().isOpen() || (banker != null && banker.interact("Bank") && sleepUntil(() -> getBank().isOpen(), 9000))){ //The bank is open, or we interact with the banker and sleep till open if(getInventory().onlyContains(item1 -> item1 != null && item1.getName().contains(" axe")) || getBank().depositAllExcept(item -> item != null && item.getName().contains(" axe"))){ if(sleepUntil(() -> !getInventory().isFull(), 8000)){ if(getBank().close()){ sleepUntil(() -> !getBank().isOpen(), 8000); } } } } } /** * **************************************************************************************** * Function: getImage * Description: Method which returns an image from a given URL link. * **************************************************************************************** */ private Image getImage(String url){ try { return ImageIO.read(new URL(url)); }catch (IOException e){ return null; } } /** * --------Getters/Setters-------- */ public void setStartScript(boolean startScript) { this.startScript = startScript; } } GUI code: /* * Created by JFormDesigner on Tue Aug 18 19:34:59 EDT 2015 */ package BasicGUIandPaint; import java.awt.*; import java.awt.event.*; import javax.swing.*; /** * @author Jeff Smith */ public class BasicWoodcutterGUI extends JFrame { private BasicGUIandPaint ctx; public BasicWoodcutterGUI(BasicGUIandPaint main){ this.ctx = main; initComponents(); } private void button1ActionPerformed(ActionEvent e) { ctx.setStartScript(true); this.setVisible(false); } private void initComponents() { button1 = new JButton(); comboBox1 = new JComboBox<>(); label1 = new JLabel(); //======== this ======== setTitle("Simple WoodCutter GUI"); Container contentPane = getContentPane(); contentPane.setLayout(null); //---- button1 ---- button1.setText("Start"); button1.addActionListener(e -> button1ActionPerformed(e)); contentPane.add(button1); button1.setBounds(10, 55, 275, 55); //---- comboBox1 ---- comboBox1.setModel(new DefaultComboBoxModel<>(new String[]{ "Tree", "Oak" })); contentPane.add(comboBox1); comboBox1.setBounds(15, 10, 185, 35); //---- label1 ---- label1.setText("Select your tree type."); contentPane.add(label1); label1.setBounds(new Rectangle(new Point(205, 20), label1.getPreferredSize())); contentPane.setPreferredSize(new Dimension(335, 120)); pack(); setLocationRelativeTo(getOwner()); } public String getTreeType() { return comboBox1.getSelectedItem().toString(); } private JButton button1; private JComboBox<String> comboBox1; private JLabel label1; } Edited September 10, 2015 by Computor Pandemic, HydraTal, jorgitoxx2101 and 17 others 2 18
Cruel 103 Posted July 15, 2015 (edited) Got any requests? I will after I'm finished sitting down and watching these. lol Edited July 15, 2015 by Cruel
Speed 79 Posted July 15, 2015 This is pretty generous of you, I'm going to go through it and give you my feedback! ( its going to be a positive one for sure )
QuakedM8 58 Posted July 15, 2015 This looks sick! Just what I needed to make my first script, I'll for sure make it when I have time, keep it up @Computor YOU'RE THE BEST! JAMES SUCKS!
Polish Civil 90 Posted July 15, 2015 (edited) 10 years later, job interview: - What languages do you know? - Dreambot API.I'm not saying its bad. But there shouldn't be any 'tutorial' of scripting, just good documentation. [imho]And pls 'package BasicWoodcutter;' dat sexy voice alt+insert ctrl alt v,c,f ctrl alt m Edited July 15, 2015 by Polish Civil
Chris 154 Posted July 15, 2015 gr8 woddcutter m8 10 years later, job interview: - What languages do you know? - Dreambot API.I'm not saying its bad. But there shouldn't be any 'tutorial' of scripting, just good documentation. [imho]And pls 'package BasicWoodcutter;' dat sexy voice alt+insert ctrl alt v,c,f ctrl alt m In many ways, knowing how to use an API is all java really is. Java itself is an API, amirite? I think video tutorials are a good start. It would be an even better start if we can focus on teaching valuable programming practices through these tutorials to generate better future programmers. It's important to teach how to do something, but even more important to teach WHY to do something. pls porish, api's r for losers. make ur own swing or jfx caus i no u use dat api Speed and HydraTal 2
ishyfishy 5 Posted July 15, 2015 Nice, can you make a video on adding GUIs to scripts? (ex. time ran, showing logs as status, etc) OldGrama 1
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now