Jump to content

isAnimating()


Jinjo

Recommended Posts

So I'm making this first project smelter which I've nearly finished but I'm kind of stuck on this last problem.

 

For some reason the boolean isAnimating() isn't working for me. It somehow always returns false even though I'm busy melting?

Or maybe it's flickering between false and true while melting?

 

Anyhow I've tried replacing it by getAnimation() == -1 but that doesn't seem to help aswell.

 

 

Any ideas here? I can post the source if needed.

Link to comment
Share on other sites

Common issue with smelting and animation-related scripts,

 

the usual response you will get, is to make a timer, so every time the animation isn't -1, set a timer for a few seconds which will count down. If timer reaches 0, it means you aren't smelting anymore, if the timer is above 0, make the script sleep.

 

Or, another perspective is to flag the player when smelting event begins, and only un-flag it when certain criteria are met; e.g. user run out of ore, user isn't interacting etc.

  • Like 1
Link to comment
Share on other sites

Common issue with smelting and animation-related scripts,

 

the usual response you will get, is to make a timer, so every time the animation isn't -1, set a timer for a few seconds which will count down. If timer reaches 0, it means you aren't smelting anymore, if the timer is above 0, make the script sleep.

 

Or, another perspective is to flag the player when smelting event begins, and only un-flag it when certain criteria are met; e.g. user run out of ore, user isn't interacting etc.

 

I'll look up on how to make a timer, seems easier than the flag thingy :)

  • Like 1
Link to comment
Share on other sites

Perhaps try doing this with a conditional sleep, something like below might give you a rough idea of what you could do.

//declare this earlier
boolean isAnimating = false;

// later, use something like this to check if you're animating.
// play with the sleep values to get it just right.
if (!script.myPlayer().isAnimating()) {
  new ConditionalSleep(1200, 1700) {
    @Override
    public boolean condition() throws InterruptedException {
      isAnimating = script.myPlayer().isAnimating();
      return isAnimating;
    }
  }.sleep();
}
if (!isAnimating) {
  // we are done animating
} else {
  // we are still smelting
}
Link to comment
Share on other sites

 

Perhaps try doing this with a conditional sleep, something like below might give you a rough idea of what you could do.

//declare this earlier
boolean isAnimating = false;

// later, use something like this to check if you're animating.
// play with the sleep values to get it just right.
if (!script.myPlayer().isAnimating()) {
  new ConditionalSleep(1200, 1700) {
    @Override
    public boolean condition() throws InterruptedException {
      isAnimating = script.myPlayer().isAnimating();
      return isAnimating;
    }
  }.sleep();
}
if (!isAnimating) {
  // we are done animating
} else {
  // we are still smelting
}

 

Eww, bit of a horrible way to use it, sleep is a boolean that blocks until the timer is reached, therefore;

        final ConditionalSleep smelting = new ConditionalSleep(random(1500, 1800)) {
	
                @Override
		public boolean condition()
		{
			return myPlayer().isAnimating();
		}
	};
	if(smelting.sleep())
		log("We are smelting");
	else
		log("We are idle.");
Edited by Zee Best
Link to comment
Share on other sites

 

Eww, bit of a horrible way to use it, sleep is a boolean that blocks until the timer is reached, therefore;

        final ConditionalSleep smelting = new ConditionalSleep(random(1500, 1800)) {
	
                @Override
		public boolean condition()
		{
			return myPlayer().isAnimating();
		}
	};
	if(smelting.sleep())
		log("We are smelting");
	else
		log("We are idle.");

That is definitely a cleaner solution, but I feel my example code may be a bit more clear to someone asking a question such as this.

Link to comment
Share on other sites

So I'm making this first project smelter which I've nearly finished but I'm kind of stuck on this last problem.

 

For some reason the boolean isAnimating() isn't working for me. It somehow always returns false even though I'm busy melting?

Or maybe it's flickering between false and true while melting?

 

Anyhow I've tried replacing it by getAnimation() == -1 but that doesn't seem to help aswell.

 

 

Any ideas here? I can post the source if needed.

 

why not just check if the player inventory contains ore? Rather than using the animation to see if they are done smithing, check if they are all out of items to smith with:

 

if (!players.getInventory().containsItemWithName("ore"))

{

          // now im not smithing because i have no ore

}

Link to comment
Share on other sites

 

Eww, bit of a horrible way to use it, sleep is a boolean that blocks until the timer is reached, therefore;

        final ConditionalSleep smelting = new ConditionalSleep(random(1500, 1800)) {
	
                @Override
		public boolean condition()
		{
			return myPlayer().isAnimating();
		}
	};
	if(smelting.sleep())
		log("We are smelting");
	else
		log("We are idle.");

 

Nice one, I see how this can work.

Edited by Jinjo
Link to comment
Share on other sites

why not just check if the player inventory contains ore? Rather than using the animation to see if they are done smithing, check if they are all out of items to smith with:

 

if (!players.getInventory().containsItemWithName("ore"))

{

          // now im not smithing because i have no ore

}

 

 

Because what if the script doesn't start smelting at all? Or events that interrupt actions such as levelling up.

Edited by Zee Best
Link to comment
Share on other sites

Because what if the script doesn't start smelting at all? Or events that interrupt actions such as levellingarrow-10x10.png up.

 

This line of code wouldn't be called until after you already start smithing so that takes care of that. Leveling up is irrelevent as it has nothing to do with weather or not you have ore in your inventory. This solution that I provided does what your asking. 

Link to comment
Share on other sites

public static boolean isBusy() throws InterruptedException {
		boolean flag = false;

		for(int i = 0; i < 4; i++) {
			if(api.myPlayer().getAnimation() != -1) {
				flag = true;
				break;
			}
			API.sleep(API.random(400, 600));
		}
		return flag;
	}
public static boolean iBusy() throws InterruptedException {

    for (int i = 0; i < 4; i++) {
        if (myPlayer().isAnimating()) return true;
        sleep(420);
    }
    return false;
}

Gotta work on writing less code for the same objective fam <3

  • Like 1
Link to comment
Share on other sites

This line of code wouldn't be called until after you already start smithing so that takes care of that. Leveling up is irrelevent as it has nothing to do with weather or not you have ore in your inventory. This solution that I provided does what your asking. 

 

Yes, but you could click to smelt, then level up and you'd still have ores in your inventory but you wouldn't be smelting. The solution you posted is idiotic. The only way that would work would be to store the amount of ores you have and keep checking for a change within a certain time else smelt again, which isn't what you said.

 

 

public static boolean isBusy() throws InterruptedException {
		boolean flag = false;

		for(int i = 0; i < 4; i++) {
			if(api.myPlayer().getAnimation() != -1) {
				flag = true;
				break;
			}
			API.sleep(API.random(400, 600));
		}
		return flag;
	}

 

 

That's horrible, why would you sleep in a method that's trying to work out if you're busy?

Link to comment
Share on other sites

 

That's horrible, why would you sleep in a method that's trying to work out if you're busy?

It's obviously that you do not understand the method.

 

Instead of judging my work, you should try to read it and learn something of it. IF you later come with a better method than mine, please share it with us. Don't pretend to be something you are not. 

 

Go and learn some java.

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