Stinji Posted February 2, 2019 Posted February 2, 2019 Hey guys, I'm writing a bot that buys items from a shop and banks them when inventory is full. The thing is that the restock rate is pretty fast and the bot will repeatedly buy items until the inventory is full (the line that says hop worlds when getAmount() == 0; doesn't even get activated because of how fast it is). That's why I decided to hop worlds whenever the message "The shop has run out of stock." appears. My code looks like this: public void onMessage(Message m) throws InterruptedException { if (m.getMessage().contains("The shop has run out of stock.")) { log("Shop ran out of stock, hopping worlds"); currentWorld = getWorlds().getCurrentWorld(); getWorlds().hopToP2PWorld(); new ConditionalSleep(5000) { @Override public boolean condition() throws InterruptedException { return getWorlds().getCurrentWorld() != currentWorld && getWorlds().isOpen(); } }.sleep(); } } However, it doesn't get overridden long enough for all of the code to be executed. I know this because I tested the following code: public void onMessage(Message m) throws InterruptedException { if (m.getMessage().contains("The shop has run out of stock.")) { sleep(10000); } } The logger gives an error message after about 5 seconds, so I'm thinking the onMessage doesn't store the message until the end of the code. Is there a way to change the length it stores the value or is there another way of achieving the same result? Thanks guys! PS. Can anyone please let me know if the 'currentWorld' line is necessary. In other words: will the hopToP2PWorld() recognize the current world and consider not hopping to this world on its own?
HeyImJamie Posted February 2, 2019 Posted February 2, 2019 I wouldn't put that code in onMessage if I were you. Use it to set a boolean and hop based on that.
Stinji Posted February 2, 2019 Author Posted February 2, 2019 Something like this? @Override public void onMessage(Message m) throws InterruptedException { if (m.getMessage().contains("The shop has run out of stock.")) { outOfStock = true; } } ... if (outOfStock.equals(true)) { insert hop here; outOfStock = false; //to reset the boolean } 1
hreyvirtue Posted February 2, 2019 Posted February 2, 2019 (edited) You can always set it to hop when it reaches 10 or below(assume you're doing a high stocked item) if you don't get the onmessage working or just have it hop after every instance of buying the item(s) Edited February 2, 2019 by hreyvirtue
Eagle Scripts Posted February 2, 2019 Posted February 2, 2019 7 minutes ago, Stinji said: Something like this? @Override public void onMessage(Message m) throws InterruptedException { if (m.getMessage().contains("The shop has run out of stock.")) { outOfStock = true; } } ... if (outOfStock.equals(true)) { insert hop here; outOfStock = false; //to reset the boolean } Yeah something like that. Please note that if (outOfStock.equals(true)) { } Can be used as if (outOfStock) { }
Stinji Posted February 2, 2019 Author Posted February 2, 2019 This works! Thanks @HeyImJamie and @Eagle Scripts! 1