Jump to content

Checking if Xp has been gained In past (X) milliseconds


Recommended Posts

Posted (edited)

Method

public boolean IsGainingXp (int CheckTime)
    {
        int XpChange;
        int CurrentXp = getSkills().getTotalExperience();
        try {
            sleep(CheckTime);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        int LaterXp = getSkills().getTotalExperience();
        XpChange = LaterXp-CurrentXp;

        if(XpChange>0) {
            return true;
        }
        else return false;
    }

Example of use

while (IsGainingXp(3000)==true)
{
    log ("we have gained xp in the past 3 seconds");
}

log ("we stopped gaining xp");

 

Sorry if this is useless but I couldn't use a check for animations so I made this to see if I gained XP recently. If someone has a better way please post.

Edited by mikehamz
Posted

Hmm

You might not want to block execution.

You could create a global variable which keeps track of the current XP. Then you can make your check to see if your new XP is greater the the current. If it is, then just set your current XP to your new XP.

 

Also:

while(test() == true)
  
// is equivalent to
  
while(test())

 

  • Like 1
Posted
56 minutes ago, dreameo said:

Hmm

You might not want to block execution.

You could create a global variable which keeps track of the current XP. Then you can make your check to see if your new XP is greater the the current. If it is, then just set your current XP to your new XP.

 

Also:


while(test() == true)
  
// is equivalent to
  
while(test())

 

It is actually funny you post here because I saw your comment that I thought was really good that didn't block execution for checking idle time with animations, but it was after I had made this.

Quote

 private boolean idleFor(int millis){

        if(myPlayer().isAnimating())
        {
            timeSinceAnimation = System.currentTimeMillis();
        }
        else
        {
            timeSinceIdle = System.currentTimeMillis();
        }

        return timeSinceAnimation + millis < timeSinceIdle;
    }

Would editing your method to something like this work for checking Xp in stuff that doesn't do animations?

 private boolean NoXpFor(int millis){

        if(getSkills().getTotalExperience() > globalXp)
        {
            TimeSinceXpGain = System.currentTimeMillis();
            globalxp = getSkills().getTotalExperience();
        }
        else
        {
            TimeSinceNoXp = System.currentTimeMillis();
        }

        return TimeSinceXpGain + millis < TimeSinceNoXp;
   
    }


 

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