justanotherkid Posted April 18, 2016 Share Posted April 18, 2016 (edited) i'm trying to smelt gold amulets for free crafting exp but the script will not sleep when smelting here is the portion so far i know 10 seconds isn't enough to craft 27 amulets but it's relooping after like 2 amulets which is like 4 seconds case MAKEAMULETS: getWalking().webWalk(new Position[] {furnaceposition}); if(getWidgets().isVisible(446, 32)) { getWidgets().interact(446,32,"Make-X"); sleep(random(300,500)); if(getWidgets().isVisible(162, 33)) { getKeyboard().typeString("27", true); } new ConditionalSleep(10000) { @Override public boolean condition() throws InterruptedException { return !myPlayer().isAnimating(); } }.sleep(); } else { Entity furnace = objects.closest("Furnace"); getInventory().interact("Use", "Gold bar"); sleep(random(200,300)); furnace.interact("Use"); } break; Edited April 18, 2016 by justanotherkid Quote Link to comment Share on other sites More sharing options...
The Hero of Time Posted April 18, 2016 Share Posted April 18, 2016 (edited) while(myPlayer().isAnimating()) { sleep(500); } should work, idk if its clean though with ur conditional sleep it will wait for the remaining of the 10seconds if you're done smelting Edited April 18, 2016 by The Hero of Time Quote Link to comment Share on other sites More sharing options...
justanotherkid Posted April 18, 2016 Author Share Posted April 18, 2016 (edited) while(myPlayer().isAnimating()) { sleep(500); } should work, idk if its clean though with ur conditional sleep it will wait for the remaining of the 10seconds if you're done smelting no, that didn't work either but there is a workaround i used to return !getInventory().contains("gold bars") || getDialogue().inDialogue(); // the dialogue part is for when it levels up crafting Edited April 18, 2016 by justanotherkid Quote Link to comment Share on other sites More sharing options...
The Hero of Time Posted April 18, 2016 Share Posted April 18, 2016 no, that didn't work either but there is a workaround i used to return !getInventory().contains("gold bars") || getDialogue().inDialogue(); // the dialogue part is for when it levels up crafting when im cooking fish, i use the while loop to check if i still have raw fish. when it levels up i check on the level-up widget, not indialoge, but i guess it both works Quote Link to comment Share on other sites More sharing options...
Woody Posted April 18, 2016 Share Posted April 18, 2016 The character only animates when it's placing the ore in the furnace, therefore it will only wait for a very short period before interacting with the furnace again. Quote Link to comment Share on other sites More sharing options...
Final Posted April 18, 2016 Share Posted April 18, 2016 (edited) EDIT: The following eliminates the issue of sleeping while proceeding with an action, as well as eliminating the issue of animations occurring only for a short period of time. When crafting you expect an experience gain every few seconds, let's use this to build a predetermined time in the future which we can check our previous crafting experience with our current crafting experience. We simply cache our crafting experience every 'check' before we are going to gain any new experience, every check, we get the current system time and add 4 - 6 seconds (the timeout essentially) to get our time for the next 'check'. In pseudo code the following would be it's own method: IF bar count = 0 THEN RETURN false END IF IF CurrentTime > LastCheckedTime + timeout THEN IF CurrentCraftingXP > PreviousCraftingXP THEN PreviousCraftingXP = CurrentCraftingXP LastCheckedTime = CurrentTime RETURN TRUE ELSE RETURN FALSE END IF ELSE RETURN TRUE END IF Edited April 18, 2016 by Final 1 Quote Link to comment Share on other sites More sharing options...
Woody Posted April 18, 2016 Share Posted April 18, 2016 while(myPlayer().isAnimating()) { sleep(500); } should work, idk if its clean though with ur conditional sleep it will wait for the remaining of the 10seconds if you're done smelting That will not work for his purpose. Quote Link to comment Share on other sites More sharing options...
The Hero of Time Posted April 18, 2016 Share Posted April 18, 2016 while(getInventory().contains("Gold bar") { sleep(500); } Quote Link to comment Share on other sites More sharing options...
Woody Posted April 18, 2016 Share Posted April 18, 2016 while(getInventory().contains("Gold bar") { sleep(500); } Nope. If you really want to use a while loop, always have a backup so it doesn't get stuck in the loop. Quote Link to comment Share on other sites More sharing options...
Final Posted April 18, 2016 Share Posted April 18, 2016 while(getInventory().contains("Gold bar") { sleep(500); } I wouldn't use this. Just because the user has a gold bar doesn't mean that he's smelting, something such as a level up or unwanted interaction could disrupt this, furthermore it's a while loop and there's clear reasons of why not to use a while loop within a script (a while loop). Quote Link to comment Share on other sites More sharing options...
Woody Posted April 18, 2016 Share Posted April 18, 2016 I wouldn't use this. Just because the user has a gold bar doesn't mean that he's smelting, something such as a level up or unwanted interaction could disrupt this, furthermore it's a while loop and there's clear reasons of why not to use a while loop within a script (a while loop). Why r u stalking me? Quote Link to comment Share on other sites More sharing options...
The Hero of Time Posted April 18, 2016 Share Posted April 18, 2016 (edited) Nope. If you really want to use a while loop, always have a backup so it doesn't get stuck in the loop. obviously, but OP already has that as far as i know, he already has the logic for leveling up @op this is how i have it Edited April 18, 2016 by The Hero of Time Quote Link to comment Share on other sites More sharing options...
Woody Posted April 18, 2016 Share Posted April 18, 2016 (edited) obviously, but OP already has that as far as i know, he already has the logic for leveling up @op this is how i have it You are making the same mistake for using while loop. You shouldn't use a while loop for sleeping purpose. Edited April 18, 2016 by Woody Quote Link to comment Share on other sites More sharing options...
The Hero of Time Posted April 18, 2016 Share Posted April 18, 2016 (edited) . Edited April 18, 2016 by The Hero of Time Quote Link to comment Share on other sites More sharing options...
Explv Posted April 18, 2016 Share Posted April 18, 2016 (edited) i'm trying to smelt gold amulets for free crafting exp but the script will not sleep when smelting here is the portion so far i know 10 seconds isn't enough to craft 27 amulets but it's relooping after like 2 amulets which is like 4 seconds case MAKEAMULETS: getWalking().webWalk(new Position[] {furnaceposition}); if(getWidgets().isVisible(446, 32)) { getWidgets().interact(446,32,"Make-X"); sleep(random(300,500)); if(getWidgets().isVisible(162, 33)) { getKeyboard().typeString("27", true); } new ConditionalSleep(10000) { @Override public boolean condition() throws InterruptedException { return !myPlayer().isAnimating(); } }.sleep(); } else { Entity furnace = objects.closest("Furnace"); getInventory().interact("Use", "Gold bar"); sleep(random(200,300)); furnace.interact("Use"); } break; Easiest way imo is just to do a long sleep, and check if you still have gold bars / have leveled up: if(getKeyboard().typeString("27")){ new ConditionalSleep(100_000){ @Override public boolean condition() throws InterruptedException { return !getInventory().contains("Gold bar") || getDialouges().isPendingContinuation(); } }.sleep(); } Edited April 18, 2016 by Explv 1 Quote Link to comment Share on other sites More sharing options...