Finding Objects/NPCs Dynamically
What this tutorial is going to do is teach YOU how to find Objects and NPCs without using their ids, so you will no longer have to worry about updating your script every time RuneScape updates it's ids. A way that I have found to be very reliable and has yet to fail on me, is instead of checking for the id of the Object/NPC, check for the amount of model points of the Object/NPC.
Model Point Count:
The amount of points on a specific model.
Tribot API RSModel:
How to find the amount of Model Points on an Object/NPC:
I wrote a simple script to check the area your in and print out the amount of model points of anything with the entered ids.
After entering the Ids in to the script arrays(example we are using aubury) and running the script near the desired Object/NPC it will print out in the console something along the lines of
----- NPC Id: 1775----- NPC Position: 3253, 3401 ----- NPC Model Point Count: 4026
Now you are probably wondering how do you find an Object/NPC without the id? There's no method in the api to find npcs by model points?
Add these methods in to your script:
What these methods do:
Gets all Objects/NPCs in the area and checks to see if their model point amount equals the parameter model point amount. If it does check to see if the actions are correct and if they are return the Object/NPC.
How you would call upon these methods once they have been added:
In our example we used aubury and found his model point count to be 4026. Using the above methods and the model point amount, here is an example of finding aubury and talking to him.
If you are wondering if this will take a substantial amount of time to loop through all the objects in the region it actually doesn't, it does take longer than the normal Objects.findNearest(64, XXXX); but only by about 100 ms
[19:16:18] iEssenceMiner: WALKING_TO_ESSENCE: It took 195 ms to complete the method findObjectByModel...