eleax Posted March 2, 2015 Share Posted March 2, 2015 Can someone walk me through the code for an animation timer to assist with cooking or smelting? myPlayer().isAnimating(); really isnt cutting it lol Quote Link to comment Share on other sites More sharing options...
Mysteryy Posted March 2, 2015 Share Posted March 2, 2015 Make a new thread. In the thread have it looping checking if your player is animating. If the player is animating, set the lastAnimation to the current time. Done. Quote Link to comment Share on other sites More sharing options...
Botre Posted March 2, 2015 Share Posted March 2, 2015 (edited) Not sure what you are asking for. Here's a simple timer class though: /** * * @author Bjorn Krols (Botre) * */ public final class SimpleTimer { private long st; public SimpleTimer() { start(); } /** * Starts the timer. */ public void start() { st = System.currentTimeMillis(); } /** * Restarts the timer. */ public void reset() { start(); } /** * @return The elapsed amount of seconds since the timer was started. */ public long getElapsedSeconds() { return (System.currentTimeMillis() - st) / 1000; } /** * @return The amount of n/s since the timer was started. */ public double getPerSecond(double n) { return n / getElapsedSeconds(); } /** * @return The amount of n/h since the timer was started. */ public int getPerHour(double n) { return (int) (getPerSecond(n) * 3600); } } Edited March 2, 2015 by Botre Quote Link to comment Share on other sites More sharing options...
Mysteryy Posted March 2, 2015 Share Posted March 2, 2015 Not sure what you are asking for. Here's a simple timer class though: /** * * @author Bjorn Krols (Botre) * */public final class SimpleTimer { private long st; public SimpleTimer() { start(); } /** * Starts the timer. */ public void start() { st = System.currentTimeMillis(); } /** * Restarts the timer. */ public void reset() { start(); } /** * @return The elapsed amount of seconds since the timer was started. */ public long getElapsedSeconds() { return (System.currentTimeMillis() - st) / 1000; } /** * @return The amount of n/s since the timer was started. */ public double getPerSecond(double n) { return n / getElapsedSeconds(); } /** * @return The amount of n/h since the timer was started. */ public int getPerHour(double n) { return (int) (getPerSecond(n) * 3600); }} I took it as, how do I make an action listener to track the time of last action. Animation not action* 2 Quote Link to comment Share on other sites More sharing options...
Xellic Posted March 2, 2015 Share Posted March 2, 2015 Make a new thread. In the thread have it looping checking if your player is animating. If the player is animating, set the lastAnimation to the current time. Done. Would you be able to elaborate on what setting lastAnimation to the current time would do? Just shows how long it takes for the player to animate? Quote Link to comment Share on other sites More sharing options...
Tyrael Posted March 2, 2015 Share Posted March 2, 2015 Why isn't { myPlayer().isAnimating(); } cutting it? I'd think this would sit higher up in your onLoop method and just sleep it if you're still animating. If it's the script wasting too much time that you're worried about, just return a lower ms while isAnimating is true. Quote Link to comment Share on other sites More sharing options...
Joseph Posted March 2, 2015 Share Posted March 2, 2015 Why isn't { myPlayer().isAnimating(); } cutting it? I'd think this would sit higher up in your onLoop method and just sleep it if you're still animating. If it's the script wasting too much time that you're worried about, just return a lower ms while isAnimating is true. ok when you cook an inv of food in rs. You cook a fish (anim) stop for a sec (non-anim) and repeat. So that one sec of non-animating fucks you over with the method isAnimating(). what i do sometimes i use a boolean and a timer. Every time it animates it reset timer. And i do a simple if statement check saying if the timer > 3 then my player isnt doing anything. i use the boolean for something. Just be cleaver about it :p Quote Link to comment Share on other sites More sharing options...
Tyrael Posted March 2, 2015 Share Posted March 2, 2015 (edited) cook a fish (anim) stop for a sec (non-anim) and repeat That's what I was missing, and that is a big game changer. In that case, I would check for all external variables that would interrupt cooking being in place and let it ride. Check if your current tile is changed, check if your fire has died (if using a fire), and stick with the isAnimating() function. EDIT: Please do not use a timer. For the love of fucking God. Edited March 2, 2015 by hitmanice Quote Link to comment Share on other sites More sharing options...
Mysteryy Posted March 2, 2015 Share Posted March 2, 2015 Would you be able to elaborate on what setting lastAnimation to the current time would do? Just shows how long it takes for the player to animate? If you have something to set the lastAnimation to the current time, then at any given time you can call something like: if(Player.getTimeSinceLastAnimation() > 1000) In other words, if your player has not animated in over a second. I have used something like this for ages to track all kinds of things that otherwise would not be trackable using the OSB api. timeSinceLastAnimation timeSinceLastInCombat timeSinceLastMovement You can apply this same concept to other things besides the player as well. Why isn't { myPlayer().isAnimating(); } cutting it? I'd think this would sit higher up in your onLoop method and just sleep it if you're still animating. If it's the script wasting too much time that you're worried about, just return a lower ms while isAnimating is true. Read the above. myPlayer.isAnimating will only return true if at the exact time you call it, your player is animating. You need to know how long it has been since your player animated. Using isAnimating can cause scripts such as fishers and cookers to spam click and screw up easily. 1 Quote Link to comment Share on other sites More sharing options...