Jump to content
View in the app

A better way to browse. Learn more.

OSBot :: 2007 OSRS Botting

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Attack NPC that isn't under attack

Featured Replies

So I'm trying to make the bot not attack the NPC that is under attack. I tried using !closestMonster.isInteracting() but no luck.

NPC closestMonster = s.getNpcs().closest(Vars.radius, Vars.combatMonster);

        if (closestMonster != null && !closestMonster.isAttackable() && s.getInventory().contains(Vars.combatFood)) {
            s.getWalking().walk(closestMonster);

        } else if (closestMonster != null && !s.myPlayer().isUnderAttack() && s.getInventory().contains(Vars.combatFood)) {
            if (s.myPlayer().isAnimating()) {
                Vars.lastAnimation = System.currentTimeMillis();

            } else if (closestMonster.interact("Attack") && System.currentTimeMillis() > (Vars.lastAnimation + 1000)) {
                Paint.status = "Attacking...";
                Sleep.sleepUntil(() -> s.myPlayer().isUnderAttack(), 5000);
            }
        }

 

Edited by Visty

I imagine you don't want to attack an NPC which is under attack, but you want to attack one which is not. Here's how to find that monster:

NPC notUnderAttack = getNpcs().closest(new Filter<NPC>() {
                        @Override
                        public boolean match(NPC npc) {
                            return !npc.isUnderAttack() && !npc.isAnimating();
                        }
                    });

 

Edited by Adept

  • Author
7 minutes ago, Adept said:

I imagine you don't want to attack an NPC which is under attack, but you want to attack one which is not. Here's how to find that monster:


NPC notUnderAttack = getNpcs().closest(new Filter<NPC>() {
                        @Override
                        public boolean match(NPC npc) {
                            return npc.isAttackable() && !npc.isHitBarVisible() && !npc.isAnimating();
                        }
                    });

 

But will that fix the issue with people splashing on NPCs? Because, isUnderAttack() seems to fix the issue with people normally attacking the NPC. But when people splash on NPCs, you can't see their HitBar, so it doesn't work

Edited by Visty

Don't quote me on this but I believe NPCs "animate" when under attack (and are being splashed on) so !npc.isAnimating() should take care of that.
Also, I just checked the API and the "!npc.isUnderAttack()" check in the filter I provided earlier is redundant since it's already checked for with "npc.isAttackable()". However since you explicitly stated to check for an NPC which is not under attack and not one which is attackable it makes more sense to keep the former. Edited my reply to reflect that.

Edited by Adept

I think this will work for you.

NPC npc = getNpcs().closest(npc -> npc.getName().equals(npcName) && npc.getInteracting() == null && !npc.isUnderAttack());

If an NPC is being splashed on #getInteracting will not return null (iirc).

Edited by Eliot

  • Author
3 hours ago, Eliot said:

I think this will work for you.


NPC npc = getNpcs().closest(npc -> npc.getName().equals(npcName) && npc.getInteracting() == null && !npc.isUnderAttack());

If an NPC is being splashed on #getInteracting will not return null (iirc).

I appreciate your responds. Your piece of code works :)

Also, just noticed that my code above checks useless stuff in the If statements lel :doge:

Edited by Visty

  • Author
3 hours ago, Alek said:

Try checking out my Macro Killer source code, I made it public. 

Thank you, will do :)

51 minutes ago, Visty said:

I appreciate your responds. Your piece of code works :)

Also, just noticed that my code above checks useless stuff in the If statements lel :doge:

Awesome! I'm glad I could help. :)

Create an account or sign in to comment

Recently Browsing 0

  • No registered users viewing this page.

Account

Navigation

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.