Jump to content

Attacking


Annointed

Recommended Posts

Hey guys, so I currently have a problem where, my script will still attack an NPC that is under attack from someone using Magic that does no damage.

 

Currently someone is using magic, and they're doing no damage to the cow, so the cow's hp bar isn't showing up, but the cow is attacking back, but my script thinks it's not fighting and tries to attack it?

 

Here's my filter:

                NPC cow = getNpcs().closest(new Filter<NPC>() {
                    @@Override
                    public boolean match(NPC cow) {
                        return cow.getName().startsWith("Cow")
                                && cow.isAttackable() && !cow.isUnderAttack()
                                && cow.getHealthPercent() > 0
                                && cowArea.contains(cow);
                    }
                });

 

Thanks!

Edited by Annointed
Link to comment
Share on other sites

Hey guys, so I currently have a problem where, my script will still attack an NPC that is under attack from someone using Magic that does no damage.

 

Currently someone is using magic, and they're doing no damage to the cow, so the cow's hp bar isn't showing up, but the cow is attacking back, but my script thinks it's not fighting and tries to attack it?

 

Here's my filter:

 

 

 

Thanks!

 

Just FYI the:

!cow.isUnderAttack() && cow.getHealthPercent() > 0

Is redundant because:

cow.isAttackable()

Does:

npc.getHealthPercent() > 0 && !npc.isUnderAttack() || npc.isInteracting(getMethods().myPlayer())

As for your issue you could try doing:

NPC cow = getNpcs().closest(npc -> npc.getName().startsWith("Cow") && cowArea.contains(npc) && npc.isAttackable() && npc.getInteracting() == null);
  • Like 1
Link to comment
Share on other sites

 

Just FYI the:

!cow.isUnderAttack() && cow.getHealthPercent() > 0

Is redundant because:

cow.isAttackable()

Does:

npc.getHealthPercent() > 0 && !npc.isUnderAttack() || npc.isInteracting(getMethods().myPlayer())

As for your issue you could try doing:

NPC cow = getNpcs().closest(npc -> npc.getName().startsWith("Cow") && cowArea.contains(npc) && npc.isAttackable() && npc.getInteracting() == null);

+1. Perfect explanation as always. .getInteracting is very useful.

  • 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...