Imthabawse Posted March 16, 2019 Share Posted March 16, 2019 (edited) Started off with a simple Oak larder project that gained me quite a few levels. Now I've moved onto the next step for quicker exp.. Oak doors. Here's the code I have thus far, it's about as broken as my Oak larders code.. but gets the job done. If you're looking for some easy levels C&P the code below and use at your own free will. Code: Edited * import org.osbot.rs07.api.map.Area; import org.osbot.rs07.api.model.NPC; import org.osbot.rs07.api.model.RS2Object; 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; @ScriptManifest(name = "Xpert Doors", logo = "", version = 1, author = "Imthabawse", info = "Build and remove oak doors, call butler when out of planks, repeat.") public class xpertdoors extends Script { private Area BUILDAREA = new Area(10139, 462, 10140, 462); private void BUILDDOOR() throws InterruptedException { RS2Object doorSpace = getObjects().closest("Door space"); if (doorSpace != null) { if (getInventory().getAmount("Oak plank") >= 10) { if (BUILDAREA.contains(doorSpace)) { doorSpace.interact("Build"); log("Interacting with Door space.."); sleep(random(1200, 1400)); RS2Widget oakDoor = getWidgets().get(458, 4, 4); if (oakDoor != null) { oakDoor.interact("Build"); log("Building Door.."); new ConditionalSleep(2000) { @Override public boolean condition() { return doorSpace.exists() && !myPlayer().isAnimating(); } }.sleep(); } } } } } private void REMOVEDOOR() throws InterruptedException { RS2Object oakDoor = getObjects().closest("Door"); if (oakDoor != null) { if (BUILDAREA.contains(oakDoor)) { oakDoor.interact("Remove"); log("Interacting with Door.."); sleep(random(1200, 1400)); RS2Widget reallyRemove = getWidgets().get(219, 1, 1); if (reallyRemove != null) { reallyRemove.interact(); log("Removing Door.."); new ConditionalSleep(2000) { @Override public boolean condition() { return oakDoor.exists() && !myPlayer().isAnimating(); } }.sleep(); } } } } private void DEMONBUTLER() throws InterruptedException { NPC demonButler = getNpcs().closest("Demon butler"); if (demonButler != null) { if (getInventory().getAmount("Oak plank") < 10) { demonButler.interact("Talk-to"); log("Interacting with Demon butler.."); sleep(random(1200, 1400)); RS2Widget fetchPlanks = getWidgets().get(219, 1, 1); if (fetchPlanks != null) { fetchPlanks.interact(); log("Waiting on planks.. Please wait."); sleep(random(600, 900)); getMouse().moveOutsideScreen(); new ConditionalSleep(7000) { @Override public boolean condition() { return getInventory().getAmount("Oak plank") > 10; } }.sleep(); } } } } @Override public int onLoop() throws InterruptedException { sleep(random(300,600)); if (!BUILDAREA.contains(myPlayer())) { getCamera().toPosition(BUILDAREA.getRandomPosition()); log("Not in build area.. moving there."); getWalking().walk(BUILDAREA); } else if(BUILDAREA.contains(myPlayer())) { log("We are in Build area.. "); BUILDDOOR(); REMOVEDOOR(); DEMONBUTLER(); } return 1500; } } I would love to hear feedback on how I can improve the script! Edited March 17, 2019 by Imthabawse Quote Link to comment Share on other sites More sharing options...
d0zza Posted March 16, 2019 Share Posted March 16, 2019 Some things I can see immediately are: Any API interact() call will return a boolean. This will be true when the interaction successfully occurred and false if it failed, combine this with if statements to make sure you're not sleeping when the interaction call failed. Don't use random sleeps, you can definitely use a conditional sleep when waiting for a widget to appear. You don't want to use static IDs to grab widgets as these can change a lot, instead use the widget debugger to find something to filter the widget on, for example the text the widget contains. 2 Quote Link to comment Share on other sites More sharing options...
Imthabawse Posted March 16, 2019 Author Share Posted March 16, 2019 @d0zza Thanks for the feedback Quote Link to comment Share on other sites More sharing options...
Mordred Posted March 16, 2019 Share Posted March 16, 2019 sexy Quote Link to comment Share on other sites More sharing options...
Imthabawse Posted March 16, 2019 Author Share Posted March 16, 2019 Edited above code with added area. Seems to be working quite well still needs better sleeps but other than that pretty smooth. Quote Link to comment Share on other sites More sharing options...
HunterRS Posted March 16, 2019 Share Posted March 16, 2019 (edited) Just some little quick advice on top of what dozza wrote, Reusing code is a great thing, my advice though when rewriting a script is to maximazie your learning by only using your old code as a guide line for areas, method etc. Have your code open on one side and on the other start the rewrite, we have all done this at one point when we said "who is the fucking dumbass who wrote this, ohh wait me", in my opinion this is the goal of rewriting a script because you can improve a lot when learning from your old mistakes. Just my opinion. Great improvement on the script though, keep it up. (Also it does a apply a bit less if your goal isn't to improve but to get a working product as fast as possible) Edited March 16, 2019 by HunterRS 1 Quote Link to comment Share on other sites More sharing options...
Imthabawse Posted March 16, 2019 Author Share Posted March 16, 2019 @HunterRS Thanks for the feedback! I'm always trying to improve my scripts a little at a time with trial and error messing around with the API. Still learning Java as I go these are just fun projects for me that I like to share with the community to maybe learn something from them and also learn from you the community. 1 Quote Link to comment Share on other sites More sharing options...
ProjectPact Posted March 16, 2019 Share Posted March 16, 2019 Didn’t look in detail by any means, by after scanning over it, I found that you are constantly re-creating objects within methods that should only be created once. Hope this helps you get your script to the next level! 1 Quote Link to comment Share on other sites More sharing options...
Imthabawse Posted March 16, 2019 Author Share Posted March 16, 2019 @ProjectPact Thanks for the feedback! Will look into this Quote Link to comment Share on other sites More sharing options...
Imthabawse Posted March 17, 2019 Author Share Posted March 17, 2019 Update on Oak doors: Tweaked code a bit seems to be working fairly well. Still dicking around with Conditional Sleeps and a few other things but going to edit above code so be sure to check it out and tell me how bad it still is None the less many levels have been gained and been a fun project thus far. Quote Link to comment Share on other sites More sharing options...