Tasemu Posted September 19, 2018 Share Posted September 19, 2018 I am currently using this conditional wait while fighting an NPC new ConditionalSleep(3000, 500) { @Override public boolean condition() throws InterruptedException { return !currentTarget.isInteracting(myPlayer()) && !myPlayer().isUnderAttack() && !currentTarget.exists(); } }.sleep(); When the NPC dies, my script immediately begins attacking the next npc, then comes back after killing that NPC to loot the first kill. What should I be using here to wait for looting each kill before attacking the next? Much appreciated! Quote Link to comment Share on other sites More sharing options...
Apaec Posted September 19, 2018 Share Posted September 19, 2018 Well, when you kill an enemy, the loot will appear on the position which the enemy died at. You could scan this tile and wait until loot is available? Remember: there could already be loot on the tile so you will have to include some kind of system capable of dealing with this situation. Good luck Apa 1 Quote Link to comment Share on other sites More sharing options...
FuryShark Posted September 19, 2018 Share Posted September 19, 2018 Theres also currentTarget.isUnderAttack() currentTarget.getHealthPercent() == 0 Quote Link to comment Share on other sites More sharing options...
liverare Posted September 20, 2018 Share Posted September 20, 2018 I would advise against sleeping during combat as you risk your character dying. Instead, use the onLoop to your advantage: NPC target; @Override public int onLoop() { if (target != null && target.exists()) { if (target.equals(myPlayer().getInteracting())) { // TODO nothing } else { // TODO attack if (target.interact("Attack")) { // TODO conditionally sleep until we've begun attacking target } } } else { target = npcs.closest("Goblin"); } } You can then add in other important things, such as health checker, loot checker, area checker, to make sure you can step away from combat to deal with more important things. 1 Quote Link to comment Share on other sites More sharing options...
Tasemu Posted September 21, 2018 Author Share Posted September 21, 2018 (edited) 11 hours ago, liverare said: I would advise against sleeping during combat as you risk your character dying. Instead, use the onLoop to your advantage: NPC target; @Override public int onLoop() { if (target != null && target.exists()) { if (target.equals(myPlayer().getInteracting())) { // TODO nothing } else { // TODO attack if (target.interact("Attack")) { // TODO conditionally sleep until we've begun attacking target } } } else { target = npcs.closest("Goblin"); } } You can then add in other important things, such as health checker, loot checker, area checker, to make sure you can step away from combat to deal with more important things. Just a question, but to me it appears that it is very possible to handle this logic within the conditional wait loop and even break out if required, is that considered a bad practise for some reason? for example, as long as I return a condition, any other logic I like can be executed within the conditional check loop. Edited September 21, 2018 by Tasemu Quote Link to comment Share on other sites More sharing options...
liverare Posted September 21, 2018 Share Posted September 21, 2018 (edited) 54 minutes ago, Tasemu said: Just a question, but to me it appears that it is very possible to handle this logic within the conditional wait loop and even break out if required, is that considered a bad practise for some reason? for example, as long as I return a condition, any other logic I like can be executed within the conditional check loop. I would consider it bad practice as that would be a loop within a loop, when only the main script loop is necessary. Conditional sleeps are great in preventing your bot from spam clicking stuff; which just so happens to be the best use case for them. If you're killing chickens, it's best to attack a chicken then sleep until you're either in combat or that chicken has been stolen and is in combat with someone else. If you choose to sleep during the fighting phase, you're opening yourself up to unnecessary risk. Checking your health, looking good loot, or making sure you're in a safe area will become harder to implement as you'd have to check for all those inside of your conditional sleep. Instead, the main loop cycle should be where you run these checks, not inside of a conditional sleep. Edited September 21, 2018 by liverare 1 Quote Link to comment Share on other sites More sharing options...