Jump to content

Attacking


Recommended Posts

Posted (edited)

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
Posted

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
Posted

 

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...