ridooz Posted September 16, 2015 Share Posted September 16, 2015 Hi i'm new to scripting at osbot.org. Trying to learn the basic stuff. Created a willow cutter and banker at draynor. Now moved onto a steel smelter at edgeville (just to get more knowledge and the basics) I just have a problem with smelting since your animations stop for a second when smelting bars. How can i prevent this? Here's an example of my code: if (!player.isAnimating()) { if (!player.isMoving()) { // && System.currentTimeMillis() > (player.getAnimation() + 3000) if (options == null) { furnace.interact("Smelt"); sleep(3000); } if (options != null) { sleep(3000); options.interact("Smelt X Steel"); sleep(random(2000, 2000)); keyboard.typeString("" + random(29, 99), true); sleep(3000); } //sleep(random(1000, 1000)); } } It just hits smelt at furnace again when it has smelted 1 bar. Thanks in advance Quote Link to comment Share on other sites More sharing options...
Flamezzz Posted September 16, 2015 Share Posted September 16, 2015 A common issue ;)http://osbot.org/forum/topic/80839-isanimating/ Quote Link to comment Share on other sites More sharing options...
ridooz Posted September 16, 2015 Author Share Posted September 16, 2015 A common issue http://osbot.org/forum/topic/80839-isanimating/ I've tried implementing a timer, without success. Can you help explaining further how i can implement in my code possibly ? Quote Link to comment Share on other sites More sharing options...
Joseph Posted September 16, 2015 Share Posted September 16, 2015 (edited) A common issue http://osbot.org/forum/topic/80839-isanimating/ tbh i didnt like any of those answers. Maybe except for the condition sleep. Personally i would just use a timer. And a simple boolean check to weather it should interaction or keep waiting. private long waitTimer = System.currentTimeMillis(); if (player animtaing) { restart timer } else if (System.currentTimeMillis() - this.waitTimer > 3000){ start interaction } edit: if you dont understand how to make the timer concept. Here a simple timer class. Its been passed around for ages 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", new Object[] { Long.valueOf(secs / 3600L), Long.valueOf(secs % 3600L/ 60L), Long.valueOf(secs % 60L) }); } } Edited September 16, 2015 by Joseph Quote Link to comment Share on other sites More sharing options...
ridooz Posted September 16, 2015 Author Share Posted September 16, 2015 Still doesn't work. What am i doing wrong here? if (!player.isAnimating()) { if (!player.isMoving()) { if(System.currentTimeMillis() - this.waitTimer > 3000){ if (options == null) { furnace.interact("Smelt"); sleep(3000); } if (options != null) { sleep(3000); options.interact("Smelt X Steel"); sleep(random(2000, 2000)); keyboard.typeString("" + random(29, 99), true); sleep(3000); } } else{ waitTimer = System.currentTimeMillis(); } } } Quote Link to comment Share on other sites More sharing options...
herojord Posted September 19, 2015 Share Posted September 19, 2015 (edited) My if else order: if(myPlayer().isAnimating()) { // Reset timer } else if (waitTimer.getElapsed() > 3000) { // Smithing code here } sleep(1000); } Edited September 19, 2015 by herojord Quote Link to comment Share on other sites More sharing options...
ridooz Posted September 29, 2015 Author Share Posted September 29, 2015 Fixed it my own way without timer or conditionsleep Quote Link to comment Share on other sites More sharing options...
Bobrocket Posted October 1, 2015 Share Posted October 1, 2015 (edited) You could have something like this: import org.osbot.rs07.script.MethodProvider; public class ConditionalTimer { private int time, step, elapsed; private TimerCondition condition; public ConditionalTimer(int t, TimerCondition cond, int s) { time = t; condition = cond; step = s; } public boolean run() throws InterruptedException { elapsed = 0; while (time <= elapsed) { if (condition.condition()) return true; MethodProvider.sleep(step); } return false; } public int getElapsed() { return elapsed; } } interface TimerCondition { public boolean condition(); } Example: if (new ConditionalTimer(3000, () -> (myPlayer().isAnimating()), 50).run()) { //we're animating } else { //we're not animating (we haven't been animating for 3000 ms) } Edited October 1, 2015 by Bobrocket Quote Link to comment Share on other sites More sharing options...