Jump to content

animation timer


Recommended Posts

Posted (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 by Botre
Posted

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*

  • Like 2
Posted

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?

Posted

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

Posted (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 by hitmanice
Posted

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.

  • Like 1

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...