Jump to content

Check to wait till npc is dead, and the loot is showing?


Tasemu

Recommended Posts

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!

Link to comment
Share on other sites

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

  • Like 1
Link to comment
Share on other sites

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.

  • Heart 1
Link to comment
Share on other sites

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 by Tasemu
Link to comment
Share on other sites

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 by liverare
  • Like 1
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...