Jump to content

Player in combat


HunterRS

Recommended Posts

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

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