Beenrange Posted June 30, 2018 Share Posted June 30, 2018 gargoyle = getNpcs().closest(n -> n.getName().equals("Gargoyle") && !n.isUnderAttack()); if ((!player.isMoving()) && (!player.isUnderAttack()) && (!player.isAnimating()) && (gargoyle != null) && (gargoyle.getHealthPercent() > 0) && (!gargoyle.isUnderAttack() && (!gargoyle.isHitBarVisible()))) { if(!gargoyle.isOnScreen()) { getCamera().toEntity(gargoyle); } gargoyle.interact("Attack"); } Sometimes, the script will find a target successfully and click it, but then after one attack (and the npc not attacking me back) it will switch to a new gargoyle. Does anyone know why/have any suggestions on how to fix this? I think its a result of player.isUnderAttack - obviously im not under attack(yet), but surely the player.isAnimating() call would fix it? Cheers. Quote Link to comment Share on other sites More sharing options...
Chuckle Posted June 30, 2018 Share Posted June 30, 2018 add a sleep timer after the original attack so it has time to get in combat in game 1 Quote Link to comment Share on other sites More sharing options...
Beenrange Posted June 30, 2018 Author Share Posted June 30, 2018 (edited) 1 hour ago, Chuckle said: add a sleep timer after the original attack so it has time to get in combat in game Thats sorted it, cheers. My sleep wasn't long enough. Still happens every now and again though, no idea why. 5 second sleep should have sorted it tbf Edited June 30, 2018 by Beenrange Quote Link to comment Share on other sites More sharing options...
HeyImJamie Posted June 30, 2018 Share Posted June 30, 2018 5 minutes ago, Beenrange said: Thats sorted it, cheers. My sleep wasn't long enough. Still happens every now and again though, no idea why. 5 second sleep should have sorted it tbf Use a conditional sleep to check if you're under attack or interacting with your npc. You can also combine filters, rather than adding a load of boolean checks like you've done above. 1 Quote Link to comment Share on other sites More sharing options...
Beenrange Posted June 30, 2018 Author Share Posted June 30, 2018 (edited) 6 minutes ago, HeyImJamie said: Use a conditional sleep to check if you're under attack or interacting with your npc. You can also combine filters, rather than adding a load of boolean checks like you've done above. Yeah, its my first time using filters so I tested removing some to see if that was the cause, I'll re-add them as clearly not. Will look at the conditional sleep - yet to use one but can see that SDN scripts require it so must be important. Do you have any examples of where it is used by any chance? Edited June 30, 2018 by Beenrange Quote Link to comment Share on other sites More sharing options...
CasDeBlanco Posted June 30, 2018 Share Posted June 30, 2018 12 minutes ago, Beenrange said: Yeah, its my first time using filters so I tested removing some to see if that was the cause, I'll re-add them as clearly not. Will look at the conditional sleep - yet to use one but can see that SDN scripts require it so must be important. Do you have any examples of where it is used by any chance? Item food = getInventory().getItem("Example"); if (food != null) { if(food.interact("Eat")){ new ConditionalSleep(random(2500, 5000)) { @Override public boolean condition() { return !myPlayer().isAnimating(); } }.sleep(); } } It'll sleep until the return condition is met or until its slept for 2500-5000 ms 1 Quote Link to comment Share on other sites More sharing options...
dreameo Posted June 30, 2018 Share Posted June 30, 2018 22 minutes ago, Castro_ said: Item food = getInventory().getItem("Example"); if (food != null) { if(food.interact("Eat")){ new ConditionalSleep(random(2500, 5000)) { @Override public boolean condition() { return !myPlayer().isAnimating(); } }.sleep(); } } It'll sleep until the return condition is met or until its slept for 2500-5000 ms hmm.. I don't think the return condition is right, should be without the '!'. If you click eat, there's probably atleast 300 ms of no action which means your player isn't animating and it will immediately continue execution. If it loops fast enough in time (nothing else blocking execution) which it probably will, then it will double click or triple click until you do animate. Quote Link to comment Share on other sites More sharing options...
Beenrange Posted June 30, 2018 Author Share Posted June 30, 2018 46 minutes ago, Castro_ said: Item food = getInventory().getItem("Example"); if (food != null) { if(food.interact("Eat")){ new ConditionalSleep(random(2500, 5000)) { @Override public boolean condition() { return !myPlayer().isAnimating(); } }.sleep(); } } It'll sleep until the return condition is met or until its slept for 2500-5000 ms Thank you, the logic is clear now will be replacing many of my sleeps. Quote Link to comment Share on other sites More sharing options...
Alek Posted July 1, 2018 Share Posted July 1, 2018 On 6/30/2018 at 10:27 AM, Beenrange said: Thank you, the logic is clear now will be replacing many of my sleeps. The random is completely useless. You're going to be returning the same sleep every single time (~500ms) because it's conditional with a 50ms recheck. Just save yourself the trouble and only add a timeout of 3000ms. Quote Link to comment Share on other sites More sharing options...