Xiwi Posted May 26, 2018 Share Posted May 26, 2018 (edited) Hello! I just got into botting and I decided to make my first script. It's a simple woodcutting script, that cuts oaks at the back of the lumbridge castle and banks them in the upstairs bank. It has a simple paint with how much xp you have gained, how many levels gained, how many logs you have chopped and how much gold you have made. If you want to chop something else you can change the cutting area, banking area and what kind of tree to chop in the code. How to use: Equip your axe. Start near lumbridge castle. Press play and it starts chopping! Paint and small proggy I decided to post this script for everyone, so that if there's anyone who might want to get into making scripts, they can look at what I have done and copy some of that. Because this was my first script i'm open to feedback! Please point out if I should have made something differently. Codes .jar download link. Place this into your OSbot script folder: C:\Users\yourprofilename\OSBot\Scripts Sorry about this long code line. Didn't know to to make it hide. Code: Spoiler import org.osbot.rs07.api.map.Area; import org.osbot.rs07.api.map.constants.Banks; import org.osbot.rs07.api.model.Entity; import org.osbot.rs07.api.model.RS2Object; import org.osbot.rs07.api.ui.Skill; import org.osbot.rs07.script.Script; import org.osbot.rs07.script.ScriptManifest; import org.osbot.rs07.utility.ConditionalSleep; import javax.imageio.ImageIO; import java.awt.*; import java.io.IOException; import java.net.URL; import java.text.DecimalFormat; import java.util.concurrent.TimeUnit; @ScriptManifest(name = "Xiwi's Woodcutter", version = 1.0, author = "Xiwi", logo = "https://i.imgur.com/ZlQD7PIt.png", info = "Cuts wood and banks it.") public class Main extends Script { //Areas. You can pick your area easily with this: "https ://explv.github.io/". private final Area treeArea = new Area(3172, 3262, 3192, 3245); private final Area lumbridgeBankArea = new Area(3208, 3218, 3209, 3219); //Paint variables. private long timeBegan; private long timeRan; private int currentXp; private int xpGained; private int beginningXp; private int currentLevel; private int beginningLevel; private int levelsGained; private int costOfItem; private int itemsMade = 0; private double gpGained; private double totalGpGained; private double oakXp = 37.5; //Background image. private final Image bg = getImage("https://i.imgur.com/ZnxtQe1.png"); @Override public void onStart() throws InterruptedException { //Anything place on here in here is played when script is started. beginningXp = skills.getExperience(Skill.WOODCUTTING); beginningLevel = skills.getStatic(Skill.WOODCUTTING); timeBegan = System.currentTimeMillis(); costOfItem = 42; //Price of the logs. } @Override public int onLoop() throws InterruptedException { //Anything placed here keeps looping. if (getInventory().getEmptySlotCount() != 0) { RS2Object tree = getObjects().closest(obj -> obj != null && obj.getName().equals("Oak") && getMap().canReach(obj)); //What tree to chop. if (!myPlayer().isAnimating()) { if (tree != null) { if (tree.interact("Chop down")) { new ConditionalSleep(5000, 2000) { @Override public boolean condition() throws InterruptedException { return false; } }.sleep(); } } else if (tree == null) { //If it doesn't see a tree it moves the camera and then moves. getCamera().toEntity(tree); log("Searching for a tree..."); if (getWalking().webWalk(treeArea)) { log("Walking to trees..."); new ConditionalSleep(5000, 6000) { @Override public boolean condition() throws InterruptedException { return false; } }; } } } } else { log("Inventory full."); //Walks to the bank. if (getWalking().webWalk(Banks.LUMBRIDGE_UPPER)) { //What bank it banks at. log("Walking to bank..."); new ConditionalSleep(5000, 1000) { @Override public boolean condition() throws InterruptedException { return true;} }; Entity depoBox = objects.closest("Bank deposit box"); //Opens deposit box and deposits logs. if (depoBox != null) { new ConditionalSleep(2000, 5000) { @Override public boolean condition() throws InterruptedException { return true; } }; if (depoBox.interact("Deposit")) { while (!depositBox.isOpen()) { new ConditionalSleep(2000, 5000) { @Override public boolean condition() throws InterruptedException { return true; } }; } depositBox.depositAllExcept("Bronze axe"); } } } } return 1000;} @Override public void onExit () throws InterruptedException { //Anything placed here executes when the script stops. log("Chopped: "); log(itemsMade); log("Made: "); log(gpGained); } @Override public void onPaint (Graphics2D g) { //Text font, color, size. Font font = new Font("Consolas", Font.BOLD, 15); g.setFont(font); g.setFont(g.getFont().deriveFont(15.0f)); g.setColor(Color.yellow); Graphics2D gr = g; //Background. g.drawImage(bg, -3, 335, null); //Script run time. timeRan = System.currentTimeMillis() - this.timeBegan; g.drawString("Time ran for: ", 40,395); g.drawString(ft(timeRan), 150, 395); //XP tracking and displaying. currentXp = skills.getExperience(Skill.WOODCUTTING); xpGained = currentXp - beginningXp; g.drawString("XP Gained: " + xpGained, 40, 420); levelsGained = currentLevel - beginningLevel; currentLevel = skills.getStatic(Skill.WOODCUTTING); g.drawString("Levels gained:" + levelsGained,260, 420); g.drawString("(" + beginningLevel, 383, 420 ); g.drawString(")", 407, 420); //How many logs chopped and profits,´. itemsMade = (int) (xpGained / oakXp); gpGained = itemsMade * costOfItem; totalGpGained = gpGained / 1000; DecimalFormat df = new DecimalFormat("#"); g.drawString("Gold made: " + df.format(totalGpGained) + " k", 260,445); g.drawString("Logs chopped: " + df.format(itemsMade), 40,445); } private String ft(long duration) //Makes time 0:0:0 { String res = ""; long days = TimeUnit.MILLISECONDS.toDays(duration); long hours = TimeUnit.MILLISECONDS.toHours(duration) - TimeUnit.DAYS.toHours(TimeUnit.MILLISECONDS.toDays(duration)); long minutes = TimeUnit.MILLISECONDS.toMinutes(duration) - TimeUnit.HOURS.toMinutes(TimeUnit.MILLISECONDS .toHours(duration)); long seconds = TimeUnit.MILLISECONDS.toSeconds(duration) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS .toMinutes(duration)); if (days == 0) { res = (hours + ":" + minutes + ":" + seconds); } else { res = (days + ":" + hours + ":" + minutes + ":" + seconds); } return res; } private Image getImage(String url) //Get's the background image. { try { return ImageIO.read(new URL(url)); } catch (IOException e) {} return null; } } Edited June 18, 2018 by Xiwi Added a spoiler for the code Quote Link to comment Share on other sites More sharing options...
01053 Posted June 1, 2018 Share Posted June 1, 2018 (edited) Nice work on your first script only thing I really see that could be changed is; else if (tree == null) { //If it doesn't see a tree it moves the camera and then moves. getCamera().toEntity(tree); log("Searching for a tree..."); if (getWalking().webWalk(treeArea)) { log("Walking to trees..."); new ConditionalSleep(5000, 6000) { @Override public boolean condition() throws InterruptedException { return false; } }; } } } Should probably check if the tree isVisible() and not if it's null because if the tree is null then your trying to face a null object, also that sleep wouldn't work properly. you should probably make it something like, new ConditionalSleep(5000, 250) { @Override public boolean condition() throws InterruptedException { return tree.isVisible(); } }; Edited June 1, 2018 by 01053 Quote Link to comment Share on other sites More sharing options...
TheMcPker Posted June 1, 2018 Share Posted June 1, 2018 On 5/26/2018 at 1:52 PM, Xiwi said: Hello! I just got into botting and I decided to make my first script. It's a simple woodcutting script, that cuts oaks at the back of the lumbridge castle and banks them in the upstairs bank. It has a simple paint with how much xp you have gained, how many levels gained, how many logs you have chopped and how much gold you have made. If you want to chop something else you can change the cutting area, banking area and what kind of tree to chop in the code. How to use: Equip your axe. Start near lumbridge castle. Press play and it starts chopping! Paint and small proggy I decided to post this script for everyone, so that if there's anyone who might want to get into making scripts, they can look at what I have done and copy some of that. Because this was my first script i'm open to feedback! Please point out if I should have made something differently. Codes .jar download link. Place this into your OSbot script folder: C:\Users\yourprofilename\OSBot\Scripts Sorry about this long code line. Didn't know to to make it hide. Code: import org.osbot.rs07.api.map.Area; import org.osbot.rs07.api.map.constants.Banks; import org.osbot.rs07.api.model.Entity; import org.osbot.rs07.api.model.RS2Object; import org.osbot.rs07.api.ui.Skill; import org.osbot.rs07.script.Script; import org.osbot.rs07.script.ScriptManifest; import org.osbot.rs07.utility.ConditionalSleep; import javax.imageio.ImageIO; import java.awt.*; import java.io.IOException; import java.net.URL; import java.text.DecimalFormat; import java.util.concurrent.TimeUnit; @ScriptManifest(name = "Xiwi's Woodcutter", version = 1.0, author = "Xiwi", logo = "https://i.imgur.com/ZlQD7PIt.png", info = "Cuts wood and banks it.") public class Main extends Script { //Areas. You can pick your area easily with this: "https ://explv.github.io/". private final Area treeArea = new Area(3172, 3262, 3192, 3245); private final Area lumbridgeBankArea = new Area(3208, 3218, 3209, 3219); //Paint variables. private long timeBegan; private long timeRan; private int currentXp; private int xpGained; private int beginningXp; private int currentLevel; private int beginningLevel; private int levelsGained; private int costOfItem; private int itemsMade = 0; private double gpGained; private double totalGpGained; private double oakXp = 37.5; //Background image. private final Image bg = getImage("https://i.imgur.com/ZnxtQe1.png"); @Override public void onStart() throws InterruptedException { //Anything place on here in here is played when script is started. beginningXp = skills.getExperience(Skill.WOODCUTTING); beginningLevel = skills.getStatic(Skill.WOODCUTTING); timeBegan = System.currentTimeMillis(); costOfItem = 42; //Price of the logs. } @Override public int onLoop() throws InterruptedException { //Anything placed here keeps looping. if (getInventory().getEmptySlotCount() != 0) { RS2Object tree = getObjects().closest(obj -> obj != null && obj.getName().equals("Oak") && getMap().canReach(obj)); //What tree to chop. if (!myPlayer().isAnimating()) { if (tree != null) { if (tree.interact("Chop down")) { new ConditionalSleep(5000, 2000) { @Override public boolean condition() throws InterruptedException { return false; } }.sleep(); } } else if (tree == null) { //If it doesn't see a tree it moves the camera and then moves. getCamera().toEntity(tree); log("Searching for a tree..."); if (getWalking().webWalk(treeArea)) { log("Walking to trees..."); new ConditionalSleep(5000, 6000) { @Override public boolean condition() throws InterruptedException { return false; } }; } } } } else { log("Inventory full."); //Walks to the bank. if (getWalking().webWalk(Banks.LUMBRIDGE_UPPER)) { //What bank it banks at. log("Walking to bank..."); new ConditionalSleep(5000, 1000) { @Override public boolean condition() throws InterruptedException { return true;} }; Entity depoBox = objects.closest("Bank deposit box"); //Opens deposit box and deposits logs. if (depoBox != null) { new ConditionalSleep(2000, 5000) { @Override public boolean condition() throws InterruptedException { return true; } }; if (depoBox.interact("Deposit")) { while (!depositBox.isOpen()) { new ConditionalSleep(2000, 5000) { @Override public boolean condition() throws InterruptedException { return true; } }; } depositBox.depositAllExcept("Bronze axe"); } } } } return 1000;} @Override public void onExit () throws InterruptedException { //Anything placed here executes when the script stops. log("Chopped: "); log(itemsMade); log("Made: "); log(gpGained); } @Override public void onPaint (Graphics2D g) { //Text font, color, size. Font font = new Font("Consolas", Font.BOLD, 15); g.setFont(font); g.setFont(g.getFont().deriveFont(15.0f)); g.setColor(Color.yellow); Graphics2D gr = g; //Background. g.drawImage(bg, -3, 335, null); //Script run time. timeRan = System.currentTimeMillis() - this.timeBegan; g.drawString("Time ran for: ", 40,395); g.drawString(ft(timeRan), 150, 395); //XP tracking and displaying. currentXp = skills.getExperience(Skill.WOODCUTTING); xpGained = currentXp - beginningXp; g.drawString("XP Gained: " + xpGained, 40, 420); levelsGained = currentLevel - beginningLevel; currentLevel = skills.getStatic(Skill.WOODCUTTING); g.drawString("Levels gained:" + levelsGained,260, 420); g.drawString("(" + beginningLevel, 383, 420 ); g.drawString(")", 407, 420); //How many logs chopped and profits,´. itemsMade = (int) (xpGained / oakXp); gpGained = itemsMade * costOfItem; totalGpGained = gpGained / 1000; DecimalFormat df = new DecimalFormat("#"); g.drawString("Gold made: " + df.format(totalGpGained) + " k", 260,445); g.drawString("Logs chopped: " + df.format(itemsMade), 40,445); } private String ft(long duration) //Makes time 0:0:0 { String res = ""; long days = TimeUnit.MILLISECONDS.toDays(duration); long hours = TimeUnit.MILLISECONDS.toHours(duration) - TimeUnit.DAYS.toHours(TimeUnit.MILLISECONDS.toDays(duration)); long minutes = TimeUnit.MILLISECONDS.toMinutes(duration) - TimeUnit.HOURS.toMinutes(TimeUnit.MILLISECONDS .toHours(duration)); long seconds = TimeUnit.MILLISECONDS.toSeconds(duration) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS .toMinutes(duration)); if (days == 0) { res = (hours + ":" + minutes + ":" + seconds); } else { res = (days + ":" + hours + ":" + minutes + ":" + seconds); } return res; } private Image getImage(String url) //Get's the background image. { try { return ImageIO.read(new URL(url)); } catch (IOException e) {} return null; } } very inpressive for a first script Quote Link to comment Share on other sites More sharing options...
Xiwi Posted June 18, 2018 Author Share Posted June 18, 2018 On 6/1/2018 at 5:53 AM, 01053 said: Nice work on your first script only thing I really see that could be changed is; else if (tree == null) { //If it doesn't see a tree it moves the camera and then moves. getCamera().toEntity(tree); log("Searching for a tree..."); if (getWalking().webWalk(treeArea)) { log("Walking to trees..."); new ConditionalSleep(5000, 6000) { @Override public boolean condition() throws InterruptedException { return false; } }; } } } Should probably check if the tree isVisible() and not if it's null because if the tree is null then your trying to face a null object, also that sleep wouldn't work properly. you should probably make it something like, new ConditionalSleep(5000, 250) { @Override public boolean condition() throws InterruptedException { return tree.isVisible(); } }; Okay thanks for the tip! On 6/1/2018 at 10:39 AM, TheMcPker said: very inpressive for a first script Thank you! Going to make something much better (at least hope so) once I find the time to code Quote Link to comment Share on other sites More sharing options...
Pectorial Posted August 5, 2023 Share Posted August 5, 2023 Very helpful use case that explained web walking and how to define areas. I appreciate it! Quote Link to comment Share on other sites More sharing options...
Fernandohoff Posted September 24 Share Posted September 24 That sounds like a great start with your woodcutting script! I remember when I first got into scripting, I was super excited about tracking stats too. It's really satisfying to see the progress, right? If you ever want to take it a step further, adding some anti-ban features can help keep things under the radar. I had a script that would occasionally switch locations or trees just to mix things up, and it seemed to work well. Quote Link to comment Share on other sites More sharing options...