MattyMurph Posted January 23, 2023 Share Posted January 23, 2023 Hi all, I had this code working a few years ago, but I can't seem to get it working for the life of me. Been out of coding for a while so it's probably a noob error. Buys & hops fine. But when inventory is full it doesn't bank. Any ideas? Thanks! 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 java.awt.*; import javax.swing.text.html.parser.Entity; @ScriptManifest(info = "GRAPE BUYER", version = 1.0, logo = "", author = "MATT", name = "GRAPE BUYER") public class main extends Script { enum State { OPENCHEST, BUYGRAPES, BANK, HOP; } public State state; public void onStart(){ if(getInventory().isFull()) { state = State.BANK; log("BANK"); } if (!getInventory().isFull()) { state = State.BUYGRAPES; } if (getInventory().onlyContains("Coins")) { state = State.OPENCHEST; log("OPEN CHEST"); } if(getStore().isOpen() && getStore().getAmount("Grapes") > 0) { state = State.BUYGRAPES; } if(getStore().isOpen() && getStore().getAmount("Grapes") == 0) { state = State.HOP; } } public int onLoop() throws InterruptedException{ switch (state){ case OPENCHEST: return openChest(); case BUYGRAPES: return buyGrapes(); case BANK: return bank(); case HOP: return hopWorlds(); } return random(100, 220); } int openChest() throws InterruptedException { objects.closest("Chest").interact("Buy-food"); sleep(900); if (getInventory().contains("Coins") && !getInventory().isFull()) { if (!getStore().contains("Grapes")) { state = State.HOP; log("HOPPING"); } else if (getStore().contains("Grapes") && !getInventory().isFull()) { log("Changing state to buying"); state = State.BUYGRAPES; } else if (getStore().contains("Grapes") && getInventory().isFull()) { state = State.BANK; } } return 0; } int buyGrapes() throws InterruptedException { log("BUYING"); if (!store.isOpen()) { state = state.OPENCHEST; } log("BUYING GRAPES NOW"); if ((store.isOpen()) && !getInventory().isFull()){ log("store is open"); sleep(300); RS2Widget grapeWidget = getWidgets().get(300, 16, 5); if (grapeWidget != null && grapeWidget.interact("Buy 10")) { log("buying 10"); sleep(1000); } if (store.isOpen()) { store.close(); } if (getInventory().isFull()) { state = State.BANK; } else { log("Hopping"); state = State.HOP; } } else if (getInventory().isFull()) { getBank().depositAllExcept("Coins"); sleep(300); } sleep(300); sleep(300); return 0; } int bank() throws InterruptedException{ if (getBank().isOpen()) { getBank().depositAllExcept("Coins"); } else if (!getBank().isOpen()) { getBank().open(); sleep(300); getBank().depositAllExcept("Coins"); } sleep(300); return 0; } int hopWorlds() throws InterruptedException { getWorlds().hopToP2PWorld(); sleep(300); return 0; } } Quote Link to comment Share on other sites More sharing options...
Juggles Posted January 23, 2023 Share Posted January 23, 2023 (edited) Does your logger show "BANK"? Also you should use sleep conditions so the script is more efficient instead of sleep(300); I'm assuming your using the chest in lumbridge basement? I think the bank isn't actually coded in getBank.open();. Instead create an object and open the bank. RS2Object bank = getObjects.closest(BANK_CHEST_NAME); if (bank!=null && !getBank().isOpen) { if (bank.interact("Open"); sleepCondition(Until_bank_is_open, 1500); } Edited January 23, 2023 by Juggles Quote Link to comment Share on other sites More sharing options...
MattyMurph Posted January 23, 2023 Author Share Posted January 23, 2023 (edited) 3 minutes ago, Juggles said: Does your logger show "BANK"? Also you should use sleep conditions so the script is more efficient instead of sleep(300); It does show 'BANK' but doesn't progress from there. & Thanks for the advice mate, will do EDIT: Also just to note, it only shows 'BANK' when I start with a full inventory. If I let the script buy & hop until a full invent, it gets stuck at 'Buying 10' [INFO][Bot #1][01/23 04:54:38 PM]: Started script : GRAPE BUYER [INFO][Bot #1][01/23 04:54:38 PM]: BUYING [INFO][Bot #1][01/23 04:54:38 PM]: BUYING GRAPES NOW [INFO][Bot #1][01/23 04:54:40 PM]: Changing state to buying [INFO][Bot #1][01/23 04:54:40 PM]: BUYING [INFO][Bot #1][01/23 04:54:40 PM]: BUYING GRAPES NOW [INFO][Bot #1][01/23 04:54:40 PM]: store is open [INFO][Bot #1][01/23 04:54:41 PM]: buying 10 Edited January 23, 2023 by MattyMurph Quote Link to comment Share on other sites More sharing options...
Khaleesi Posted January 23, 2023 Share Posted January 23, 2023 You should try to only do 1 interaction every onloop, don't chain too much things. If 1 interaction fails all other after it will fail or fuck up. Quote Link to comment Share on other sites More sharing options...
Czar Posted January 23, 2023 Share Posted January 23, 2023 You must move everything from onStart to onLoop. onStart only triggers once (when script first starts) and never again. And the code inside onstart is determining which state to be in, aka the script will be stuck in whatever state is set in onstart. By moving it to onloop it will always update/refresh every cycle Quote Link to comment Share on other sites More sharing options...