Jump to content

Best way to select an NPC?


Recommended Posts

Posted

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?

Posted

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

Posted (edited)

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

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