Gearfighter Posted October 17, 2016 Share Posted October 17, 2016 Hi all, ive got 2 problems with my script. First is that if the script starts with the bank open it wont do anything, but if i close the bank the bot starts(and when it starts it opens the bank....) second one is that i want it to make all the uncooked pizzas first before cooking them, but once it makes all the uncooked one it just goes into an endless loop of opening and closing the bank. Here is my code (hope it something simple im overlooking): import java.awt.Graphics2D; import java.awt.font.NumericShaper.Range; import org.osbot.rs07.api.Bank; import org.osbot.rs07.api.Inventory; import org.osbot.rs07.api.Mouse; import org.osbot.rs07.api.Objects; import org.osbot.rs07.api.Settings; import org.osbot.rs07.api.map.Area; import org.osbot.rs07.api.map.Position; import org.osbot.rs07.api.model.NPC; import org.osbot.rs07.api.model.Player; import org.osbot.rs07.api.model.RS2Object; import org.osbot.rs07.input.mouse.MiniMapTileDestination; import org.osbot.rs07.script.Script; import org.osbot.rs07.script.ScriptManifest; import org.osbot.rs07.utility.ConditionalSleep; import org.osbot.rs07.api.ui.RS2Widget; @SuppressWarnings("unused") @ScriptManifest(name = "Gearz Pizza Maker", author = "Gearfighter", version = 1.0, info = "About your script", logo = "Logo of your script. Imgur links here [DIRECT LINKS ONLY]") public class GearzPizzaMaker extends Script { public void makeAll() throws InterruptedException { RS2Widget PizzaWidget; PizzaWidget = getWidgets().get(309, 6); if (PizzaWidget != null && PizzaWidget.isVisible()) if (PizzaWidget.interact("Make all")) sleep(18000); } public void cookAll() throws InterruptedException { RS2Widget UnpizzaWidget = widgets.get(307, 4); if (UnpizzaWidget != null && UnpizzaWidget.isVisible()) sleep(500); UnpizzaWidget.interact("Cook All"); new ConditionalSleep(1000000) { @ Override public boolean condition() throws InterruptedException { return !getInventory().contains("Uncooked pizza"); } }.sleep(); } public void onStart() { log("Ima Make some a Pizza"); } private enum State { Basetomato, Incompcheese, Uncookbank, Incompbank, Uncooking, Basefail, Tomfail, Cheesefail, Plainbank } private State getState() { if (getInventory().isEmpty()) { return State.Basetomato; } else if (getInventory().contains("Incomplete pizza")) { return State.Incompcheese; } else if (getInventory().contains("Uncooked pizza")) { return State.Uncookbank; } else if (getBank().contains("Incomplete pizza")) { return State.Incompbank; } else if (!getBank().contains("Pizza base") && (!getBank().contains("Incomplete pizza"))) { return State.Uncooking; } else if (getInventory().onlyContains("Pizza base")) { return State.Basefail; } else if (getInventory().onlyContains("Tomato")) { return State.Tomfail; } else if (getInventory().onlyContains("Cheese")) { return State.Cheesefail; } else if (getInventory().contains("Plain pizza") && (!getInventory().contains("Uncooked pizza"))) { return State.Plainbank; } return null; } @[member=Override] public void onExit() { // Code here will execute after the script ends // Examples: logs, listeners, or dynamic sig data. Really anything that // needs to be ended when the user of your script stops it. log("Script ended! Please leave feedback on the forums"); } @[member=Override] public int onLoop() throws InterruptedException { switch (getState()) { case Basetomato: if (!getBank().isOpen()) { getBank().open(); getBank().withdraw("Pizza base", 14); sleep(300); getBank().withdraw("Tomato", 14); getBank().close(); if (getInventory().getItem("Pizza base").interact("Use", "Pizza base")) if (getInventory().getItem("Tomato").interact("Use", "Tomato")) sleep(1000); makeAll(); } break; case Incompcheese: if (!getBank().isOpen()) { getBank().open(); sleep(300); if (!getInventory().contains("Pizza base")); getBank().withdraw("Cheese", 14); getBank().close(); if (getInventory().getItem("Incomplete pizza").interact("Use", "Incomplete pizza")) if (getInventory().getItem("Cheese").interact("Use", "Cheese")) sleep(800); makeAll(); } break; case Uncookbank: if (!getBank().isOpen());{ getBank().open(); sleep(500); getBank().depositAll(); getBank().close(); } break; case Incompbank: sleep(300); { getBank().withdraw("Incomplete pizza", 14); if (getInventory().contains("Incomplete pizza")); sleep(300); getBank().withdraw("Cheese", 14); getBank().close(); if (getInventory().getItem("Incomplete pizza").interact("Use", "Incomplete pizza")) if (getInventory().getItem("Cheese").interact("Use", "Cheese")) sleep(500); makeAll(); } break; case Uncooking: sleep(300); { getBank().withdrawAll("Uncooked pizza"); sleep(500); getBank().close(); RS2Widget UnpizzaWidget = widgets.get(307, 4); RS2Object Range = objects.closest("Range");{ if (Range.isVisible()); if (getInventory().getItem("Uncooked pizza").interact("Use", "Uncooked pizza")) if (Range.interact("Use")); new ConditionalSleep(10000) { @ Override public boolean condition() throws InterruptedException { return (UnpizzaWidget != null && (UnpizzaWidget.isVisible())); } }.sleep(); cookAll(); } } break; case Basefail: if (!getBank().isOpen()) { getBank().open(); sleep(800); getBank().withdraw("Tomato", 14); getBank().close(); } break; case Cheesefail: if (!getBank().isOpen()) { getBank().open(); sleep(800); getBank().withdraw("Incomplete pizza", 14); getBank().close(); } break; case Tomfail: if (!getBank().isOpen()) { getBank().open(); sleep(800); getBank().withdraw("Pizza base", 14); getBank().close(); } break; default: break; } return 0; } } Quote Link to comment Share on other sites More sharing options...
House Posted October 17, 2016 Share Posted October 17, 2016 (edited) In general the statement deciding logic seems iffy. do something more like. does my inventory have dough and tomatoes in it -> combine elsedoes my inventory have plain pizzas and cheese -> combine else ... ... bank.open() if bank contains dough and tomatoes -> withdraw them. else if bank contains plain pizzas and cheese -> withdraw them. Edited October 17, 2016 by House Quote Link to comment Share on other sites More sharing options...
Zappster Posted October 17, 2016 Share Posted October 17, 2016 Just from first glance I notice that in every state you are doing something with the bank. I bet you've got a little confused with the logic and somewhere it's just not exiting correctly, may I offer a suggestion to your logic? Start with the states and rewrite them. Have one state that handles all banking. Within that state you'll have your checks too see what item you need (can set as a global variable and call from within the case) and then proceed to withdraw them. Your next state should be prepare. In here you'll maybe also have another global var set after banking which tells you what part of prep you are at. In here it will contain the logic for adding the ingredients together. Another state you may want is a Walking state. This will handle walking from the place to cook -><- to the bank. The final state will be cooking. This is where you look for uncooked pizzas, and if none exist, you simply set your walking state. You have a lot of repeating actions which can be reduced to help with the logic. Quote Link to comment Share on other sites More sharing options...
Gearfighter Posted October 17, 2016 Author Share Posted October 17, 2016 @House so do i basically make 2 states? one for withdrawing items and the other for combining? also what about the cooking problem? Quote Link to comment Share on other sites More sharing options...
House Posted October 17, 2016 Share Posted October 17, 2016 (edited) @House so do i basically make 2 states? one for withdrawing items and the other for combining? also what about the cooking problem? imo its bad to trigger interactions in a row assuming the previous one correctly executed. hence why i told you on shitbox to return after each interaction and use the example i provided :p Start writing you script the same way my example is written. https://github.com/HouseMD/HMeltingBalls Edited October 17, 2016 by House Quote Link to comment Share on other sites More sharing options...
Gearfighter Posted October 17, 2016 Author Share Posted October 17, 2016 so would it be something like if (getBank().contains("Pizza base") && (getBank().contains("Tomato") { getBank().withdraw("Pizza base", 14) if (getInventory().contains("Pizza base") getBank().withdraw("Tomato", 14) else if (getBank().contains("Incomplete pizza") && (getBank().contains("Cheese") { getBank().withdraw("Incomplete pizza", 14) if (getInventory().contains("Incomplete pizza") getBank().withdraw("Cheese", 14) else if..... ? @House im scared Quote Link to comment Share on other sites More sharing options...
House Posted October 17, 2016 Share Posted October 17, 2016 (edited) if (inventory.contains("Pizza base") && inventory.contains("Tomato")) { return State.MAKE_INCOMPLETE_PIZZA; } if (inventory.contains("Incomplete pizza") && inventory.contains("Cheese")) { return State.MAKE_UNCOOKED_PIZZA; } if (getBank().contains("Pizza base") && getBank().contains("Tomato")) { return State.WITHDRAW_BASE_TOMATO; } else if (getBank().contains("Incomplete pizza") && getBank().contains("Cheese")) { return State.WITHDRAW_INCOMPLETE_CHEESE; an example (don't forget to deposit the product item each time too) But just yeah its a lot to explain. i think ima have to give up im really bad with patients. Use my example use ititititit. Make one Task to withdraw and one to combine. Determine which items to combine within the task. That way you can fix code or append to each step of pizza making by editing it in one place Edited October 17, 2016 by House Quote Link to comment Share on other sites More sharing options...
Explv Posted October 19, 2016 Share Posted October 19, 2016 (edited) Hi all, ive got 2 problems with my script. First is that if the script starts with the bank open it wont do anything, but if i close the bank the bot starts(and when it starts it opens the bank....) second one is that i want it to make all the uncooked pizzas first before cooking them, but once it makes all the uncooked one it just goes into an endless loop of opening and closing the bank. Here is my code (hope it something simple im overlooking) Your logic in general is a bit off. It should be as simple as this: If the player has the ingredients for making an uncooked pizza in their inventory: If the bank is open: Close the bank Else: Make uncooked pizzas Else if the player has uncooked pizzas in their inventory: If the bank is open: Close the bank Else If the player is at the range: Cook the pizzas Else: Walk to the range Else if the player is not at the bank: Walk to the bank Else if the bank is not open: Open the bank Else if the inventory is not empty: Deposit All Else if the player has ingredients for uncooked pizza in the bank: Withdraw the ingredients Else if the player has uncooked pizzas in the bank: Withdraw the uncooked pizzas Else: Stop the script If you really want to use states, then from the above logic you would have: BANK, MAKE_UNCOOKED, COOK_PIZZAS Your getState() method should not return null, your script should always be in some kind of state. Also try and use Conditional Sleeps where you can Hopefully this helps: private enum State { BANK, MAKE_UNCOOKED, COOK_PIZZAS } public int onLoop() throws InterruptedException { switch(getState()) { case MAKE_UNCOOKED: if(getBank() != null && getBank().isOpen()) getBank().close(); else makeUncookedPizzas(); break; case COOK_PIZZAS: if(getBank() != null && getBank().isOpen()) getBank().close(); else cookPizzas(); break; case BANK: bank(); break; } return random(100, 150); } private final State getState() { if (hasUncookedIngredients()) return State.MAKE_UNCOOKED; if (hasUncookedPizzas()) return State.COOK_PIZZAS; return State.BANK; } private final void makeUncookedPizzas() { // make the pizzas } private final void cookPizzas() { // check if at range, if not walk there // cook the pizzas } private final void bank() throws InterruptedException { if(getBank() == null) { getWalking().webWalk(bankArea); } else if(!getBank().isOpen()) { openBank(); } else if(!getInventory().isEmpty()) { getBank().depositAll(); } else if(!hasUncookedIngredients() && bankContainsUncookedIngredients()) { withdrawUncookedIngredients(); } else if(!hasUncookedPizzas() && bankContainsUncookedPizzas()) { withdrawCookedPizzas(); } else { stop(); } } private final void openBank() throws InterruptedException { if(getBank().open()) { new ConditionalSleep(5000) { public boolean condition() throws InterruptedException { return getBank().isOpen(); } }.sleep(); } } Edited October 19, 2016 by Explv 3 Quote Link to comment Share on other sites More sharing options...
Qubit Posted October 20, 2016 Share Posted October 20, 2016 read my signature Quote Link to comment Share on other sites More sharing options...