Jinjo Posted August 26, 2015 Posted August 26, 2015 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.
Czar Posted August 26, 2015 Posted August 26, 2015 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. 1
Flamezzz Posted August 26, 2015 Posted August 26, 2015 (edited) You could listen for game messages.I think getAnimation() != -1 is exactly what isAnimating() does Edited August 26, 2015 by Flamezzz
Jinjo Posted August 26, 2015 Author Posted August 26, 2015 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 1
Eliot Posted August 26, 2015 Posted August 26, 2015 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 }
Zee Best Posted August 26, 2015 Posted August 26, 2015 (edited) 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 August 26, 2015 by Zee Best
Eliot Posted August 26, 2015 Posted August 26, 2015 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.
LoudPacks Posted August 27, 2015 Posted August 27, 2015 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 }
Jinjo Posted August 27, 2015 Author Posted August 27, 2015 (edited) 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 August 27, 2015 by Jinjo
Zee Best Posted August 28, 2015 Posted August 28, 2015 (edited) 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 August 28, 2015 by Zee Best
LoudPacks Posted August 29, 2015 Posted August 29, 2015 Because what if the script doesn't start smelting at all? Or events that interrupt actions such as levelling 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.
Woody Posted August 29, 2015 Posted August 29, 2015 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; }
Bobrocket Posted August 29, 2015 Posted August 29, 2015 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 1
Zee Best Posted August 30, 2015 Posted August 30, 2015 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?
Woody Posted August 30, 2015 Posted August 30, 2015 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.