Imthabawse Posted February 2, 2019 Share Posted February 2, 2019 package oaklarders; import org.osbot.rs07.api.ui.RS2Widget; import org.osbot.rs07.script.Script; import org.osbot.rs07.script.ScriptManifest; // Start script lvl 33 Construction @ScriptManifest(author = "Imthabawse", info = "Oaklarder Builder", logo = "", name = "Oaklarders", version = 0) public class Oaklarders extends Script { @Override public void onStart() { log("Sit back and relax"); } @Override public int onLoop() throws InterruptedException { objects.closest("Larder space").interact("Build"); { sleep(1000); } RS2Widget widget = widgets.get(458, 5, 4); if(widget != null) { widget.interact(); { sleep(2000); } objects.closest("Larder").interact("Remove"); sleep(1000); } RS2Widget removeMenu = widgets.get(219, 1, 1); if(removeMenu != null) { removeMenu.interact(); { sleep(1000); } if(!inventory.contains("Oak plank")) { RS2Widget settings = widgets.get(548, 35); if(settings != null) { settings.interact(); { sleep(200); } RS2Widget house = widgets.get(261, 99); if(house != null) { house.interact(); { sleep(200); } RS2Widget servant = widgets.get(370, 19, 0); if(servant != null) { servant.interact(); { sleep(200); } RS2Widget unote = widgets.get(219, 1, 1); if(unote != null) { unote.interact(); { sleep(10000); } } } } } } } return(200); } @Override public void onExit() { log("Thank's for using Oaklardersv1"); } } // Make bot build and remove larders // Make bot interact with butler to unote planks // Make bot call servant if needed // Add humanlike behavior sleeps etc So everything's good untill I run out of planks and it trys to build larders over and over again. I know sleeps arnt the best method and should be using ConditionalSleeps but still a noob to this shit lol. If anyone can help give me an idea on how to break each task up id greatly appreciate it. Quote Link to comment Share on other sites More sharing options...
TutIslander Posted February 2, 2019 Share Posted February 2, 2019 By any chance does it leave you with one or two oak planks in invent when it's finished building as many as it can? Quote Link to comment Share on other sites More sharing options...
Mr_MilkysButler Posted February 2, 2019 Share Posted February 2, 2019 Have a check if your inventory even contains oak planks. Quote Link to comment Share on other sites More sharing options...
Spider Scripts Posted February 2, 2019 Share Posted February 2, 2019 maybe just try to use if and else statements so if(has planks) build larders else if(condition 2) remove larders else if(condition 3) interact with butler Quote Link to comment Share on other sites More sharing options...
Charlotte Posted February 2, 2019 Share Posted February 2, 2019 You can do several checks, if more than 'x' oak planks, interact. Quote Link to comment Share on other sites More sharing options...
Imthabawse Posted February 2, 2019 Author Share Posted February 2, 2019 5 minutes ago, TutIslander said: By any chance does it leave you with one or two oak planks in invent when it's finished building as many as it can? Well for example ill have 20 planks in inv at start of script. Then it builds two larders (16x planks) and i still have 4 left. Then it continuously try's to build over and over. Quote Link to comment Share on other sites More sharing options...
ItPoke Posted February 2, 2019 Share Posted February 2, 2019 (edited) Here is what you should look into, the code has not been tested so just use it as a guide package oaklarders; import org.osbot.rs07.api.ui.RS2Widget; import org.osbot.rs07.script.Script; import org.osbot.rs07.script.ScriptManifest; // Start script lvl 33 Construction @ScriptManifest(author = "Imthabawse", info = "Oaklarder Builder", logo = "", name = "Oaklarders", version = 0) public class Oaklarders extends Script { @Override public void onStart() { log("Sit back and relax"); } @Override public int onLoop() throws InterruptedException { /* OLD objects.closest("Larder space").interact("Build"); { sleep(1000); } */ if (!objects.closest("Larder space").interact("Build") { return; // If the interaction fails we return and it will try again. } else { // Do a conditional sleep here to make sure we dont spam interact. // The conditional sleep should check if the widget exists. new ConditionalSleep(3000) { @Override public boolean condition() { RS2Widget widget = widgets.get(458, 5, 4); return widget.isVisiable(); } }.sleep(); if (widget == null || !widget.interact()) { return; // Here we return so if the widget is null or not shown and the 3000 ms has passed, we try again. } } // Repeat here with the remove function if(!inventory.contains("Oak plank")) { RS2Widget settings = widgets.get(548, 35); // Look at the api to see if you can find the settings in the tab to open it. if(settings == null) { // Here we changed it from not null to is equial to null so we dont wrap everything into this if statment :) return; // Then we can just return instead. } settings.interact(); { sleep(200); // look above to see what to do instead of using sleeps like this. } RS2Widget house = widgets.get(261, 99); if(house != null) { house.interact(); { sleep(200); // look above to see what to do instead of using sleeps like this. } RS2Widget servant = widgets.get(370, 19, 0); if(servant != null) { servant.interact(); { sleep(200); // look above to see what to do instead of using sleeps like this. } RS2Widget unote = widgets.get(219, 1, 1); if(unote != null) { unote.interact(); { sleep(10000); // look above to see what to do instead of using sleeps like this. } } } } } } return(200); } @Override public void onExit() { log("Thank's for using Oaklardersv1"); } } // Make bot build and remove larders // Make bot interact with butler to unote planks // Make bot call servant if needed // Add humanlike behavior sleeps etc Thats just my quick gist of what you can improve, best of luck! Edited February 2, 2019 by ItPoke Refactored a tiny bit 1 Quote Link to comment Share on other sites More sharing options...
FuryShark Posted February 2, 2019 Share Posted February 2, 2019 (edited) 6 minutes ago, Imthabawse said: Well for example ill have 20 planks in inv at start of script. Then it builds two larders (16x planks) and i still have 4 left. Then it continuously try's to build over and over. if getInvetory().getAmount(plank) > 5 Edited February 2, 2019 by FuryShark 1 Quote Link to comment Share on other sites More sharing options...
TutIslander Posted February 2, 2019 Share Posted February 2, 2019 @Imthabawse thought so, your code is just checking that you have 1 plank in invent that's why it'll keep trying to build. Furyshark has pointed you in the right direction. Quote Link to comment Share on other sites More sharing options...
Imthabawse Posted February 2, 2019 Author Share Posted February 2, 2019 Thanks you all for fast replies appreciate it! 1 Quote Link to comment Share on other sites More sharing options...
Imthabawse Posted February 2, 2019 Author Share Posted February 2, 2019 So I added @ItPoke's suggestion and now I'm getting multiple errors If anyone has any ideas where I went wrong (I'm sure most of you do you're all very knowledgeable) Any help would be greatly appreciated! It's a long stretched out mess of a code and I'm sure it could be shortened significantly but I R Nub so don't h8 package oaklarders; import org.osbot.rs07.api.ui.RS2Widget; import org.osbot.rs07.script.Script; import org.osbot.rs07.script.ScriptManifest; import org.osbot.rs07.utility.ConditionalSleep; // Start script lvl 33 Construction @ScriptManifest(author = "Imthabawse", info = "Oaklarder Builder", logo = "", name = "Oaklarders", version = 0) public class Oaklarders extends Script { @Override public void onStart() { log("Sit back and relax"); } @Override public int onLoop() throws InterruptedException { if (!objects.closest("Larder space").interact("Build")) { return; } else { new ConditionalSleep(3000) { @Override public boolean condition() { RS2Widget widget = widgets.get(458, 5, 4); return widget.isVisible(); } }.sleep(); if (widget == null || !widget.interact()) { return; } } if (!objects.closest("Larder").interact("Remove")) { return; } else { new ConditionalSleep(3000) { @Override public boolean condition() { RS2Widget widget = widgets.get(219, 1, 1); return widget.isVisible(); } }.sleep(); if (widget == null || !widget.interact()) { return; } if(getInventory().getAmount("Oak plank") > 4) { RS2Widget settings = widgets.get(548, 35); if(settings == null) { return; } settings.interact(); { new ConditionalSleep(3000) { @Override public boolean condition() { RS2Widget widget = widgets.get(548, 35); return widget.isVisible(); } }.sleep(); if (widget == null || !widget.interact()) { return; } RS2Widget house = widgets.get(261, 99); if(house != null) { house.interact(); { new ConditionalSleep(3000) { @Override public boolean condition() { RS2Widget widget = widgets.get(261, 99); return widget.isVisible(); } }.sleep(); if (widget == null || !widget.interact()) { return; } RS2Widget servant = widgets.get(370, 19, 0); if(servant != null) { servant.interact(); { new ConditionalSleep(3000) { @Override public boolean condition() { RS2Widget widget = widgets.get(370, 19, 0); return widget.isVisible(); } }.sleep(); if (widget == null || !widget.interact()) { return; } RS2Widget unote = widgets.get(219, 1, 1); if(unote != null) { unote.interact(); { new ConditionalSleep(3000) { @Override public boolean condition() { RS2Widget widget = widgets.get(219, 1, 1); return widget.isVisible(); } }.sleep(); if (widget == null || !widget.interact()) { return; } RS2Widget inventory = widgets.get(548, 51); if(inventory != null) { inventory.interact(); { new ConditionalSleep(3000) { @Override public boolean condition() { RS2Widget widget = widgets.get(548, 51); return widget.isVisible(); } }.sleep(); if (widget == null || !widget.interact()) { return; } } } } } } } } } } return(500); @Override public void onExit() { log("Thank's for using Oaklardersv1"); } } // Make bot build and remove larders // Make bot interact with butler to unote planks // Make bot call servant if needed // Add humanlike behavior sleeps etc Quote Link to comment Share on other sites More sharing options...
Mr_MilkysButler Posted February 2, 2019 Share Posted February 2, 2019 Can you provide your log? Quote Link to comment Share on other sites More sharing options...
ItPoke Posted February 2, 2019 Share Posted February 2, 2019 Format the code better and make sure you don't have too many } 1 Quote Link to comment Share on other sites More sharing options...
Imthabawse Posted February 2, 2019 Author Share Posted February 2, 2019 (edited) 59 minutes ago, ItPoke said: Format the code better and make sure you don't have too many } if (widget == null || !widget.interact()) { ^This was one of my first errors any ideas? Also with return; I get error: "This method must return a result of type int" So could I just make "return 0;" ? Edited February 2, 2019 by Imthabawse Quote Link to comment Share on other sites More sharing options...
ItPoke Posted February 2, 2019 Share Posted February 2, 2019 35 minutes ago, Imthabawse said: if (widget == null || !widget.interact()) { ^This was one of my first errors any ideas? Also with return; I get error: "This method must return a result of type int" So could I just make "return 0;" ? I just told you to clean the code so you can make sure that you have your brackets correct.... if (widget == null || !widget.interact()) { return; } // <- Why is there a curly bracket here?! } Quote Link to comment Share on other sites More sharing options...