Jump to content

My NPC Filter sometimes tries swapping to new NPC


Brian

Recommended Posts

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` ?

Link to comment
Share on other sites

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