Twin Posted February 18, 2015 Share Posted February 18, 2015 (edited) I've had a few hiccups with this script but apaec has helped me through with most of it, basically when, it cuts down trees, and depending on your level will choose between willows, oaks or trees. it all goes well until it goes into the bank, it just stands there cluelessly. import org.osbot.rs07.api.Bank; import org.osbot.rs07.api.model.Entity; import org.osbot.rs07.api.ui.Skill; import org.osbot.rs07.script.Script; import org.osbot.rs07.script.ScriptManifest; import org.osbot.rs07.api.Skills; import org.osbot.rs07.api.ui.Skill; import org.osbot.rs07.utility.Area; import java.awt.*; @ScriptManifest(author = "Twin 763", info = "1-30 auto woodcutting levler", name = "Twin Power WC", version = 1, logo = "") public class Bf extends Script { @Override public void onStart() { log("If you experience any issues while running this script please report them to me on the forums."); log("Enjoy the script, gain some woodcutting levels!."); } Area BANK_AREA = new Area(3092, 3246, 3097, 3240); private int wcLvl2; private enum State { CHOP, BANK_WALK, BANK, TREE_WALK, WAIT, CHOPO, CHOPW,UNDER_ATTACK }; private State getState() { if (myPlayer().isUnderAttack()) return State.UNDER_ATTACK; if (inventory.isFull()) return State.BANK_WALK; if (!myPlayer().isAnimating()&&!inventory.isFull()) return State.CHOP; if (!myPlayer().isAnimating() && wcLvl2 >= 15 && wcLvl2 < 30&&!inventory.isFull()) return State.CHOPO; if (!myPlayer().isAnimating() && wcLvl2 >= 30&&!inventory.isFull()) return State.CHOPW; if (BANK_AREA.contains(myPlayer())) return State.BANK; if(inventory.isEmpty()) return State.TREE_WALK; return State.WAIT; } @Override public int onLoop() throws InterruptedException { switch (getState()) { case CHOP: Entity tree = objects.closest(1276, 1277, 1278); if (wcLvl2 < 15&&!myPlayer().isAnimating()&&!inventory.isFull()) { tree.interact("Chop down"); sleep(random(500, 1000)); break; } case CHOPO: Entity oak = objects.closest("Oak"); if (wcLvl2 < 30&&!myPlayer().isAnimating()&&!inventory.isFull()) { oak.interact("Chop down"); sleep(random(2000, 3000)); break; } case CHOPW: Entity willow = objects.closest("Willow"); if (wcLvl2 >= 30&&!myPlayer().isAnimating()) { willow.interact("Chop down"); sleep(random(500, 1000)); } case BANK: if (BANK_AREA.contains(myPlayer())) bank.open(); if(bank.isOpen()) { bank.depositAll("Logs,Oak logs, Willow logs"); break; } case BANK_WALK: if(inventory.isFull()) getLocalWalker().walk(3093, 3243); if (BANK_AREA.contains(myPlayer())) break; case TREE_WALK: if (wcLvl2 < 15&&!inventory.isFull()) { getLocalWalker().walk(3100, 3245); break; } else if (wcLvl2 >= 15 && wcLvl2 < 30&&!inventory.isFull()) { getLocalWalker().walk(3100, 3245); break; } else { getLocalWalker().walk(3090, 3234); break; } case UNDER_ATTACK: if(myPlayer().isUnderAttack()) getLocalWalker().walk(3093, 3244); break; case WAIT: sleep(random(500, 700)); break; } return random(200, 300); } @Override public void onExit() { log("Thanks for running my Auto Woodcutter!"); } @Override public void onPaint(Graphics2D g) { wcLvl2 = skills.getDynamic(Skill.WOODCUTTING); } } probably have thrown in way more logic than I need to try and figure this out but I just can't get it. i've found a few other issues with the code after posting this, but still couldnt find out what's wrong with the banking. Edited February 18, 2015 by twin 763 Link to comment Share on other sites More sharing options...
Isolate Posted February 18, 2015 Share Posted February 18, 2015 I've had a few hiccups with this script but apaec has helped me through with most of it, basically when, it cuts down trees, and depending on your level will choose between willows, oaks or trees. it all goes well until it goes into the bank, it just stands there cluelessly. probably have thrown in way more logic than I need to try and figure this out but I just can't get it. i've found a few other issues with the code after posting this, but still couldnt find out what's wrong with the banking. case BANK: if (BANK_AREA.contains(myPlayer())) bank.open(); if(bank.isOpen()) { bank.depositAll("Logs,Oak logs, Willow logs"); break; } case BANK_WALK: if(inventory.isFull()) getLocalWalker().walk(3093, 3243); if (BANK_AREA.contains(myPlayer())) break; u wot m8. You're telling it to walk to the bank no matter what You're telling it to open spam open the bank if its in the bank if (BANK_AREA.contains(myPlayer())){ if(bank.isOpen){ //bank stuff }else{ bank.open } } I feel like you just need better checks if(inventory.isFull()){ if(!BANK_AREA.contains(myPlayer())){ getLocalWalker().walk(3093, 3243); }else{ break; } } Link to comment Share on other sites More sharing options...
Twin Posted February 19, 2015 Author Share Posted February 19, 2015 case BANK: if (BANK_AREA.contains(myPlayer())) bank.open(); if(bank.isOpen()) { bank.depositAll("Logs,Oak logs, Willow logs"); break; } case BANK_WALK: if(inventory.isFull()) getLocalWalker().walk(3093, 3243); if (BANK_AREA.contains(myPlayer())) break; u wot m8. You're telling it to walk to the bank no matter what You're telling it to open spam open the bank if its in the bank if (BANK_AREA.contains(myPlayer())){ if(bank.isOpen){ //bank stuff }else{ bank.open } } I feel like you just need better checks if(inventory.isFull()){ if(!BANK_AREA.contains(myPlayer())){ getLocalWalker().walk(3093, 3243); }else{ break; } } Still getting stuck, tried to just get rid of using the bank class and making an entity called booth and having it interact with that, but it still didn't work. I'm assuming its getting stuck within another case in the script and it doesn't know what its supposed to do. I'm stumped with this one. Link to comment Share on other sites More sharing options...
Celeos Posted February 19, 2015 Share Posted February 19, 2015 Your use of "states" is wrong and flawed. Your script is stuck at State.BANK_WALK thus State.BANK won't activate due to full inventory. I have cleaned up your code just a tiny bit however I can already see you will encounter more issues but the following code should be better than what you have at the moment. I recommend you create a "TREE_AREA" variable which it changes based on your woodcutting level. You don't need State.WAIT, just make it return null. private State getState() { if (myPlayer().isUnderAttack()) { return State.UNDER_ATTACK; } else if (inventory.isFull()) { if (BANK_AREA.contains(myPlayer())) { return State.BANK; } else { return State.BANK_WALK; } } else if (!myPlayer().isAnimating()) { if (wcLvl2 >= 30) { return State.CHOPW; } else if (wcLvl2 >= 15) { return State.CHOPO; } else { return State.CHOP; } } return null; } Link to comment Share on other sites More sharing options...
Twin Posted February 19, 2015 Author Share Posted February 19, 2015 Your use of "states" is wrong and flawed. Your script is stuck at State.BANK_WALK thus State.BANK won't activate due to full inventory. I have cleaned up your code just a tiny bit however I can already see you will encounter more issues but the following code should be better than what you have at the moment. I recommend you create a "TREE_AREA" variable which it changes based on your woodcutting level. You don't need State.WAIT, just make it return null. private State getState() { if (myPlayer().isUnderAttack()) { return State.UNDER_ATTACK; } else if (inventory.isFull()) { if (BANK_AREA.contains(myPlayer())) { return State.BANK; } else { return State.BANK_WALK; } } else if (!myPlayer().isAnimating()) { if (wcLvl2 >= 30) { return State.CHOPW; } else if (wcLvl2 >= 15) { return State.CHOPO; } else { return State.CHOP; } } return null; } Didn't think of having a tree area change based on woodcutting level, will defiantly try it out. And I know it's not the best but i'm still trying to learn it, so if I can get something like this to work even if those code is written poorly it will still help me grasp the osbot api better and what not. Also, thanks for cleanig up the states, would have never really thought to change any of those. will defiantly try my best to not have my states just to be a bunch of jumbled of if statements. thanks for the reply! 1 Link to comment Share on other sites More sharing options...
Isolate Posted February 19, 2015 Share Posted February 19, 2015 Your use of "states" is wrong and flawed. Your script is stuck at State.BANK_WALK thus State.BANK won't activate due to full inventory. I have cleaned up your code just a tiny bit however I can already see you will encounter more issues but the following code should be better than what you have at the moment. I recommend you create a "TREE_AREA" variable which it changes based on your woodcutting level. You don't need State.WAIT, just make it return null. private State getState() { if (myPlayer().isUnderAttack()) { return State.UNDER_ATTACK; } else if (inventory.isFull()) { if (BANK_AREA.contains(myPlayer())) { return State.BANK; } else { return State.BANK_WALK; } } else if (!myPlayer().isAnimating()) { if (wcLvl2 >= 30) { return State.CHOPW; } else if (wcLvl2 >= 15) { return State.CHOPO; } else { return State.CHOP; } } return null; } Didn't think of having a tree area change based on woodcutting level, will defiantly try it out. And I know it's not the best but i'm still trying to learn it, so if I can get something like this to work even if those code is written poorly it will still help me grasp the osbot api better and what not. Also, thanks for cleanig up the states, would have never really thought to change any of those. will defiantly try my best to not have my states just to be a bunch of jumbled of if statements. thanks for the reply! Just a quick question. Why does (nearly) everyone choose to do this state based scripting method? Link to comment Share on other sites More sharing options...
Twin Posted February 19, 2015 Author Share Posted February 19, 2015 (edited) Just a quick question. Why does (nearly) everyone choose to do this state based scripting method? Apaec helped me kind of get to know the api and get a start on just general bot scripting, and I used his tea thiever guide to get started so It stemmed form there. What would another way of doing it be? multiple classes? Edited February 19, 2015 by twin 763 Link to comment Share on other sites More sharing options...
Isolate Posted February 19, 2015 Share Posted February 19, 2015 Apaec helped me kind of get to know the api and get a start on just general bot scripting, and I used his tea thiever guide to get started so It stemmed form there. What would another way of doing it be? multiple classes? 0.0 well sure you could do a class based task system for organisational sake. But you can just write it all in the loop Link to comment Share on other sites More sharing options...