Jump to content

Any way to get NPC ID while in dialogue?


tivo444

Recommended Posts

Hello.

 

Is there a way to get an NPC's ID while in dialogue with them? Or at least their name?

 

Thanks

Well, thought about something like this, pretty sure there are better ways of doing this;

		if (getDialogues().inDialogue()) {
			for (NPC npc : getNpcs().getAll()) {
				if (npc != null && npc.getName().equals("NPC NAME HERE") && npc.getInteracting() != null && npc.isInteracting(myPlayer())) {
					return npc.getId();
				}
			}
		}
Edited by iJodix
Link to comment
Share on other sites

  if(ctx.getDialogues.inDialogue()){
        NPC n = ctx.npcs.closest(new Filter<NPC>() {
             @Override
             public boolean match(NPC npc) {
                 return ctx.myPlayer().isInteracting(npc);
             }
         });
            //do whatever you want. (n.getName())
       }
ctx is my MethodProvider.

I didn't test the code nor do I exactly know what the isInteracting() method does. However you should be close. Of course there are better ways doing this but for now it will work.

Or what the guy above me used! biggrin.png

Edited by Psvxe
Link to comment
Share on other sites

  if(ctx.getDialogues.inDialogue()){
        NPC n = ctx.npcs.closest(new Filter<NPC>() {
             @Override
             public boolean match(NPC npc) {
                 return ctx.myPlayer().isInteracting(npc);
             }
         });
            //do whatever you want. (n.getName())
       }
ctx is my MethodProvider.

I didn't test the code nor do I exactly know what the isInteracting() method does. However you should be close. Of course there are better ways doing this but for now it will work.

Or what the guy above me used! biggrin.png

 

isinteracting returns true if you're interacting or false ff not

Link to comment
Share on other sites

The API does not provide any method to obtain information about the npc you are in a dialogue with at any given moment. There are 3 methods you can use to determine the npc although all of them have exceptions.

 

1. Get the npc you are interacting with (easiest)

myPlayer().getInteracting().getId();

Works when you click on the npc and your player starts moving towards the npc as well as for 1 tick after each response from the npc. You could use this to determine the id before the actual dialogue.

 

2. Find the npc that is interacting with you (least reliable)

npcs.getAll().stream().filter(n -> n.getInteracting() == myPlayer()).findFirst().get().getId();

The npc should be interacting with you for 1 tick after each response from you. The main issue here is that other people might attempt to start dialogues with same npc leading to undefined behaviour.

 

3. Extract npc name from dialogue widget and then search for the npc (most reliable)

npcs.getAll().stream().filter(n -> n.getName().equals(widgets.get(WIDGET_COORDINATES).getMessage())).findFirst().get().getId();

Where WIDGET_COORDINATES represents the ids of the npc name widget on your dialogue interface. The only drawback of this method is that you can only obtain the id of the npc once they are the ones talking.

 

You can also filter the npcs using the API Filter class if you don't like lambda expressions:

npcs.closest(new Filter<NPC>() {
    @Override
    public boolean match(NPC n) {
        return n.getInteracting() == myPlayer();
    }
}).getId();

That's pretty much all you can do with the API right now, the main issue being that npc interaction is not a continuous thing, at least not for dialogues. It is continuous for instance if you are safespotting an npc and that npc keeps trying to reach your player but they can't. In this case, that npc will be interacting with your player. But anyway, there is absolutely no need for the npc id you are in dialogue with so we don't really have a method that provides that 100% accurate result.

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