LoremIpsum213 0 Share Posted March 20, 2023 (edited) At the moment i use this function to determine whether the player is smelting bars: private boolean isSmelting() { return Players.getLocal().isAnimating() || (Players.getLocal().getAnimation() == Players.getLocal().getStandAnimation() && canSmelt()); } where canSmelt() determines whether there is enough ores in the inventory. However, this is not fool proof as sometimes, the player model just stands still for a brief moment before adding more ore in the furnace. In the execute function i have an if statement that uses the isSmelting() function to determine whether we should interact with the furnace, \ if we are already smelting i don't want it to click on the furnace again. I have got everything else working for my smithing script, except for this annoying issue. If someone knows a better way, let me know. Edited March 20, 2023 by LoremIpsum213 Link to comment Share on other sites More sharing options...
una_maquina 35 Share Posted March 20, 2023 I had this happen when I was doing a cooking script, essentially you make sure that you started animating, and then you sleep until there's no more raw resources in your inventory (ores in this case), or until you're in dialogue. Link to comment Share on other sites More sharing options...
LoremIpsum213 0 Author Share Posted March 20, 2023 39 minutes ago, una_maquina said: I had this happen when I was doing a cooking script, essentially you make sure that you started animating, and then you sleep until there's no more raw resources in your inventory (ores in this case), or until you're in dialogue. Thats what i do, although iam not sure if iam using the sleepWhile() function correctly: // check whether we are in area if(Area.getArea().contains(Players.getLocal().getTile())) { GameObject furnace = Area.GetInteractionObject(); // if player is on tile in front of furnace and we can smelt, and interact if(furnace.interact()) { sleep(500, 3000); WidgetChild selectionbox = Widgets.getWidgetChild(270, widgetMap.get(Bar.getID())); if (selectionbox != null && selectionbox.isVisible()) { //widget exists selectionbox.interact(); } sleepWhile(() -> canSmelt(), 30000, 5000); } } Link to comment Share on other sites More sharing options...
una_maquina 35 Share Posted March 20, 2023 1 hour ago, LoremIpsum213 said: Thats what i do, although iam not sure if iam using the sleepWhile() function correctly: // check whether we are in area if(Area.getArea().contains(Players.getLocal().getTile())) { GameObject furnace = Area.GetInteractionObject(); // if player is on tile in front of furnace and we can smelt, and interact if(furnace.interact()) { sleep(500, 3000); WidgetChild selectionbox = Widgets.getWidgetChild(270, widgetMap.get(Bar.getID())); if (selectionbox != null && selectionbox.isVisible()) { //widget exists selectionbox.interact(); } sleepWhile(() -> canSmelt(), 30000, 5000); } } Oh, you're passing 3 arguments to sleepWhile, you can only pass two, wrap the "30000, 5000" into Calculations.random(30000,50000), otherwise check out your canSmelt logic, it might be the problem. sleepWhile(() -> canSmelt(), Calculations.random(30000, 50000)); Link to comment Share on other sites More sharing options...
una_maquina 35 Share Posted March 20, 2023 Oh, maybe you can pass 3 arguments to sleepWhile and it automatically randomizes the sleep times (didn't know that), but the fact that you've put 30000 and 5000 as the other number, might be the problem, because it's 30 secs and 5 secs. Link to comment Share on other sites More sharing options...
mrchrismas 1 Share Posted March 20, 2023 1 hour ago, una_maquina said: Oh, maybe you can pass 3 arguments to sleepWhile and it automatically randomizes the sleep times (didn't know that), but the fact that you've put 30000 and 5000 as the other number, might be the problem, because it's 30 secs and 5 secs. 30000, 5000 just means that he'll have a timeout for 30 seconds and it will poll every 5 seconds if i understood the documentation correctly una_maquina 1 Link to comment Share on other sites More sharing options...
una_maquina 35 Share Posted March 20, 2023 1 minute ago, mrchrismas said: 30000, 5000 just means that he'll have a timeout for 30 seconds and it will poll every 5 seconds if i understood the documentation correctly I see, that makes sense, still though fixed sleeping times like that is unadvisable, better to always have random sleep times with Calculation.random(). As for why he's having that bug is probably due to something being wrong in the canSmelt() method. Link to comment Share on other sites More sharing options...
LoremIpsum213 0 Author Share Posted March 20, 2023 (edited) In the end i solved it as following: //get furnace object in Area (= special class that uses Dreambot Area API) GameObject furnace = Area.GetInteractionObject(); // check if we are within reach, otherwise, keep walking to destination if(furnace != null && furnace.distance() < 10) { // if furnace was clicked if(furnace.interact()) { // succesfully clicked on furnace, now wait until widget menu is opened sleepUntil(() -> Widgets.isOpen(), 10000, 500); WidgetChild selectionbox = Widgets.getWidgetChild(270, widgetMap.get(Bar.getID())); if (selectionbox != null && selectionbox.isVisible() && selectionbox.interact()) { //wait until done smelting or when a lvl-up dialogue pops up sleepUntil(() -> !canSmelt() || Dialogues.canContinue(), 60000, 5000); } } } I guess this code can be repeated for many different activities within the game. Let me know if i did something else kinda weird. Edited March 20, 2023 by LoremIpsum213 Link to comment Share on other sites More sharing options...
LoremIpsum213 0 Author Share Posted March 20, 2023 3 hours ago, una_maquina said: I see, that makes sense, still though fixed sleeping times like that is unadvisable, better to always have random sleep times with Calculation.random(). As for why he's having that bug is probably due to something being wrong in the canSmelt() method. the fixed sleeping time, is just the timeout, so that means it will always exit after 60 seconds in my latest code change. But 99.9% of time, everything has been smelted by then and the canSmelt function will return false (which is checked every 5 seconds). Perhaps I should randomize that a little bit. so i don't always walk away exactly at the same time. Link to comment Share on other sites More sharing options...
hashbang 8 Share Posted March 22, 2023 Look into using the `reset` condition of the sleepUntil method. This way you can sleepUntil your inventory contains no more resources (raw fish, ores etc) with a low timeout (5 seconds for example), but reset the timeout if you are ever animating. Something like this could work: static int SMELTING_ANIMATION_ID = 899 Player me = Players.getLocal(); Sleep.sleepUntil(me::isStandingStill, () -> me.getAnimation() == SMELTING_ANIMATION_ID, 10000, 150, 3); LoremIpsum213 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now