MasonStorm Posted December 17, 2019 Share Posted December 17, 2019 (edited) My first ever script, if you don't count the goblin killer @Chris taught me to make, or the tea thiever @Apaec taught me. Big shoutout to both. Mainly posting this to get some feedback. I took note of people saying that every iteration of onloop should execute one action, use conditional sleeps and limit regular sleeps. But I'm having issues of some actions happening very fast. I know you could adjust the return of onloop, but that might make other actions too slow. Would adding regular non conditional sleeps in those cases be fine? I did add 2-3, but I think I need more. Been running the script for around 8 hours with several trips to the G.E. Has not gotten stuck yet. Features: Smelts bronze bars and banks in Edgeville Walks to the G.E and restocks copper and tin ore Requirements: Bank should contain either coins or bronze bars (which will be sold to obtain coins) for restocking The amount of copper ore and tin ore in your bank should be equal. Don't think I added a check for what to do when one of them is below x14 and the other is not. Guess the script will just stand there You can probably start the script pretty much anywhere since the walking relies on the webwalk method, although I would advice you to start it in the GE - Edgeville general area. Download Source code: import org.osbot.rs07.api.Bank; import org.osbot.rs07.api.GrandExchange; import org.osbot.rs07.api.map.Area; import org.osbot.rs07.api.map.constants.Banks; 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; import java.awt.*; @ScriptManifest(name = "Bronze Smelter", logo = "", version = 1, author = "Mason", info = "Smelts bronze bars at Edgeville and restocks ores.") public class Main extends Script { Area furnaceRoom = new Area(3105, 3501, 3110, 3496); long copperOre = 100; long tinOre = 100; long bronzeBar = 100; long coins = 100; @Override public void onStart() throws InterruptedException { log("Let's smelt some bronze bars"); } @Override public int onLoop() throws InterruptedException { NPC bank = getNpcs().closest("Banker"); NPC clerk = getNpcs().closest("Grand Exchange Clerk"); RS2Object furnace = getObjects().closest("Furnace"); RS2Widget bronzeWidget = getWidgets().get(270,14, 29); if ((copperOre >= 14) && (tinOre >= 14)) { if ((inventory.isEmpty() || inventory.getAmount("Bronze bar") == 14) && !Banks.EDGEVILLE.contains(myPlayer())) { getWalking().webWalk(Banks.EDGEVILLE); new ConditionalSleep(20000) { @Override public boolean condition() throws InterruptedException { return Banks.EDGEVILLE.contains(myPlayer()); } }.sleep(); } else if (Banks.EDGEVILLE.contains(myPlayer()) && bank != null && !bank.isVisible()) { getCamera().toEntity(bank); } else if ((inventory.isEmpty() || (inventory.getAmount("Bronze bar") == 14) || ((inventory.getAmount("Copper ore") == 14 || inventory.getAmount("Tin ore") == 14) && (inventory.getAmount("Copper ore") != 14 || inventory.getAmount("Tin ore") != 14))) && Banks.EDGEVILLE.contains(myPlayer()) && bank != null && bank.isVisible() && !getBank().isOpen()) { bank.interact("Bank"); new ConditionalSleep(5000) { @Override public boolean condition() throws InterruptedException { return getBank().isOpen(); } }.sleep(); } else if (inventory.isEmpty() && Banks.EDGEVILLE.contains(myPlayer()) && bank != null && getBank().isOpen()) { if ((getBank().getAmount("Copper ore") >= 14) && (getBank().getAmount("Tin ore") >= 14)) { getBank().withdraw("Copper ore", 14); new ConditionalSleep(3000) { @Override public boolean condition() throws InterruptedException { return inventory.contains("Copper ore"); } }.sleep(); } else { copperOre = getBank().getAmount("Copper ore"); tinOre = getBank().getAmount("Tin ore"); bronzeBar = getBank().getAmount("Bronze bar"); coins = getBank().getAmount("Coins"); } } else if ((inventory.getAmount("Copper ore") == 14) && !inventory.contains("Tin ore") && Banks.EDGEVILLE.contains(myPlayer()) && bank != null && getBank().isOpen()) { getBank().withdraw("Tin ore", 14); new ConditionalSleep(3000) { @Override public boolean condition() throws InterruptedException { return inventory.contains("Tin ore"); } }.sleep(); } else if ((inventory.getAmount("Bronze bar") == 14) && Banks.EDGEVILLE.contains(myPlayer()) && bank != null && getBank().isOpen()) { getBank().depositAll("Bronze bar"); new ConditionalSleep(3000) { @Override public boolean condition() throws InterruptedException { return !inventory.contains("Bronze bar"); } }.sleep(); } else if (inventory.contains("Copper ore", "Tin ore") && !furnaceRoom.contains(myPlayer())) { getWalking().webWalk(furnaceRoom); new ConditionalSleep(30000) { @Override public boolean condition() throws InterruptedException { return furnaceRoom.contains(myPlayer()); } }.sleep(); } else if (furnaceRoom.contains(myPlayer()) && furnace != null && !furnace.isVisible()) { getCamera().toEntity(furnace); } else if (inventory.contains("Copper ore", "Tin ore") && furnaceRoom.contains(myPlayer()) && furnace != null && bronzeWidget == null && !myPlayer().isAnimating() && furnace.isVisible()) { furnace.interact("Smelt"); new ConditionalSleep(5000) { @Override public boolean condition() throws InterruptedException { return getDialogues().isPendingContinuation() || bronzeWidget != null; } }.sleep(); } else if (inventory.contains("Copper ore", "Tin ore") && furnaceRoom.contains(myPlayer()) && bronzeWidget != null && !myPlayer().isAnimating()) { bronzeWidget.interact(); new ConditionalSleep(60000) { @Override public boolean condition() throws InterruptedException { return !inventory.contains("Copper ore", "Tin ore") || getDialogues().isPendingContinuation(); } }.sleep(); } } // Smelting operation ends here else { if (!Banks.GRAND_EXCHANGE.contains(myPlayer())) { getWalking().webWalk(Banks.GRAND_EXCHANGE); new ConditionalSleep(120000) { @Override public boolean condition() throws InterruptedException { return Banks.GRAND_EXCHANGE.contains(myPlayer()); } }.sleep(); } else if (Banks.GRAND_EXCHANGE.contains(myPlayer())) { if (bank != null && clerk != null) { if (inventory.isEmpty() && bronzeBar != 0) { if (!getBank().isOpen()) { bank.interact("Bank"); new ConditionalSleep(20000) { @Override public boolean condition() throws InterruptedException { return getBank().isOpen(); } }.sleep(); } else if (getBank().isOpen()) { if (getBank().isBankModeEnabled(Bank.BankMode.WITHDRAW_NOTE)) { if ((coins / 100) <= bronzeBar) { getBank().withdrawAll("Bronze bar"); new ConditionalSleep(3000) { @Override public boolean condition() throws InterruptedException { return inventory.contains("Bronze bar"); } }.sleep(); } else { getBank().withdrawAllButOne("Coins"); new ConditionalSleep(3000) { @Override public boolean condition() throws InterruptedException { return inventory.contains("Coins"); } }.sleep(); } } else { getBank().enableMode(Bank.BankMode.WITHDRAW_NOTE); new ConditionalSleep(3000) { @Override public boolean condition() throws InterruptedException { return getBank().isBankModeEnabled(Bank.BankMode.WITHDRAW_NOTE); } }.sleep(); } } } else { if (!getGrandExchange().isOpen() && !inventory.contains("Copper ore", "Tin ore")) { clerk.interact("Exchange"); new ConditionalSleep(5000) { @Override public boolean condition() throws InterruptedException { return getGrandExchange().isOpen(); } }.sleep(); } else { if (getGrandExchange().getItemId(GrandExchange.Box.BOX_1) == 436 || getGrandExchange().getItemId(GrandExchange.Box.BOX_1) == 438 || getGrandExchange().getItemId(GrandExchange.Box.BOX_1) == 2349) { sleep(500); getGrandExchange().collect(false); new ConditionalSleep(5000) { @Override public boolean condition() throws InterruptedException { return getGrandExchange().getItemId(GrandExchange.Box.BOX_1) == 0; } }.sleep(); } else if (getInventory().contains("Bronze bar")) { getGrandExchange().sellItem(2350, 1, (int) bronzeBar); new ConditionalSleep(10000) { @Override public boolean condition() throws InterruptedException { return !getGrandExchange().isSellOfferOpen(); } }.sleep(); bronzeBar = 0; } else if (getInventory().onlyContains("Coins")) { coins = getInventory().getAmount("Coins"); getGrandExchange().buyItem(436, "Copper", 70, (int) (coins / 2) / 70); new ConditionalSleep(10000) { @Override public boolean condition() throws InterruptedException { return !getGrandExchange().isBuyOfferOpen(); } }.sleep(); } else if (getInventory().contains("Coins", "Copper ore") && !getInventory().contains("Tin ore")) { getGrandExchange().buyItem(438, "Tin ore", 70, (int) (coins / 2) / 70); new ConditionalSleep(10000) { @Override public boolean condition() throws InterruptedException { return !getGrandExchange().isBuyOfferOpen(); } }.sleep(); } else if (getInventory().contains("Copper ore", "Tin ore")) { if (getGrandExchange().isOpen()) { getGrandExchange().close(); new ConditionalSleep(3000) { @Override public boolean condition() throws InterruptedException { return !getGrandExchange().isOpen(); } }.sleep(); } else if (!getBank().isOpen()) { bank.interact("Bank"); new ConditionalSleep(10000) { @Override public boolean condition() throws InterruptedException { return getBank().isOpen(); } }.sleep(); } else { long copper = inventory.getAmount("Copper ore"); long tin = inventory.getAmount("Tin ore"); getBank().depositAll(); new ConditionalSleep(3000) { @Override public boolean condition() throws InterruptedException { return false; } }.sleep(); copperOre = copper; tinOre = tin; } } } } } } } // Grand Exchange ends here return 1500; } @Override public void onExit() throws InterruptedException { log("Stopping Bronze Smelter."); } @Override public void onPaint(Graphics2D g) { } } Edited December 17, 2019 by MasonStorm 1 Quote Link to comment Share on other sites More sharing options...
Kramnik Posted December 17, 2019 Share Posted December 17, 2019 Cool script. Stange for me why you use conditional sleep when webwalking, any particular reasons for that? Had any issues without it? Quote Link to comment Share on other sites More sharing options...
MasonStorm Posted December 17, 2019 Author Share Posted December 17, 2019 2 minutes ago, Kramnik said: Cool script. Stange for me why you use conditional sleep when webwalking, any particular reasons for that? Had any issues without it? Now that you mention it, it does indeed seem redundant. Webwalker will constantly click on the map anyways. so there probably isn't any need for it. I haven't tried it without conditional sleep. I got into the habit of doing conditional sleep after every action taken Quote Link to comment Share on other sites More sharing options...
Kramnik Posted December 17, 2019 Share Posted December 17, 2019 29 minutes ago, MasonStorm said: Now that you mention it, it does indeed seem redundant. Webwalker will constantly click on the map anyways. so there probably isn't any need for it. I haven't tried it without conditional sleep. I got into the habit of doing conditional sleep after every action taken Yup, as far I used not having conditional sleep won't cause any problems. And also it would anyway run webwalking event and just after it finish proceed to conditional sleep. Quote Link to comment Share on other sites More sharing options...
MasonStorm Posted December 17, 2019 Author Share Posted December 17, 2019 I see. I didn't think of webwalking like that. I was thinking of it like every time it tries to walk its a new action, but its actually just one action with lesser actions within it. Thanks. I got a little smarter now. Quote Link to comment Share on other sites More sharing options...
Chris Posted December 17, 2019 Share Posted December 17, 2019 Make use of the Bank.open() api Would reduce the code needed to interact with the banker. // getBank().open() already does a conditional sleep! if (!getBank().isOpen()) getBank().open(); Quote Link to comment Share on other sites More sharing options...
MasonStorm Posted December 17, 2019 Author Share Posted December 17, 2019 11 minutes ago, Chris said: Make use of the Bank.open() api Would reduce the code needed to interact with the banker. // getBank().open() already does a conditional sleep! if (!getBank().isOpen()) getBank().open(); Interesting, thanks for your input. Will definitely make use of it in the future. Btw am I just unable to find it, or is there no equivalent to this for the G.E? Quote Link to comment Share on other sites More sharing options...
RSAccountsFarm Posted January 3, 2020 Share Posted January 3, 2020 Working good so far, thanks Quote Link to comment Share on other sites More sharing options...
PhaseCoder Posted January 3, 2020 Share Posted January 3, 2020 wow lots of if else you tried task based? Quote Link to comment Share on other sites More sharing options...
MasonStorm Posted January 6, 2020 Author Share Posted January 6, 2020 On 1/3/2020 at 3:17 PM, PhaseCoder said: wow lots of if else you tried task based? Yeah, if else statements is basically the extent of my java knowledge atm. Task based certainly looks cleaner from what I've seen, but I don't really understand it. I've been following a course on udemy for java, but I'm only about 15% done with it, maybe I'll get back to it when I have some free time. Thanks for your input, appreciated. Quote Link to comment Share on other sites More sharing options...
ForumGhost Posted January 16, 2023 Share Posted January 16, 2023 (edited) I am new to scripting and I used this script for a bit to make some decent money in F2P. The script worked as intended and didn't snag but it also had a few features that I didn't like: - It spends all of the money gained from selling bronze bars on copper and tin every time. This is an issue because as a F2P player with 0 quests completed you can't sell the copper or tin, so if you want to mule, you have to wait for the bot to finish smelting, which takes longer and longer after each restock. - If coins/100 > bronze bars it spends gold on copper/tin and doesn't sell bronze bars. This is just annoying - It tries to sell bronze bars for 1 GP each. This isn't really an issue but if you were to start a larger farm and singlehandedly crash the price of bronze bars you'd run into issues. I WAS going to re-write the whole thing from the ground up using switches and methods to make it neater and easier to read but I got about halfway through and got bored and frustrated so instead I added one variable, adjusted a few numbers, and commented out a portion of your code and now I have it set up the way I wanted. Now, it'll buy a MAXIMUM of 798 copper/tin and keep the rest of the wealth as coins on hand for easy muling. It'll never spend coins on hand on copper/tin instead using only profits from selling bronze bars (this means that if you interrupt the script after it sells bronze bars it'll get stuck, the script must be started with copper/tin or bronze bars in the bank/inv) It'll set the sell price of bronze bars at 150. Which is high enough to ensure a profit even if you are buying copper/tin at 70. Source: Spoiler import org.osbot.rs07.api.Bank; import org.osbot.rs07.api.GrandExchange; import org.osbot.rs07.api.map.Area; import org.osbot.rs07.api.map.constants.Banks; 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; import java.awt.*; @ScriptManifest(name = "Bronze Smelter", logo = "", version = 1, author = "Mason + Jojo", info = "Smelts bronze bars at Edgeville and restocks ores.") public class Main extends Script { Area furnaceRoom = new Area(3105, 3501, 3110, 3496); long copperOre = 100; long tinOre = 100; long bronzeBar = 100; long coins = 100; public int quantity = 0; @Override public void onStart() throws InterruptedException { log("Let's smelt some bronze bars"); } @Override public int onLoop() throws InterruptedException { NPC bank = getNpcs().closest("Banker"); NPC clerk = getNpcs().closest("Grand Exchange Clerk"); RS2Object furnace = getObjects().closest("Furnace"); RS2Widget bronzeWidget = getWidgets().get(270,14, 29); if ((copperOre >= 14) && (tinOre >= 14)) { if ((inventory.isEmpty() || inventory.getAmount("Bronze bar") == 14) && !Banks.EDGEVILLE.contains(myPlayer())) { getWalking().webWalk(Banks.EDGEVILLE); new ConditionalSleep(20000) { @Override public boolean condition() throws InterruptedException { return Banks.EDGEVILLE.contains(myPlayer()); } }.sleep(); } else if (Banks.EDGEVILLE.contains(myPlayer()) && bank != null && !bank.isVisible()) { getCamera().toEntity(bank); } else if ((inventory.isEmpty() || (inventory.getAmount("Bronze bar") == 14) || ((inventory.getAmount("Copper ore") == 14 || inventory.getAmount("Tin ore") == 14) && (inventory.getAmount("Copper ore") != 14 || inventory.getAmount("Tin ore") != 14))) && Banks.EDGEVILLE.contains(myPlayer()) && bank != null && bank.isVisible() && !getBank().isOpen()) { bank.interact("Bank"); new ConditionalSleep(5000) { @Override public boolean condition() throws InterruptedException { return getBank().isOpen(); } }.sleep(); } else if (inventory.isEmpty() && Banks.EDGEVILLE.contains(myPlayer()) && bank != null && getBank().isOpen()) { if ((getBank().getAmount("Copper ore") >= 14) && (getBank().getAmount("Tin ore") >= 14)) { getBank().withdraw("Copper ore", 14); new ConditionalSleep(3000) { @Override public boolean condition() throws InterruptedException { return inventory.contains("Copper ore"); } }.sleep(); } else { copperOre = getBank().getAmount("Copper ore"); tinOre = getBank().getAmount("Tin ore"); bronzeBar = getBank().getAmount("Bronze bar"); coins = getBank().getAmount("Coins"); } } else if ((inventory.getAmount("Copper ore") == 14) && !inventory.contains("Tin ore") && Banks.EDGEVILLE.contains(myPlayer()) && bank != null && getBank().isOpen()) { getBank().withdraw("Tin ore", 14); new ConditionalSleep(3000) { @Override public boolean condition() throws InterruptedException { return inventory.contains("Tin ore"); } }.sleep(); } else if ((inventory.getAmount("Bronze bar") == 14) && Banks.EDGEVILLE.contains(myPlayer()) && bank != null && getBank().isOpen()) { getBank().depositAll("Bronze bar"); new ConditionalSleep(3000) { @Override public boolean condition() throws InterruptedException { return !inventory.contains("Bronze bar"); } }.sleep(); } else if (inventory.contains("Copper ore", "Tin ore") && !furnaceRoom.contains(myPlayer())) { getWalking().webWalk(furnaceRoom); new ConditionalSleep(30000) { @Override public boolean condition() throws InterruptedException { return furnaceRoom.contains(myPlayer()); } }.sleep(); } else if (furnaceRoom.contains(myPlayer()) && furnace != null && !furnace.isVisible()) { getCamera().toEntity(furnace); } else if (inventory.contains("Copper ore", "Tin ore") && furnaceRoom.contains(myPlayer()) && furnace != null && bronzeWidget == null && !myPlayer().isAnimating() && furnace.isVisible()) { furnace.interact("Smelt"); new ConditionalSleep(5000) { @Override public boolean condition() throws InterruptedException { return getDialogues().isPendingContinuation() || bronzeWidget != null; } }.sleep(); } else if (inventory.contains("Copper ore", "Tin ore") && furnaceRoom.contains(myPlayer()) && bronzeWidget != null && !myPlayer().isAnimating()) { bronzeWidget.interact(); new ConditionalSleep(60000) { @Override public boolean condition() throws InterruptedException { return !inventory.contains("Copper ore", "Tin ore") || getDialogues().isPendingContinuation(); } }.sleep(); } } // Smelting operation ends here else { if (!Banks.GRAND_EXCHANGE.contains(myPlayer())) { getWalking().webWalk(Banks.GRAND_EXCHANGE); new ConditionalSleep(120000) { @Override public boolean condition() throws InterruptedException { return Banks.GRAND_EXCHANGE.contains(myPlayer()); } }.sleep(); } else if (Banks.GRAND_EXCHANGE.contains(myPlayer())) { if (bank != null && clerk != null) { if (inventory.isEmpty() && bronzeBar != 0) { if (!getBank().isOpen()) { bank.interact("Bank"); new ConditionalSleep(20000) { @Override public boolean condition() throws InterruptedException { return getBank().isOpen(); } }.sleep(); } else if (getBank().isOpen()) { if (getBank().isBankModeEnabled(Bank.BankMode.WITHDRAW_NOTE)) { //if ((coins / 100) <= bronzeBar) { getBank().withdrawAll("Bronze bar"); new ConditionalSleep(3000) { @Override public boolean condition() throws InterruptedException { return inventory.contains("Bronze bar"); } }.sleep(); //} /*else { getBank().withdrawAllButOne("Coins"); new ConditionalSleep(3000) { @Override public boolean condition() throws InterruptedException { return inventory.contains("Coins"); } }.sleep(); }*/ } else { getBank().enableMode(Bank.BankMode.WITHDRAW_NOTE); new ConditionalSleep(3000) { @Override public boolean condition() throws InterruptedException { return getBank().isBankModeEnabled(Bank.BankMode.WITHDRAW_NOTE); } }.sleep(); } } } else { if (!getGrandExchange().isOpen() && !inventory.contains("Copper ore", "Tin ore")) { clerk.interact("Exchange"); new ConditionalSleep(5000) { @Override public boolean condition() throws InterruptedException { return getGrandExchange().isOpen(); } }.sleep(); } else { if (getGrandExchange().getItemId(GrandExchange.Box.BOX_1) == 436 || getGrandExchange().getItemId(GrandExchange.Box.BOX_1) == 438 || getGrandExchange().getItemId(GrandExchange.Box.BOX_1) == 2349) { sleep(500); getGrandExchange().collect(false); new ConditionalSleep(5000) { @Override public boolean condition() throws InterruptedException { return getGrandExchange().getItemId(GrandExchange.Box.BOX_1) == 0; } }.sleep(); } else if (getInventory().contains("Bronze bar")) { getGrandExchange().sellItem(2350, 150, (int) bronzeBar); new ConditionalSleep(10000) { @Override public boolean condition() throws InterruptedException { return !getGrandExchange().isSellOfferOpen(); } }.sleep(); bronzeBar = 0; } else if (getInventory().onlyContains("Coins")) { coins = getInventory().getAmount("Coins"); if(coins >= 111720){ quantity = 798; } else{ quantity = (int)coins/2/70; } getGrandExchange().buyItem(436, "Copper", 70, quantity); new ConditionalSleep(10000) { @Override public boolean condition() throws InterruptedException { return !getGrandExchange().isBuyOfferOpen(); } }.sleep(); } else if (getInventory().contains("Coins", "Copper ore") && !getInventory().contains("Tin ore")) { getGrandExchange().buyItem(438, "Tin ore", 70, quantity); new ConditionalSleep(10000) { @Override public boolean condition() throws InterruptedException { return !getGrandExchange().isBuyOfferOpen(); } }.sleep(); } else if (getInventory().contains("Copper ore", "Tin ore")) { if (getGrandExchange().isOpen()) { getGrandExchange().close(); new ConditionalSleep(3000) { @Override public boolean condition() throws InterruptedException { return !getGrandExchange().isOpen(); } }.sleep(); } else if (!getBank().isOpen()) { bank.interact("Bank"); new ConditionalSleep(10000) { @Override public boolean condition() throws InterruptedException { return getBank().isOpen(); } }.sleep(); } else { long copper = inventory.getAmount("Copper ore"); long tin = inventory.getAmount("Tin ore"); getBank().depositAll(); new ConditionalSleep(3000) { @Override public boolean condition() throws InterruptedException { return false; } }.sleep(); copperOre = copper; tinOre = tin; } } } } } } } // Grand Exchange ends here return 1500; } @Override public void onExit() throws InterruptedException { log("Stopping Bronze Smelter."); } @Override public void onPaint(Graphics2D g) { } } Edited January 16, 2023 by ForumGhost Fixed 792 to 798 for 57 full inventories Quote Link to comment Share on other sites More sharing options...