Jump to content

Player in combat


Recommended Posts

Posted (edited)

I cant for the life of me get this to work.

I am trying to attack a cow while my player is not in combat and the cow is not in combat.

I used so many freaking filters but non of them work.

Here is what I currently have:

State definer
  
  
  
NPC cow = getNpcs().closest(cowFilter);
if (cow != null && !myPlayer().isAnimating())
    		return State.ATTACK;


switch case
  
  
  
		case ATTACK:
			NPC cow = getNpcs().closest(cowFilter);
			if (cow != null && !myPlayer().isAnimating())
				cow.interact("Attack");
			break;


cow filter
  
  
  
      Filter<NPC> cowFilter = new Filter<NPC>(){
        public boolean match(NPC npc){
           return (npc.getName().equalsIgnoreCase("Cow") || npc.getName().equalsIgnoreCase("Cow calf")) && !npc.isHitBarVisible() && !npc.isAnimating() && npc.isAttackable() && getMap().canReach(npc);
        }
    };
  

 

Anyone has any idea what I am doing wrong?

Edited by HunterRS
Posted
20 minutes ago, GPSwap said:

combat.isFighting();
cow.isUnderAttack

combat.isFighting checks if your player is in combat - so change your !myPlayer().isAnimating to !combat.isFighting()
Entity.isUnderAttack will check if entity is under attack - and add this to your cow filter

ya just found isFighting, was exactly what I was looking for. 

Ty for your help :)

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