Jump to content

animation timer


eleax

Recommended Posts

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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

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