Jump to content

Checking Idle time?


Recommended Posts

Posted
11 minutes ago, Explv said:

Seems like you are doing something wrong or need to improve your script.

Why would you need to detect if you are idle for 7 seconds? Makes no sense to me

I think like a failsafe or something. But 7 secs seems too low. E.g some scripts auto stops the script if no xp has been gained over a period of 7-10 minutes. In case it fucked up somewhere

  • Like 1
Posted

Managed to solve it with something kind of what @Explv suggested,
 

if(myPlayer().isMoving() || myPlayer().isAnimating()){
                           time = System.currentTimeMillis();
                         }
                         else if(!myPlayer().isAnimating() && !myPlayer().isMoving()){
                           timeToMove=System.currentTimeMillis();
                           if(timeToMove>time+5000){
                             //Code
                           }
                         }
}

Mabye not the most elegant solution, but i gets the job done while i think of a better Solution :)

Posted (edited)

It's a good solution, just be clear on how you write it so you don't get confused later (variable naming).

time variables have to be global.

 

  private boolean idleFor(int millis){

        if(myPlayer().isAnimating() || myPlayer.isMoving())
        {
            timeSinceAction = System.currentTimeMillis();
        }
        else
        {
            timeSinceIdle = System.currentTimeMillis();
        }

        return timeSinceAction + millis < timeSinceIdle;
    }

 

Edited by dreameo
  • Like 2
Posted
17 hours ago, dreameo said:

It's a good solution, just be clear on how you write it so you don't get confused later (variable naming).

time variables have to be global.

 


  private boolean idleFor(int millis){

        if(myPlayer().isAnimating() || myPlayer.isMoving())
        {
            timeSinceAction = System.currentTimeMillis();
        }
        else
        {
            timeSinceIdle = System.currentTimeMillis();
        }

        return timeSinceAction + millis < timeSinceIdle;
    }

 

Hmm this was actually very neat, im gonna go ahead and save this snippet, thanks! :D

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...