Imthabawse Posted April 25, 2019 Share Posted April 25, 2019 (edited) Re-made an Oak-door's script that I whipped up awhile back. Looking for feedback on the code of ways I can improve it. Still need to add an option to stop script either after bank doesn't contain Oak planks or based on message that Butler says when you run out of Oak planks to build. Would also like to add random checking of EXP widget when you gain EXP in skill. Id also like to add that when I write a script I don't make it with the intentions of running it and leaving it. I baby sit my bot whilst watching Youtube/pornhub(jk) or whatever I may be doing. Not saying you can't walk away for a bit while scripts running but wouldn't let it run for hours un-attended. 74-83 Construction achieved so far Features - Build's and Remove's Oak doors in player owned basement - Interacts with Butler to fetch planks from bank (Must be Demon butler) - Moves mouse outside screen while waiting on Butler to return - Basic informative paint To run script - Have client on "Fixed mode" - Have Oak planks in bank - Interact with Butler prior to running and have him set to fetch 20x Oak planks from bank - Saw, Hammer, Nails in inventory - Be in player owned basement (Build mode ON) - Butler in basement with you - level 74 Construction (Obviously) - Have Servant's money bag with at least 100k in it (Demon-butler takes 10k every 8 trips, keep this in mind) Code Reveal hidden contents import org.osbot.rs07.api.model.Entity; import org.osbot.rs07.api.ui.RS2Widget; import org.osbot.rs07.api.ui.Skill; import org.osbot.rs07.script.Script; import org.osbot.rs07.script.ScriptManifest; import org.osbot.rs07.utility.ConditionalSleep; import java.awt.*; import java.util.concurrent.TimeUnit; @ScriptManifest(author = "Imthabawse", info = "Builds/Removes Oak Doors, Calls Butler to re-stock", logo = "", name = "OakDoorsPro", version = 1) public class OakDoorsPro extends Script { private long timeBegan; private long timeRan; private int beginningXp; private int currentXp; private int xpGained; private int currentLevel; private int beginningLevel; private int levelsGained; @Override public void onStart() { timeBegan = System.currentTimeMillis(); beginningXp = skills.getExperience(Skill.CONSTRUCTION); beginningLevel = skills.getStatic(Skill.CONSTRUCTION); } @Override public void onPaint(Graphics2D g) { g.setColor(Color.GREEN); timeRan = System.currentTimeMillis() - this.timeBegan; g.drawString(ft(timeRan), 12, 235); currentXp = skills.getExperience(Skill.CONSTRUCTION); xpGained = currentXp - beginningXp; g.drawString("Exp Gained: " + xpGained, 12, 255); currentLevel = skills.getStatic(Skill.CONSTRUCTION); levelsGained = currentLevel - beginningLevel; g.drawString("Start Level: " + beginningLevel, 12,275); g.drawString("Current Level: " + currentLevel, 12,295); g.drawString("Levels Gained: " + levelsGained, 12, 315); } private String ft(long duration) { String res = ""; long days = TimeUnit.MILLISECONDS.toDays(duration); long hours = TimeUnit.MILLISECONDS.toHours(duration) - TimeUnit.DAYS.toHours(TimeUnit.MILLISECONDS.toDays(duration)); long minutes = TimeUnit.MILLISECONDS.toMinutes(duration) - TimeUnit.HOURS.toMinutes(TimeUnit.MILLISECONDS .toHours(duration)); long seconds = TimeUnit.MILLISECONDS.toSeconds(duration) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS .toMinutes(duration)); if (days == 0) { res = (hours + ":" + minutes + ":" + seconds); } else { res = (days + ":" + hours + ":" + minutes + ":" + seconds); } return res; } @Override public int onLoop() throws InterruptedException { if (canBuildDoor()) { buildRemove(); } else { callButler(); missClickedDoor(); } return random(350, 500); } private void buildRemove() throws InterruptedException { RS2Widget oakDoor = getWidgets().get(458, 4, 4); RS2Widget reallyRemove = getWidgets().getWidgetContainingText("Yes"); Entity door = getObjects().closest("Door"); Entity doorSpace = getObjects().closest("Door space"); if (!myPlayer().isAnimating() && !myPlayer().isMoving() && oakDoor == null && door == null && buildDoor()) { log("Interacting with door space.."); new ConditionalSleep(5000) { @Override public boolean condition() { return oakDoorWidget(); } }.sleep(); } else if (oakDoor != null && oakDoor.interact()) { sleep(random(455, 555)); doorSpace.hover(); log("Building door.."); new ConditionalSleep(5000) { @Override public boolean condition() { return !myPlayer().isAnimating() && doorExists(); } }.sleep(); } else if (doorExists() && reallyRemove == null && removeDoor()) { log("Interacting with door.."); new ConditionalSleep(5000) { @Override public boolean condition() { return removeDoorWidget(); } }.sleep(); } else if (removeDoorWidget() && reallyRemove != null && reallyRemove.interact()) { log("Removing door.."); new ConditionalSleep(5000) { @Override public boolean condition() { return !myPlayer().isAnimating() && doorSpaceExists(); } }.sleep(); } } private void callButler() throws InterruptedException { RS2Widget yesFetch = getWidgets().getWidgetContainingText("Fetch from bank: 20 x Oak plank"); Entity door = getObjects().closest("Door"); RS2Widget reallyRemove = getWidgets().getWidgetContainingText("Yes"); Entity closeThaDoor = getObjects().closestThatContains("Close"); if (getInventory().getAmount("Oak plank") < 10 && door == null && yesFetch == null && talkToButler()) { log("Talking to Butler.."); new ConditionalSleep(5000) { @Override public boolean condition() { return fetchPlanksWidget(); } }.sleep(); } else if (fetchPlanksWidget() && yesFetch != null && yesFetch.interact()) { log("Fetching planks.."); sleep(random(650, 945)); getMouse().moveOutsideScreen(); new ConditionalSleep(7200) { @Override public boolean condition() { return getInventory().getAmount("Oak plank") >= 10; } }.sleep(); } else { if (doorExists() && reallyRemove == null && closeThaDoor == null && removeDoor()) { new ConditionalSleep(5000) { @Override public boolean condition() { return removeDoorWidget(); } }.sleep(); } else if (removeDoorWidget() && reallyRemove != null && reallyRemove.interact()) { new ConditionalSleep(5000) { @Override public boolean condition() { return myPlayer().isAnimating(); } }.sleep(); } else if (missClickedDoor() && closeThaDoor != null && closeThaDoor.interact("Close")) { sleep(random(150, 200)); log("Oops miss-clicked.. closing door.."); } } } private boolean missClickedDoor() { return getObjects().closestThatContains( "Close") != null; } private boolean canBuildDoor() { return getInventory().getAmount("Oak plank") >= 10; } private boolean buildDoor() { return getObjects().closest("Door space").interact("Build"); } private boolean oakDoorWidget() { return getWidgets().get(458, 4, 4) != null; } private boolean removeDoor() { return getObjects().closest("Door").interact("Remove"); } private boolean removeDoorWidget() { return getWidgets().getWidgetContainingText("Yes") != null; } private boolean talkToButler() { return getNpcs().closest("Demon butler").interact("Talk-to"); } private boolean fetchPlanksWidget() { return getWidgets().getWidgetContainingText("Fetch from bank: 20 x Oak plank") != null; } private boolean doorExists() { Entity oakDoor = getObjects().closest("Door"); return oakDoor != null; } private boolean doorSpaceExists() { Entity doorSpace = getObjects().closest("Door space"); return doorSpace != null; } } Edited April 28, 2019 by Imthabawse Edited code 1 Quote Link to comment Share on other sites More sharing options...
Imthabawse Posted April 25, 2019 Author Share Posted April 25, 2019 Thanks for the like @Chris is there anything you think could be better? Quote Link to comment Share on other sites More sharing options...
dreameo Posted April 25, 2019 Share Posted April 25, 2019 You haven't been using conditionals in the right way at all. // WRONG talkToButler(); new ConditionalSleep(5000) { @Override public boolean condition() { return fetchPlanksWidget(); } }.sleep(); // RIGHT if(talkToButler()){ new ConditionalSleep(5000) { @Override public boolean condition() { return fetchPlanksWidget(); } }.sleep(); } The conditonalSleep should be triggered if the "talkToButler" action is true. 1 Quote Link to comment Share on other sites More sharing options...
Imthabawse Posted April 25, 2019 Author Share Posted April 25, 2019 (edited) On 4/25/2019 at 7:06 PM, dreameo said: You haven't been using conditionals in the right way at all. // WRONG talkToButler(); new ConditionalSleep(5000) { @Override public boolean condition() { return fetchPlanksWidget(); } }.sleep(); // RIGHT if(talkToButler()){ new ConditionalSleep(5000) { @Override public boolean condition() { return fetchPlanksWidget(); } }.sleep(); } The conditonalSleep should be triggered if the "talkToButler" action is true. Expand Thank you @dreameo so all of my Conditionals are wrong? This is my first time using booleans like this so I expected mistakes lol. Appreciate your feedback nonetheless! * Edited above code Edited April 25, 2019 by Imthabawse Quote Link to comment Share on other sites More sharing options...
dreameo Posted April 25, 2019 Share Posted April 25, 2019 On 4/25/2019 at 7:51 PM, Imthabawse said: Thank you @dreameo so all of my Conditionals are wrong? This is my first time using booleans like this so I expected mistakes lol. Appreciate your feedback nonetheless! * Edited above code Expand Notice how most of the actions are booleans? They return true if the action occured and false if the action failed. You only want to do a conditional sleep if an action occurs. So for example if you interact and fail, you will wait for 5 seconds because of the timeout. On the other hand, if you use the conditionals right, if you fail an interact, you wont wait those 5 seconds. 1 Quote Link to comment Share on other sites More sharing options...
Imthabawse Posted April 25, 2019 Author Share Posted April 25, 2019 @dreameo So would something like this work correctly? The script works okay but not sure if my code is being executed in the right way. What the below code means to me is if my inventory has less than 10 planks and door doesnt exist and yes widget doesnt exist then we talk to butler? If talked to butler sleep 5 seconds or until fetch widget exists? Or is this skipping all the other checks and just talking to butler? Appreciate all your help if (getInventory().getAmount("Oak plank") < 10 && door == null && yesFetch == null && talkToButler()) { log("Talking to Butler.."); new ConditionalSleep(5000) { @Override public boolean condition() { return fetchPlanksWidget(); Quote Link to comment Share on other sites More sharing options...
Imthabawse Posted April 27, 2019 Author Share Posted April 27, 2019 Updated code would appreciate feedback Quote Link to comment Share on other sites More sharing options...