Jump to content

Best way to select an NPC?


ScummyBotter

Recommended Posts

Currently I'm doing something like this for every single (unique) NPC in the script I'm making, since I don't want to identify them using their id's in case Jagex change them:

NPC npcOne = npcs.closest(npc -> npc.getName().equals(NAME) && area.contains(elemental));

I'm making a sorceress's garden script, so I need to make one of these for every single elemental and need to store their areas too, as I'm writing this I just notice that their areas can overlap too, so there is a chance I get the wrong elemental in that case. Should I just identify them by their id's and update them if Jagex ever change the ids? Do Jagex change the id's?

Link to comment
Share on other sites

Even if their IDs were to change (which I somewhat doubt they will, but who knows), their IDs relative to eachother will probably remain the same, since they seem to count from X to X+1, X+2, X+3 in order of their progression.

There are many ways you could do it, but I'd probably try with their relative ID offset. Something like this:

private final static int IDOFFSET_SUMMER_SECTION1 = 0;
private final static int IDOFFSET_SUMMER_SECTION2 = 1;
private final static int IDOFFSET_SUMMER_SECTION3 = 2;

int baseId = getNpcs().filter(npc -> npc.getName().equals(NAME)).stream().min(Comparator.comparing(NPC::getId)).getId();
NPC npcSection1 = getNpcs().singleFilter(npc -> npc.getId() == (baseId + IDOFFSET_SUMMER_SECTION1));

Ofc. you will only need to find the base ID once, and should add various checks; this is only a pseudo example

  • Like 2
Link to comment
Share on other sites

18 minutes ago, FrostBug said:

Even if their IDs were to change (which I somewhat doubt they will, but who knows), their IDs relative to eachother will probably remain the same, since they seem to count from X to X+1, X+2, X+3 in order of their progression. 

There are many ways you could do it, but I'd probably try with their relative ID offset. Something like this: 


private final static int IDOFFSET_SUMMER_SECTION1 = 0;
private final static int IDOFFSET_SUMMER_SECTION2 = 1;
private final static int IDOFFSET_SUMMER_SECTION3 = 2;

int baseId = getNpcs().filter(npc -> npc.getName().equals(NAME)).stream().min(Comparator.comparing(NPC::getId)).getId();
NPC npcSection1 = getNpcs().singleFilter(npc -> npc.getId() == (baseId + IDOFFSET_SUMMER_SECTION1));

Ofc. you will only need to find the base ID once, and should add various checks; this is only a pseudo example 

That's a good observation and it makes sense, thanks a lot! I was under the impression that the id's were something that gets changed frequently, seems like that's not the case then.

Link to comment
Share on other sites

Haven't seen a NPC ID change in my 3 years of being on osbot with over 300 scripts written. Take that as you will. Widgets change a little more frequently and stuff of tut island every once in a while but outside of that things rarely change. And if they do, it takes two seconds to get the new ID

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