Jump to content

My NPC Filter sometimes tries swapping to new NPC


Recommended Posts

Posted
Filter<NPC> gorillaFilter;

  if(myPlayer().isUnderAttack()){
  gorillaFilter = n -> n.getName().contains("Demonic") && n.getInteracting() == myPlayer();
  }else{
  gorillaFilter = n -> n.getName().contains("Demonic") && !n.isUnderAttack();
  }
  NPC a = npcs.closest(gorillaFilter);

 

I am having some trouble determining which gorilla to attack.  (Demonic gorilla) After I do boulder dodge, it will sometimes pick some random gorilla very far away and occasionally will just start trying to attack some other gorilla.  How can I enhance my `gorillaFilter` ?

Posted (edited)
private NPC getInteractingNPC() {
        return getNpcs().closest((Filter<NPC>) npc -> npc != null && npc.hasAction("Attack") && (myPlayer().isInteracting(npc) || (npc.isInteracting(myPlayer()) && !npc.isUnderAttack())));
}

What this does: 
Looks for npc that
has attack option AND (we are interacting with it OR  it is interacting with us AND not under attack)


Then for our main check we do
 

public NPC getAvailableNPC() {
        NPC npc = getInteractingNPC();
        return npc != null ? npc : PRIMARY_FILTER_HERE);
}

 It will make a call to getInteractingNPC()

if its null it will try to do your primary filter


PRIMARY_FILTER_HERE can be substituted with what you have on the main thread.

getNpcs().closest(n -> n.getName().contains("Demonic") && !n.isUnderAttack());

though I recommend adding more checks 

 

Then when you want to call 
 

NPC a = getAvailableNPC();

If (a != null && a.interact("Attack")) {
    // sleep until in combat ....... or w.e
}

 

@Brian

Edited by Chris
  • Heart 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...