REEEEEEEEEENN 1 Share Posted June 25, 2020 Hello, I am a new scripter, who hasa been working on a wc progression script. my background with Java is very basic, and I would love any advice on how to make the script better. This is my first script so I know its bad. (I still need to add paints and maybe I will figure out Gui's one day.) as for the code, If there is more efficent ways of doing it, I would love to know what type of functions I should use. -Renn p.s I havnt tested the willow section (so it maybe buggy) import java.awt.*; import org.dreambot.api.methods.Calculations; import org.dreambot.api.methods.map.Area; import org.dreambot.api.methods.map.Tile; import org.dreambot.api.methods.skills.Skill; import org.dreambot.api.methods.tabs.Tab; 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.wrappers.interactive.GameObject; import org.dreambot.api.wrappers.widgets.WidgetChild; @ScriptManifest( author = "Renn", description = "Best Cutter", category = Category.WOODCUTTING, version = 1.01, name = "RCutter" ) public class Main extends AbstractScript { public static final String Willow_Tree = "Willow"; public static final String BRONZE_AXE = "Bronze axe"; public static final String IRON_AXE = "Iron axe"; public static final String STEEL_AXE = "Steel axe"; public static final String BLACK_AXE = "Black axe"; public static final String MITHRIL_AXE = "Mithril axe"; public static final String ADAMANT_AXE = "Adamant axe"; public static final String RUNE_AXE = "Rune axe"; private int Lvl; private static final Tile Tree_Tile = new Tile(3000, 3362); private static final Tile Oak_Tile = new Tile(3001, 3365); private static final Tile Willow_Tile = new Tile(3089, 3233); private Timer timer; Area TreeArea = new Area(3005,3354,2996,3371); Area OakArea = new Area(2999, 3370, 3005, 3363); @Override public void onStart() { Lvl = getSkills().getRealLevel(Skill.WOODCUTTING); timer = new Timer(); } @Override public void onPaint(Graphics g) { g.setColor(Color.WHITE); g.setFont(new Font("Arial", Font.PLAIN, 12)); g.drawString("Timer: " + timer.formatTime(), 10, 50); } @Override public int onLoop() { //If no Axe on start if (!getInventory().contains("Bronze axe", "Iron axe", "Steel axe", "Black axe", "Mithril axe", "Adamant axe", "Rune axe")) { log("No axe Found! Getting one."); getBank().openClosest(); getBank().depositAllItems(); if (getBank().contains(RUNE_AXE) && (getSkills().getRealLevel(Skill.WOODCUTTING) >= 41)) { getBank().withdraw(RUNE_AXE); } else if (getBank().contains(ADAMANT_AXE) && (getSkills().getRealLevel(Skill.WOODCUTTING) >= 31)) { getBank().withdraw(ADAMANT_AXE); } else if (getBank().contains(MITHRIL_AXE) && (getSkills().getRealLevel(Skill.WOODCUTTING) >= 21)) { getBank().withdraw(MITHRIL_AXE); } else if (getBank().contains(BLACK_AXE) && (getSkills().getRealLevel(Skill.WOODCUTTING) >= 11)) { getBank().withdraw(BLACK_AXE); } else if (getBank().contains(STEEL_AXE) && (getSkills().getRealLevel(Skill.WOODCUTTING) >= 6)) { getBank().withdraw(STEEL_AXE); } else if (getBank().contains(IRON_AXE) && (getSkills().getRealLevel(Skill.WOODCUTTING) >= 1)) { getBank().withdraw(IRON_AXE); } else if (getBank().contains(BRONZE_AXE) && (getSkills().getRealLevel(Skill.WOODCUTTING) >= 1)) { getBank().withdraw(BRONZE_AXE); }else{ getBank().close(); sleep(Calculations.random(1000, 2000)); getTabs().open(Tab.LOGOUT); sleep(Calculations.random(1000, 2000)); WidgetChild Logout = getWidgets().getWidgetChild(182, 12); Logout.interact("Logout"); stop(); } } // If wc lvl >= 30 gets 15 combat level (in progress) if (getSkills().getRealLevel(Skill.WOODCUTTING) >= 30) // Willow Section if (getSkills().getRealLevel(Skill.WOODCUTTING) >= 30) { if (getInventory().isFull()) { getBank().openClosest(); if (getBank().isOpen()) { getBank().depositAllExcept("Bronze axe", "Iron axe", "Steel axe", "Black axe", "Mithril axe", "Adamant axe", "Rune axe"); } } } if (!getInventory().isFull() && (getSkills().getRealLevel(Skill.WOODCUTTING) >= 30)) { if (getInventory().contains("Bronze axe", "Iron axe", "Steel axe", "Black axe", "Mithril axe", "Adamant axe", "Rune axe")) if (Willow_Tile.distance() > 5) { getWalking().walk(Willow_Tile); } else if (!getLocalPlayer().isAnimating()) { GameObject tree = getGameObjects().closest(Willow_Tree); if (tree != null) { tree.interact("Chop Down"); } } } //Oak Section else if (getSkills().getRealLevel(Skill.WOODCUTTING) >= 15) { if (getInventory().isFull()) { getBank().openClosest(); if (getBank().isOpen()) { getBank().depositAllExcept("Bronze axe", "Iron axe", "Steel axe", "Black axe", "Mithril axe", "Adamant axe", "Rune axe"); getBank().close(); } } if (!getInventory().isFull()) { if (getInventory().contains("Bronze axe", "Iron axe", "Steel axe", "Black axe", "Mithril axe", "Adamant axe", "Rune axe")) { if (Oak_Tile.distance() > 5) { getWalking().walk(Oak_Tile); } else if (!getLocalPlayer().isAnimating()) { GameObject tree = getGameObjects().closest(g -> g != null && g.getName().equals("Oak") && OakArea.contains(g)); tree.interact("Chop Down"); } } } } //Tree Section else if (getSkills().getRealLevel(Skill.WOODCUTTING) >= 1) { if (getInventory().isFull()) { getBank().openClosest(); if (getBank().isOpen()) { getBank().depositAllExcept("Bronze axe", "Iron axe", "Steel axe", "Black axe", "Mithril axe", "Adamant axe", "Rune axe"); } } if (!getInventory().isFull() && getInventory().contains("Bronze axe", "Iron axe", "Steel axe", "Black axe", "Mithril axe", "Adamant axe", "Rune axe")) { if (getInventory().contains("Bronze axe", "Iron axe", "Steel axe", "Black axe", "Mithril axe", "Adamant axe", "Rune axe")) { if (Tree_Tile.distance() > 10) { getWalking().walk(Tree_Tile); } else if (!getLocalPlayer().isAnimating()) { GameObject tree = getGameObjects().closest(g -> g != null && g.getName().equals("Tree") && TreeArea.contains(g)); tree.interact("Chop Down"); } } } } return 3000; } } Link to comment Share on other sites More sharing options...
Xtra 31 Share Posted June 25, 2020 Try to do 1 action per loop, otherwise if it lags or something some of the actions might not go through: if (condition) { //Action } With your get axe logic, you might want to try something along the lines of: If inventory doesn't contain an axe If bank is open Deposit all items If bank contains axe, and you have the required level to use it Withdraw the axe Close bank else, open closest bank Example (not sure if this will work straight up, its 3am and I'm very tired :)) if (!getInventory().contains("Iron axe")){ if (getBank().isOpen()){ getBank().depositAllItems(); if (getBank().contains("Iron axe")){ getBank().withdraw("Iron axe"); } getBank().close(); } else { getBank().openClosest(); } } Really good code though, there's probably more others could add to help you but these are what stood out to me! Nice job. Link to comment Share on other sites More sharing options...
CoolSlayer131 0 Share Posted June 25, 2020 i really like the scrips, could figure out classes and return statments and it will clean everything up Link to comment Share on other sites More sharing options...
Auroch 4 Share Posted June 25, 2020 Off the top of my head, I see two things which are basic but are good practice to follow For one, you reuse a bunch of strings that don't need to be reiterated over and over again, ("Bronze axe", "Iron axe", "Steel axe", "Black axe", "Mithril axe", "Adamant axe", "Rune axe") a more elegant solution is to use a filter considering all the these items have one constant value within each string:" axe" You should refactor if (getInventory().contains("Bronze axe", "Iron axe", "Steel axe", "Black axe", "Mithril axe", "Adamant axe", "Rune axe")) {} into: if(!getInventory.contains(a -> a.getName().contains(" axe"))){ log("No axe found!"); } or if you really needed to check through a list of different strings that have nothing in common, iterate over an array that's defined elsewhere to check if the inventory contains anything in your specified list: String[] list = {"Lobster", "Rune axe", "Small fishing net"}; for(int i=0; i<list.length; i++){ if(getInventory().contains(list[i]){ log("My inventory has: " + list[i]); } } //outputs: //My inventory has: Lobster //My inventory has: Rune axe //etc The other thing that jumps out to me is the use of singular tiles to move around, which in general probably isn't the best practice. Randomizing movement as much as possible is preferred, which the most simple method of this is the method getRandomTile() if(!TREE_AREA.contains(getLocalPlayer())){ getWalking.walk(TREE_AREA.getRandomTile()); } Link to comment Share on other sites More sharing options...
REEEEEEEEEENN 1 Author Share Posted June 25, 2020 Thanks for the feedback, I will for sure be adding it to my script. In testing I have been having problems with bans on it and getting it to act more human like will help that Link to comment Share on other sites More sharing options...
Xtra 31 Share Posted June 25, 2020 You could add some sleep(Calculations.random(50, 150)); etc so that it's not doing the same thing at exactly the same timings Link to comment Share on other sites More sharing options...
REEEEEEEEEENN 1 Author Share Posted June 25, 2020 1 minute ago, Xtra said: You could add some sleep(Calculations.random(50, 150); etc so that it's not doing the same thing at exactly the same timings Thats a good idea, I start adding that now. Link to comment Share on other sites More sharing options...
Xtra 31 Share Posted June 25, 2020 Keep in mind it might slow down your script if you use too many lol I always put a couple in my scripts atleast, usually just before or after an action Link to comment Share on other sites More sharing options...
REEEEEEEEEENN 1 Author Share Posted June 25, 2020 Yeah, I was seeing it double click trees, and now it dosnt do that anymore. I apricate the help. Link to comment Share on other sites More sharing options...
NovaGTX 106 Share Posted June 29, 2020 This is a common recommendation I make to new scripters. See the post I linked. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.