Juggles Posted February 9, 2017 Share Posted February 9, 2017 (edited) Very simple snippet of an animation timer I used in one of my scripts. Useful for things such as fletching, crafting, etc. Things where the animation returns -1 even when it is still doing an action. Define variable long lastAnimation = 0; Usage: if (myPlayer().isAnimating()) { lastAnimation = System.currentTimeMillis(); } else if (System.currentTimeMillis() > (lastAnimation + int)){ //do action } int is the amount of time to sleep before it needs to click again if you haven't animated. For example, if you wanted it to click after 2 seconds of not animating, you would put 2000 there. Edited February 9, 2017 by Juggles 15 Quote Link to comment Share on other sites More sharing options...
Eagle Scripts Posted February 9, 2017 Share Posted February 9, 2017 Thanks for sharing 1 Quote Link to comment Share on other sites More sharing options...
DrDu Posted February 9, 2017 Share Posted February 9, 2017 thanks fam Quote Link to comment Share on other sites More sharing options...
InsomniakSam Posted February 9, 2017 Share Posted February 9, 2017 Appreciated Quote Link to comment Share on other sites More sharing options...
Juggles Posted August 26, 2017 Author Share Posted August 26, 2017 Bumping Quote Link to comment Share on other sites More sharing options...
jca Posted December 5, 2017 Share Posted December 5, 2017 Thanks... helped a lot. Quote Link to comment Share on other sites More sharing options...
Explv Posted December 5, 2017 Share Posted December 5, 2017 On 2/9/2017 at 4:22 AM, Juggles said: Very simple snippet of an animation timer I used in one of my scripts. Useful for things such as fletching, crafting, etc. Things where the animation returns -1 even when it is still doing an action. Define variable long lastAnimation = 0; Usage: if (myPlayer().isAnimating()) { lastAnimation = System.currentTimeMillis(); } else if (System.currentTimeMillis() > (lastAnimation + int)){ //do action } int is the amount of time to sleep before it needs to click again if you haven't animated. For example, if you wanted it to click after 2 seconds of not animating, you would put 2000 there. 4 hours ago, jca said: Thanks... helped a lot. This just looks like an over complicated, and less efficient way of writing: if (myPlayer().isAnimating()) { sleep(2000); } else { // do action } 1 Quote Link to comment Share on other sites More sharing options...
jca Posted December 7, 2017 Share Posted December 7, 2017 (edited) On 05/12/2017 at 2:48 PM, Explv said: This just looks like an over complicated, and less efficient way of writing: if (myPlayer().isAnimating()) { sleep(2000); } else { // do action } I was under the impression sleep() was discouraged in place of ConditionalSleep() Then with ConditionalSleep() I wasn't able to find the right condition that would allow me to pick an item up after combat, thus a timer seemed to come in handy to delay the action of combat so bot has time to pick up item. Please enlighten me if this is not the case. Also thanks for the maps - helped heaps. EDIT: Also, surely this would not help in the case of picking up an item after combat? If the player is fighting then isAnimating() = true, but as soon as it stops fighting isAnimating() = false, which lets it proceed. Edited December 7, 2017 by jca Quote Link to comment Share on other sites More sharing options...
Juggles Posted December 7, 2017 Author Share Posted December 7, 2017 1 hour ago, jca said: I was under the impression sleep() was discouraged in place of ConditionalSleep() Then with ConditionalSleep() I wasn't able to find the right condition that would allow me to pick an item up after combat, thus a timer seemed to come in handy to delay the action of combat so bot has time to pick up item. Please enlighten me if this is not the case. Also thanks for the maps - helped heaps. EDIT: Also, surely this would not help in the case of picking up an item after combat? If the player is fighting then isAnimating() = true, but as soon as it stops fighting isAnimating() = false, which lets it proceed. Check if item exists Quote Link to comment Share on other sites More sharing options...
ownage999 Posted December 7, 2017 Share Posted December 7, 2017 bump the bump :^) Quote Link to comment Share on other sites More sharing options...
Explv Posted December 7, 2017 Share Posted December 7, 2017 (edited) 2 hours ago, jca said: I was under the impression sleep() was discouraged in place of ConditionalSleep() Then with ConditionalSleep() I wasn't able to find the right condition that would allow me to pick an item up after combat, thus a timer seemed to come in handy to delay the action of combat so bot has time to pick up item. Please enlighten me if this is not the case. Also thanks for the maps - helped heaps. EDIT: Also, surely this would not help in the case of picking up an item after combat? If the player is fighting then isAnimating() = true, but as soon as it stops fighting isAnimating() = false, which lets it proceed. sleep() is not discouraged, the sleep method and the ConditionalSleep class serve two different purposes. The first allows you to sleep for a fixed amount of time, and the second allows you to sleep until a condition is satisfied or a timeout exceeded. As for your question about picking up an item after combat, isAnimating() is a shitty way to determine if you are in combat, you could do something like this instead (note, not tested at all) : if (!myPlayer().isUnderAttack() && myPlayer().getInteracting() == null) { GroundItem bones = getGroundItems().closest("Bones"); if (bones != null) { if (bones.interact("Take")) { new CondtionalSleep(5000) { @Override public boolean condition() { return !bones.exists(); } }.sleep(); } } else { NPC monster = getNpcs().closest(npc -> npc.getName().equals("Monster") && npc.isAttackable()); if (monster != null && monster.interact("Attack")) { new ConditionalSleep(5000) { @Override public boolean condition() { return !monster.isAttackable() || myPlayer().getInteracting() == monster; } } } } } Edited December 7, 2017 by Explv Quote Link to comment Share on other sites More sharing options...
jca Posted December 7, 2017 Share Posted December 7, 2017 1 hour ago, Explv said: sleep() is not discouraged, the sleep method and the ConditionalSleep class serve two different purposes. The first allows you to sleep for a fixed amount of time, and the second allows you to sleep until a condition is satisfied or a timeout exceeded. As for your question about picking up an item after combat, isAnimating() is a shitty way to determine if you are in combat, you could do something like this instead (note, not tested at all) : if (!myPlayer().isUnderAttack() && myPlayer().getInteracting() == null) { GroundItem bones = getGroundItems().closest("Bones"); if (bones != null) { if (bones.interact("Take")) { new CondtionalSleep(5000) { @Override public boolean condition() { return !bones.exists(); } }.sleep(); } } else { NPC monster = getNpcs().closest(npc -> npc.getName().equals("Monster") && npc.isAttackable()); if (monster != null && monster.interact("Attack")) { new ConditionalSleep(5000) { @Override public boolean condition() { return !monster.isAttackable() || myPlayer().getInteracting() == monster; } } } } } The problem with this is the dying animation of the NPC, if there's multiple NPCs and no item exists on the ground until the dying animation is complete. myPlayer().isUnderAttack() resolves to false when NPC is dead, but has not completed dying animation, which means there's no item on the ground and bones != null will be false. myPlayer().getInteracting() == null will also be true when the NPC is dead, but has not completed animation. Therefore is there's another NPC near by they will go on to attack that NPC as monster != null && monster.interact("Attack") is true. I also tried .exists(), isVisible() etc. but all have the same result, so the only option I've found is timer to allow for NPC to complete dying animation. Quote Link to comment Share on other sites More sharing options...
Explv Posted December 7, 2017 Share Posted December 7, 2017 (edited) 39 minutes ago, jca said: The problem with this is the dying animation of the NPC, if there's multiple NPCs and no item exists on the ground until the dying animation is complete. myPlayer().isUnderAttack() resolves to false when NPC is dead, but has not completed dying animation, which means there's no item on the ground and bones != null will be false. myPlayer().getInteracting() == null will also be true when the NPC is dead, but has not completed animation. Therefore is there's another NPC near by they will go on to attack that NPC as monster != null && monster.interact("Attack") is true. I also tried .exists(), isVisible() etc. but all have the same result, so the only option I've found is timer to allow for NPC to complete dying animation. I didn't realise you wanted to wait for the animation to finish. This is probably how I would approach such a problem (note I wrote this fucking quickly, so it probably doesn't even work, but it should at least give you an idea) NPC currentMonster; @Override public int onLoop() throws InterruptedException { // If we need to attack a monster if (currentMonster == null) { // Get the closest monster that is attackable NPC monster = getNpcs().closest(npc -> npc.getName().equals("Monster") && npc.isAttackable()); // If the attack interaction was successful if (monster != null && monster.interact("Attack")) { // Sleep until we're fighting the monster, or someone else is fighting it new ConditionalSleep(5000) { @Override public boolean condition() { return !monster.isAttackable() || myPlayer().getInteracting() == monster; } }.sleep(); // If we're fighting the monster, set it as our currentMonster if (myPlayer().getInteracting() == monster) { currentMonster = monster; } } } // If we are fighting, do nothing else if (myPlayer().getInteracting() == currentMonster) { return 600; } // If we're not fighting, and the current monster is dying, wait until the animation has finished so we can pick up items else if (currentMonster.isAnimating() && currentMonster.getHealthPercent() == 0) { new ConditionalSleep(3000) { @Override public boolean condition() { return !currentMonster.isAnimating(); // Could change to exists(), not sure } }.sleep(); sleep(200); // Not sure if there is a delay between death and items appearing } else { GroundItem bones = getGroundItems().closest("Bones"); // If loot exists, then we take it if (bones != null) { if (bones.interact("Take")) { new CondtionalSleep(5000) { @Override public boolean condition() { return !bones.exists(); } }.sleep(); } } else { // Otherwise set current monster to null so we can attack a new one. currentMonster = null; } } return 200; } Edited December 7, 2017 by Explv Quote Link to comment Share on other sites More sharing options...
jca Posted December 7, 2017 Share Posted December 7, 2017 15 minutes ago, Explv said: I didn't realise you wanted to wait for the animation to finish. This is probably how I would approach such a problem (note I wrote this fucking quickly, so it probably doesn't even work, but it should at least give you an idea) // If we're not fighting, and the current monster is dying, wait until the animation has finished so we can pick up items else if (currentMonster.isAnimating() && currentMonster.getHealthPercent() == 0) { new ConditionalSleep(3000) { @Override public boolean condition() { return !currentMonster.isAnimating(); // Could change to exists(), not sure } }.sleep(); sleep(200); // Not sure if there is a delay between death and items appearing } I'll try switching out the timer for isAnimating() && getHealthPercent Thanks for the snippet. Quote Link to comment Share on other sites More sharing options...
beaver_fever Posted March 8, 2020 Share Posted March 8, 2020 Works perfect Quote Link to comment Share on other sites More sharing options...