March 10, 20178 yr Hello everyone. In my script I'm trying to combine the use of rock cakes with overloads. It works initially when the bot has started but during combat when it goes to use the overload again it will also use the rock cake as the health is dropping, which leads to me dying. Any ideas on how I can tweak this code to get it to wait until the overload has finished to then use the rock cake? Cheers import org.osbot.rs07.api.GrandExchange; import org.osbot.rs07.api.Prayer; import org.osbot.rs07.api.Bank.BankMode; import org.osbot.rs07.api.model.Player; import org.osbot.rs07.api.ui.RS2Widget; import org.osbot.rs07.api.ui.Skill; import org.osbot.rs07.input.mouse.InventorySlotDestination; import org.osbot.rs07.script.Script; import org.osbot.rs07.script.ScriptManifest; import java.awt.*; @ScriptManifest(name = "NMZ", author = "Matt", version = 1.0, info = "", logo = "") public class main extends Script { boolean overLoad; @Override public void onStart() { //Code here will execute before the loop is started } private enum State { ABSORBPOT, RAPIDHEAL, ROCKCAKE, OVERLOAD, RESTART, WAIT }; private State getState() { if (getSkills().getDynamic(Skill.HITPOINTS) > 50) { overLoad = true; return State.OVERLOAD; } if (getSkills().getDynamic(Skill.HITPOINTS) > 1 && getSkills().getDynamic(Skill.HITPOINTS) < 51 && overLoad == false) { return State.ROCKCAKE; } if (getCurrentAbsorption() < 200) { while(getCurrentAbsorption() < 1000) { return State.ABSORBPOT; } } if (getSkills().getDynamic(Skill.HITPOINTS) == 1) { return State.RAPIDHEAL; } return State.WAIT; } public int onLoop() throws InterruptedException { switch (getState()) { case ROCKCAKE: getInventory().interact("Guzzle", "Dwarven rock cake"); break; case ABSORBPOT: if (getInventory().contains("Absorption (4)")) { int slot = getInventory().getSlot("Absorption (4)"); getMouse().click(new InventorySlotDestination(getBot(), slot)); } else if (getInventory().contains("Absorption (3)")) { int slot = getInventory().getSlot("Absorption (3)"); getMouse().click(new InventorySlotDestination(getBot(), slot)); } else if (getInventory().contains("Absorption (2)")) { int slot = getInventory().getSlot("Absorption (2)"); getMouse().click(new InventorySlotDestination(getBot(), slot)); } else if (getInventory().contains("Absorption (1)")) { int slot = getInventory().getSlot("Absorption (1)"); getMouse().click(new InventorySlotDestination(getBot(), slot)); } break; case OVERLOAD: overLoad = true; if (getInventory().contains("Overload (4)")) { int slot = getInventory().getSlot("Overload (4)"); getMouse().click(new InventorySlotDestination(getBot(), slot)); sleep(5000); overLoad = false; } else if (getInventory().contains("Overload (3)")) { int slot = getInventory().getSlot("Overload (3)"); getMouse().click(new InventorySlotDestination(getBot(), slot)); sleep(5000); overLoad = false; } else if (getInventory().contains("Overload (2)")) { int slot = getInventory().getSlot("Overload (2)"); getMouse().click(new InventorySlotDestination(getBot(), slot)); sleep(5000); overLoad = false; } else if (getInventory().contains("Overload (1)")) { int slot = getInventory().getSlot("Overload (1)"); getMouse().click(new InventorySlotDestination(getBot(), slot)); sleep(5000); overLoad = false; } break; case RAPIDHEAL: RS2Widget quickPrayer = widgets.get(160, 16); quickPrayer.interact(); sleep(500); quickPrayer.interact(); sleep(40000); break; case RESTART: sleep(10000); case WAIT: sleep(3000); break; } return random(200, 300); } public int getCurrentAbsorption() { RS2Widget widget = widgets.get(202, 1, 9); if(widget == null || !widget.isVisible() || widget.getMessage().isEmpty()) return 0; return Integer.parseInt(widget.getMessage()); } @Override public void onExit() { //Code here will execute after the script ends } public void onPaint(Graphics2D g) { //This is where you will put your code for paint(s) } } Edited March 10, 20178 yr by uyfgfarOS
March 12, 20178 yr You can add a sleep after you eat the rock cake. You can add a check before you interact with the rock cake (Yes I know you already check with the state thing, but I had this problem too with my script and I added it) I remember there being 2 options on the rock cake. One to reduce your hp by a larger amount and one option to reduce it by 1. You can use logic here to decide which option the script should use.
March 13, 20178 yr It think it would be best to script taking an overload at a specific value (51 for example, or maybe a range. e.g. 51-53) and then in the part after where you drink the overload put a ConditionalSleep which basically sleeps until your condition is true. So make your condition health >= 1 && health <= 3, for example. That would make the drink absorption part wait until you reached your desired health by absorption. Don't forget to call sleep, use it like this: new ConditionalSleep(10000) { //max amount of sleep in constructor //override condition() here }.sleep(); Otherwise, if you need to do stuff while the health is being dropped (so you can't afford a wait) you would be better of using a timer and then checking the conditions of the timer and health in your guzzle part. Edit: Also, you should post this in Scripting Help Edited March 13, 20178 yr by Reveance
March 24, 20178 yr I had the same issue a few weeks ago when i first started writing my NMZ script. Personally, I use timers for when to drink an overload since they will ALWAYS last for only 5 minutes, then health is restored. So create a timer after successfully drinking an overload. Only rock cake under a few cases overload timer isn't running and doesn't have overload pots (should have 51 hp but need to bring back down to 1) Health is full at start of dream, rock cake down to 51 for overloads if using them Health is full at start of dream, rock cake down to 1 if not using overloads Also make sure the timer has been running for at least 5001ms (just a tad over 5 seconds) but i use 5100, otherwise if the script needs to rockcake under a valid condition while the overload is hitting you, it'll rock cake and kill you. Waiting until the overload timer is at least 5001ms into its time will ensure the overload has completed its damage.
March 25, 20178 yr Actually, I think I've seen a message when the overload wears off: "The effects of overload have worn off, and you feel normal again." :p. That would actually be the best thing to do; implement a MessageListener in your script and register when the overload has worn off using that message
March 25, 20178 yr 8 hours ago, Reveance said: Actually, I think I've seen a message when the overload wears off: "The effects of overload have worn off, and you feel normal again." :p. That would actually be the best thing to do; implement a MessageListener in your script and register when the overload has worn off using that message Certainly one route you can take, I use a timer so that I can make the script a little more humanlike
March 25, 20178 yr 5 hours ago, Polymorphism said: Certainly one route you can take, I use a timer so that I can make the script a little more humanlike Yeah sure, you should add some randomness though...but that applies to both methods. I don't think it actually matters which route you take since I doubt a timer will fail :P
March 25, 20178 yr 8 minutes ago, Reveance said: Yeah sure, you should add some randomness though...but that applies to both methods. I don't think it actually matters which route you take since I doubt a timer will fail :P For NMZ, I am building my script around the playing style "afk training in nmz while distracted by other internets" lol
March 25, 20178 yr 26 minutes ago, Polymorphism said: For NMZ, I am building my script around the playing style "afk training in nmz while distracted by other internets" lol haha yeah that does definately work best there :p