Mofo0 Posted January 25, 2016 Posted January 25, 2016 My script is using a furnace and I am currently using if (!myPlayer().isAnimating()) to check if I am already using the furnace. It works most of the time but it occasionally breaks and tries to restart the crafting while it already is crafting. I am guessing it is because there is a small delay between the smithing animations so the script will think the player is not animating. I have experimented with sleeps and seen into getAnimationDelay() but cannot figure it out. Any help is appreciated 1
Chris Posted January 25, 2016 Posted January 25, 2016 (edited) public class Timer { private long period; private long start; public Timer(long period) { this.period = period; this.start = System.currentTimeMillis(); } public long getElapsed() { return System.currentTimeMillis() - this.start; } public long getRemaining() { return this.period - this.getElapsed(); } public boolean isRunning() { return this.getElapsed() <= this.period; } public void setPeriod(long period) { this.period = period; } public void reset() { this.start = System.currentTimeMillis(); } public static String format(long milliSeconds) { long secs = milliSeconds / 1000L; return String.format("%02d:%02d:%02d", secs / 3600L, secs % 3600L / 60L, secs % 60L); } } //method public boolean isSmithing() { boolean isSmith = false; Timer timer = new Timer(1800); while (timer.isRunning() && !isSmith) { isSmith = myPlayer().getAnimation() != -1 ? true : isSmith; } return isSmith; } Edited January 25, 2016 by Sinatra 3
Mofo0 Posted January 25, 2016 Author Posted January 25, 2016 public class Timer { private long period; private long start; public Timer(long period) { this.period = period; this.start = System.currentTimeMillis(); } public long getElapsed() { return System.currentTimeMillis() - this.start; } public long getRemaining() { return this.period - this.getElapsed(); } public boolean isRunning() { return this.getElapsed() <= this.period; } public void setPeriod(long period) { this.period = period; } public void reset() { this.start = System.currentTimeMillis(); } public static String format(long milliSeconds) { long secs = milliSeconds / 1000L; return String.format("%02d:%02d:%02d", secs / 3600L, secs % 3600L / 60L, secs % 60L); } } //method public boolean isSmithing() { boolean isSmith = false; Timer timer = new Timer(1800); while (timer.isRunning() && !isSmith) { isSmith = myPlayer().getAnimation() != -1 ? true : isSmith; } return isSmith; } Add a timer Thanks for the help, I'll try this out
Acerd Posted January 25, 2016 Posted January 25, 2016 (edited) Timer timer = new Timer(0); if (myPlayer().isAnimating()) timer.reset(); if (timer.getElapsed() > MS) { //do shit } else { //w/e } Edited January 25, 2016 by Assnerd
Explv Posted January 25, 2016 Posted January 25, 2016 (edited) My script is using a furnace and I am currently using if (!myPlayer().isAnimating()) to check if I am already using the furnace. It works most of the time but it occasionally breaks and tries to restart the crafting while it already is crafting. I am guessing it is because there is a small delay between the smithing animations so the script will think the player is not animating. I have experimented with sleeps and seen into getAnimationDelay() but cannot figure it out. Any help is appreciated Just do a really long ConditionalSleep. For example if you are smelting Gold bars you could do something like: private final ConditionalSleep SMELTING_SLEEP = new ConditionalSleep(100_000) { @Override public boolean condition() throws InterruptedException { return !getInventory().contains("Gold ore"); } }; When you start smelting, you can call: SMELTING_SLEEP.sleep(); And it will then sleep for up to 100 seconds, or until the inventory no longer contains Gold Ore Edited January 25, 2016 by Explv 1
Mofo0 Posted January 26, 2016 Author Posted January 26, 2016 Thanks for all the help guys, figured it out