Phaibooty Posted January 11, 2017 Share Posted January 11, 2017 Hi, I'm still new to scripting and learning java while scripting.. but here is the code, I was wondering how would I tell the bot to only cut trees that are in the tree area? Even if it is visible, I don't want the bot to click trees that are not in the area? import org.osbot.rs07.api.map.Area; import org.osbot.rs07.api.model.Entity; import org.osbot.rs07.script.Script; import org.osbot.rs07.script.ScriptManifest; import java.awt.*; /** * Created by Phaibooty on 1/11/2017. */ @ScriptManifest(author = "Phaibooty", info = "Chops Logs Only", name ="LogWoodcutter", version = 1, logo ="") public class SimpleWoodcutter extends Script { final String tree_name = "Tree"; final Area BANK_AREA = new Area(3092,3040,3097,3246); final Area Tree_Area = new Area(3103,3226,3114,3233); final int BANK_BOOTH_ID = 23961; @[member=Override] //Code used at Start public void onStart() { log("lets get started!"); log("This is where the code begins."); } @[member=Override] public int onLoop() throws InterruptedException { if(!inventory.isFull()){ //Chop if(Tree_Area.contains(myPlayer())){ Entity tree = objects.closest(tree_name); if (tree != null) { if (tree.isVisible()) { if(!myPlayer().isAnimating()){ if(!myPlayer().isMoving()){ tree.interact("Chop down"); sleep(random(700,800)); } } } else { camera.toEntity(tree); } } } else { getWalking().webWalk(Tree_Area); } }else { //bank if (BANK_AREA.contains(myPlayer())){ Entity bankbooth = objects.closest(BANK_BOOTH_ID); if(bank.isOpen()){ bank.depositAll(); } if (bankbooth != null){ if(bankbooth.isVisible()){ bankbooth.interact("Bank"); sleep(random(700,800)); } } } else { getWalking().webWalk(BANK_AREA); } } return random(200, 300); } @[member=Override] //Code used at End public void onExit(){ log("Thanks for using my woodcutter!"); } @[member=Override] public void onPaint(Graphics2D g) { } } Code is really messy and I'm still confused... but hopefully some guidance will help. Quote Link to comment Share on other sites More sharing options...
Precise Posted January 11, 2017 Share Posted January 11, 2017 RS2Object tree = getObjects().closest(AREA_HERE, TREE_NAME HERE); check out the api here for more options: http://osbot.org/api/org/osbot/rs07/api/EntityAPI.html 2 Quote Link to comment Share on other sites More sharing options...
Solution Posted January 11, 2017 Share Posted January 11, 2017 Isn't there an area#contains(Entity entity)? If (Tree_area.contains(tree)) {} or smth Quote Link to comment Share on other sites More sharing options...
Precise Posted January 11, 2017 Share Posted January 11, 2017 Isn't there an area#contains(Entity entity)? If (Tree_area.contains(tree)) { } or smth yes there is a methods for it, but then it will do nothing if the entity is not in the area. you want to filter out the ones like i have above 1 Quote Link to comment Share on other sites More sharing options...
Phaibooty Posted January 11, 2017 Author Share Posted January 11, 2017 Isn't there an area#contains(Entity entity)? If (Tree_area.contains(tree)) { } or smth Thank you! Gave this a try, and works beautifully. Still a little confused on where I should put it, but I guess that just comes with more java knowledge lol. I put it right before tree.isVisible.. @[member=Override] public int onLoop() throws InterruptedException { if(!inventory.isFull()){ //Chop if(Tree_Area.contains(myPlayer())){ Entity tree = objects.closest(tree_name); if (tree != null) { if (Tree_Area.contains(tree)) if (tree.isVisible()) { if(!myPlayer().isAnimating()){ if(!myPlayer().isMoving()){ tree.interact("Chop down"); sleep(random(700,800)); } } } else { camera.toEntity(tree); } } RS2Object tree = getObjects().closest(AREA_HERE, TREE_NAME HERE); check out the api here for more options: http://osbot.org/api/org/osbot/rs07/api/EntityAPI.html shit, explains why it stops chopping after 1 tree. lmao Still a little confused on how to use that line of code but I'll keep reading. Thank you! Quote Link to comment Share on other sites More sharing options...
Precise Posted January 11, 2017 Share Posted January 11, 2017 (edited) Thank you! Gave this a try, and works beautifully. Still a little confused on where I should put it, but I guess that just comes with more java knowledge lol. I put it right before tree.isVisible.. @[member='Override'] public int onLoop() throws InterruptedException { if(!inventory.isFull()){ //Chop if(Tree_Area.contains(myPlayer())){ Entity tree = objects.closest(tree_name); if (tree != null) { if (Tree_Area.contains(tree)) if (tree.isVisible()) { if(!myPlayer().isAnimating()){ if(!myPlayer().isMoving()){ tree.interact("Chop down"); sleep(random(700,800)); } } } else { camera.toEntity(tree); } } shit, explains why it stops chopping after 1 tree. lmao Still a little confused on how to use that line of code but I'll keep reading. Thank you! here is what it could look like: if(!getInventory().isFull()) { //Chop if(!myPlayer().isAnimating() && !myPlayer().isMoving()) { if(TREE_AREA.contains(myPlayer())) { Entity tree = getObjects().closest(AREA_HERE, TREE_NAME); if (tree != null) { if(tree.interact("CHOP??")) add sleep here } } } } Edited January 11, 2017 by Precise 2 Quote Link to comment Share on other sites More sharing options...
Phaibooty Posted January 11, 2017 Author Share Posted January 11, 2017 here is what it could look like: if(!getInventory().isFull()) { //Chop if(!myPlayer().isAnimating() && !myPlayer().isMoving()) { if(TREE_AREA.contains(myPlayer())) { Entity tree = getObjects().closest(AREA_HERE, TREE_NAME); if (tree != null) { if(tree.interact("CHOP??")) add sleep here } } } } Thank you! I appreciate the help. It works beautifully now. Going to do more studying lmao. thanks again 2 Quote Link to comment Share on other sites More sharing options...
Sphiinx Posted January 14, 2017 Share Posted January 14, 2017 Thank you! I appreciate the help. It works beautifully now. Going to do more studying lmao. thanks again If you're curious to learn more about Java specifically to grow your knowledge, I would recommend these two sources. They're fantastic sources! Source one: Source two: http://mooc.fi/english.html Quote Link to comment Share on other sites More sharing options...
progamerz Posted January 14, 2017 Share Posted January 14, 2017 if (BANK_AREA.contains(myPlayer())){ Entity bankbooth = objects.closest(BANK_BOOTH_ID); if(bank.isOpen()){ bank.depositAll(); } if (bankbooth != null){ if(bankbooth.isVisible()){ bankbooth.interact("Bank"); sleep(random(700,800)); } } Now there is no need for Entity bankbooth = objects.closest(BANK_BOOTH_ID); Instead you can simply use the Bank(Api) to open by using: getBank().open(); And the second thing is that the logic is wrong instead you can do: if (BANK_AREA.contains(myPlayer())){ if(bank.isOpen()){ // If bank is opened deposit all bank.depositAll(); } else { // If bank is not opened open it getBank().open(); new ConditionalSleep(5000) { // Conditional Sleep 5000ms untill bank is open. @[member=Override] public boolean condition() throws InterruptedException { return getBank().isOpen(); } }.sleep(); } Quote Link to comment Share on other sites More sharing options...
Phaibooty Posted January 18, 2017 Author Share Posted January 18, 2017 if (BANK_AREA.contains(myPlayer())){ Entity bankbooth = objects.closest(BANK_BOOTH_ID); if(bank.isOpen()){ bank.depositAll(); } if (bankbooth != null){ if(bankbooth.isVisible()){ bankbooth.interact("Bank"); sleep(random(700,800)); } } Now there is no need for Entity bankbooth = objects.closest(BANK_BOOTH_ID); Instead you can simply use the Bank(Api) to open by using: getBank().open(); And the second thing is that the logic is wrong instead you can do: if (BANK_AREA.contains(myPlayer())){ if(bank.isOpen()){ // If bank is opened deposit all bank.depositAll(); } else { // If bank is not opened open it getBank().open(); new ConditionalSleep(5000) { // Conditional Sleep 5000ms untill bank is open. @[member='Override'] public boolean condition() throws InterruptedException { return getBank().isOpen(); } }.sleep(); } Wow. Beautiful. Thank you for the help. Quote Link to comment Share on other sites More sharing options...