12we12qw12 Posted May 8, 2019 Share Posted May 8, 2019 I'm making a woodcutting script but I have ran into an issue, when I get a full inventory of logs my character will walk to the back but will not deposit the logs but instead run back to the trees and try to cut them down. This making my character run back and forth. Script is below, I don't know what to add to fix this. If you guys have any other recommendations to add to the script or tips let me know, Thanks. @Override public void onStart() throws InterruptedException { super.onStart(); int wcLvl = getSkills().getStatic(Skill.WOODCUTTING); if (getInventory().isEmptyExcept("Bronze axe", "Iron axe", "Steel Axe", "Black axe", "Mithril axe", "Adamant axe", "Rune axe", "Dragon axe")) ; } @Override public int onLoop() throws InterruptedException { Player player = myPlayer(); RS2Object Tree = getObjects().closest(new Filter<RS2Object>() { @Override public boolean match(RS2Object rs2Object) { return rs2Object != null && rs2Object.getName().equals("Tree") && rs2Object.exists() && getMap().canReach(rs2Object); } }); if (Banks.VARROCK_WEST.contains(myPosition()) && bankbooth != null && !getBank().isOpen()) { getBank().withdraw("Steel axe",1); } if (Tree != null) if (Tree.isVisible()) { getWalking().walk(Tree.getPosition()); getCamera().toEntity(Tree); if (Tree.getPosition().distance(myPosition()) > 6) ; if (!myPlayer().isAnimating()) if (Tree.interact("Chop down")) ; getMouse().moveOutsideScreen(); sleep(random(301, 2999)); } else { RS2Object bankBooth = getObjects().closest("Bank booth"); if (getInventory().isFull()) getWalking().webWalk(BANK_AREA); log("Inventory full walking to bank"); if (Banks.VARROCK_WEST.contains(myPosition()) && bankbooth != null && !getBank().isOpen()) { getBank().depositAllExcept("Bronze axe", "Iron axe", "Steel axe", "Black axe", "Mithril axe", "Adamant axe", "Rune axe", "Dragon axe"); log("interacting with bank"); bankBooth.interact("Bank"); } else if (getBank().isOpen()) { int wcLvl = getSkills().getStatic(Skill.WOODCUTTING); log("Depositing Logs"); getBank().depositAllExcept("Bronze axe", "Iron axe", "Steel axe", "Black axe", "Mithril axe", "Adamant axe", "Rune axe", "Dragon axe"); if (wcLvl >= 6 && getInventory().contains("Bronze axe", "Iron axe") && getBank().contains("Steel axe")) { log("withdrawing shitty axe"); getBank().deposit("Bronze axe", 1); getBank().withdraw("Steel axe", 1); } } }return 0;}} Quote Link to comment Share on other sites More sharing options...
Imthabawse Posted May 8, 2019 Share Posted May 8, 2019 Perhaps split the script into 2 methods Private void chop () { // chop code here Private void bank () { // bank code here Call in loop if(!getInventory.isFull) { Chop (); }else{ Bank (); Would look cleaner and function better. Quote Link to comment Share on other sites More sharing options...
CasDeBlanco Posted May 8, 2019 Share Posted May 8, 2019 (edited) I'd also recommend making some methods and take a look at conditional sleeps. It's running back and forth because both your banking if statement and your chopping if statement can both be valid at the same time. Also, change the return from 0 to like 600 or so as it'll help reduce CPU usage etc Edited May 8, 2019 by Castro_ 1 Quote Link to comment Share on other sites More sharing options...
EsotericRS Posted May 8, 2019 Share Posted May 8, 2019 22 minutes ago, Imthabawse said: Perhaps split the script into 2 methods Private void chop () { // chop code here Private void bank () { // bank code here Definitely feel this here. The readability of this code should jump out at you. 1 hour ago, 12we12qw12 said: I'm making a woodcutting script but I have ran into an issue, when I get a full inventory of logs my character will walk to the back but will not deposit the logs but instead run back to the trees and try to cut them down. This making my character run back and forth. Script is below, I don't know what to add to fix this. If you guys have any other recommendations to add to the script or tips let me know, Thanks. int wcLvl = getSkills().getStatic(Skill.WOODCUTTING); if (getInventory().isEmptyExcept("Bronze axe", "Iron axe", "Steel Axe", "Black axe", "Mithril axe", "Adamant axe", "Rune axe", "Dragon axe")) ; } ....... if (Banks.VARROCK_WEST.contains(myPosition()) && bankbooth != null && !getBank().isOpen()) { getBank().withdraw("Steel axe",1); } I would look into flow control for help with this... Quote Link to comment Share on other sites More sharing options...
Charlotte Posted May 8, 2019 Share Posted May 8, 2019 You got to know how if else statement works before proceeding. Quote Link to comment Share on other sites More sharing options...
Imthabawse Posted May 14, 2019 Share Posted May 14, 2019 Study @Explv's Scripting tutorial and study the structure of his example script. This should give you a better idea of how to write your own scripts. Studying some Java syntax wont hurt either. Look into conditional sleeps as well so your bot will sleep until a condition is met rather than trying to execute actions instantaneously. Quote Link to comment Share on other sites More sharing options...
HeyImJamie Posted May 14, 2019 Share Posted May 14, 2019 Stop, learn java, come back, write scripts. Quote Link to comment Share on other sites More sharing options...
Czar Posted May 14, 2019 Share Posted May 14, 2019 (edited) There are many logical errors, go over each line and make sure they make sense. I highly recommend using { } properly, otherwise it will be super confusing, the entire 'if (Tree != null) is a one line if statement extending 50 lines, also format the code it should be more readable, which software are you using for coding? Split up the logic into two, so you have player_woodcutting, and player_banking: The woodcutting part isn't done, you gotta do that yourself: @Override public int onLoop() throws InterruptedException { if (getInventory().isFull()) { /* * If inventory full, go bank */ if (!Banks.VARROCK_WEST.contains(myPlayer())) { getWalking().webWalk(Banks.VARROCK_EAST); } else { if (!getBank().isOpen()) { getBank().open(); return 1; } if (getBank().depositAllExcept("Bronze axe", "Iron axe", "Steel axe", "Black axe", "Mithril axe", "Adamant axe", "Rune axe", "Dragon axe")) { log("Deposited everything except axe"); } } } else { /* * Inventory not full yet, keep woodcutting. */ RS2Object treeObject = getObjects().closest(a -> a.getName().equalsIgnoreCase("Tree")); if (treeObject != null) { if (treeObject.interact("Chop-down")) { log("Clicked chop!"); } } } return 0; } Edited May 14, 2019 by Czar Quote Link to comment Share on other sites More sharing options...
AsBakedAsCake Posted May 14, 2019 Share Posted May 14, 2019 (edited) Yeah the logic in this code makes no sense. Also, you should almost NEVER return 0. Please, do yourself a favor and look here: https://www.w3schools.com/java/java_conditions.asp This will explain how each statement works. After looking this over you should have a better understanding - even without experience. It's easier than you would think At the bottom of the page there are also exercises for practice. Good luck. Edited May 14, 2019 by AsBakedAsCake Quote Link to comment Share on other sites More sharing options...