Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
Buy OSRS Gold

Sign in to follow this  

Finding Objects/NPCs Dynamically!(By Model)

Recommended Posts

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.

package scripts;import java.awt.Graphics;import java.awt.Point;import java.util.ArrayList;import org.tribot.api2007.NPCs;import org.tribot.api2007.Objects;import org.tribot.api2007.Player;import org.tribot.api2007.types.RSNPC;import org.tribot.api2007.types.RSObject;import org.tribot.script.Script;import org.tribot.script.ScriptManifest;import org.tribot.script.interfaces.MouseActions;import org.tribot.script.interfaces.MousePainting;import org.tribot.script.interfaces.MouseSplinePainting;import org.tribot.script.interfaces.Painting;@ScriptManifest(authors = { "Ian" }, category = "Tools", name = "iPointCountGrabber")public class iPointCountGrabber extends Script implements Painting,MouseSplinePainting, MousePainting, MouseActions {		public static final int DISTANCE_TO_CHECK = 5;		public static final int[] OBJECTS = {		2213 //bank			};		public static final int[] NPCS = {		1775 //aubury			};		private void printObjectPointCounts() {		RSObject[] objects = Objects.sortByDistance(Player.getPosition(), Objects.findNearest(DISTANCE_TO_CHECK, OBJECTS));		for(RSObject object : objects) { 			if(object != null) {				println("----- Object Id: " + object.getID());				println("----- Object Position: " + object.getPosition()); 				println("----- Object Model Point Count: " + object.getModel().getPoints().length);			}		}	}		private void printNPCPointCounts() {		RSNPC[] npcs = NPCs.sortByDistance(Player.getPosition(), NPCs.findNearest(NPCS));		for(RSNPC npc : npcs) {			if(npc != null) {				println("----- NPC Name: " + npc.getName());				println("----- NPC Position: " + npc.getPosition());				println("----- NPC Point Length: " + npc.getModel().getPoints().length);			}		}	}		@Override	public void run() {		while(true) {						printObjectPointCounts();						sleep(1000);						printNPCPointCounts();						sleep(1000);		}	}		@Override	public void mouseClicked(Point arg0, int arg1, boolean arg2) {		// TODO Auto-generated method stub			}	@Override	public void mouseDragged(Point arg0, int arg1, boolean arg2) {		// TODO Auto-generated method stub			}	@Override	public void mouseMoved(Point arg0, boolean arg1) {		// TODO Auto-generated method stub			}	@Override	public void mouseReleased(Point arg0, int arg1, boolean arg2) {		// TODO Auto-generated method stub			}	@Override	public void paintMouse(Graphics arg0, Point arg1, Point arg2) {		// TODO Auto-generated method stub			}	@Override	public void paintMouseSpline(Graphics arg0, ArrayList<Point> arg1) {		// TODO Auto-generated method stub			}	@Override	public void onPaint(Graphics arg0) {		// TODO Auto-generated method stub			}} 


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:

	public RSNPC findNPCByModelPoints(final int MODEL_POINTS) {		RSNPC[] npcs = NPCs.sortByDistance(Player.getPosition(), NPCs.getAll());		if(npcs != null && npcs.length > 0) {			for(RSNPC npc : npcs) {				if(npc != null) {					if(correctNPC(npc, MODEL_POINTS)) {						return npc;					}				}			}		}		return null;	}		public RSObject findObjectByModelPoints(final int MODEL_POINTS) {		RSObject[] objects = Objects.sortByDistance(Player.getPosition(), Objects.getAll(64));			for(RSObject object : objects) {			if(object != null) {				if(correctObject(object, MODEL_POINTS)) {					return object;				}			}		}		return null;	}		private boolean correctNPC(RSNPC npc, final int MODEL_POINTS) {		if(npc != null) {						if(npc.getModel() != null) {								if(npc.getModel().getPoints().length == MODEL_POINTS) {					return true;									}			}		}		return false;	}		private boolean correctObject(RSObject object, final int MODEL_POINTS) {		if(object != null) {						if(object.getModel() != null) {								if(object.getDefinition() != null) {										if(object.getModel().getPoints().length == MODEL_POINTS) {												return true;											}				}			}		}		return false;	}


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.

public static final int AUBURY_MODEL_POINT_COUNT = 4026;public boolean talkToAubury() {    RSNPC aubury = findNPCByModelPoints(AUBURY_MODEL_POINT_COUNT);    if(aubury != null) {        return DynamicClicking.clickRSModel(aubury.getModel(), "Talk-to");    }    return false;}



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...
Edited by iant06

Share this post

Link to post
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.

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.

Sign in to follow this  

  • Similar Content

  • Our picks

    • TRiBot 12 Release Candidate

      The TRiBot team has been hard at work creating the last major version of TRiBot before the TRiBot X release. We've noticed many problems with TRiBot 11 with a lot of users preferring TRiBot 10 over 11. We've heard you, so we took TRiBot 10, added the new features introduced with 11, introduced some other new things, and created TRiBot 12. So without further adieu, here's TRiBot 12.
        • Sad
        • Like
      • 18 replies
    • Gradle is a build tool used to accelerate developer productivity.

      We recently setup a Maven repository (TRiBot Central) to make it easier for scripters to create scripts. Check it out here: https://gitlab.com/trilez-software/tribot/tribot-central/-/packages

      Furthermore, we've released a simple Gradle project to make it easy to run TRiBot and develop scripts for it. Check it out here: https://gitlab.com/trilez-software/tribot/tribot-gradle-launcher

      The goals of TRiBot Central are to:

      Deliver updates to TRiBot faster

      Better organize TRiBot's dependencies (AKA dependancies)

      Make it easier to develop scripts for TRiBot

      Make it easier to use and run TRiBot

      Note: TRiBot won't be able to run scripts from within this project until TRiBot's next release.
        • Like
      • 10 replies
    • Hi everyone,

      I'd like to thank everyone for their patience in this transition period. Since last week, we've worked out the remaining bugs with this integration.

      Some users have still been having issues with connecting their forums account to their Auth0 account. To resolve this, we've imported all forums accounts into Auth0.

      Unfortunately, the accounts which were imported today were using an unsupported password hashing algorithm. Hence, random passwords were set during the import.

      What does this mean for me?

      If you've previously linked your forums account to your Auth0 account, you don't have to do anything. Nothing changes for you.

      If you haven't logged in via our new login yet,

      Try logging in with your forums email address and the last password you used

      If you are unable to login, please use the "Forgot password" tool on the login page:
      Follow the instructions to reset your password
        • thonking
        • Like
      • 17 replies
    • Hello everyone,

      Last week we tried to roll out Auth0 Login, but we lost that battle. Now it's time to win the war!

      Important changes

      When logging into the client, you'll now have to enter your Auth0 account credentials instead of your forums credentials

      Note: 2FA is still handled through your forums account (for the time being)

      Changes for existing users

      You'll have to link your Auth0 account to your forums account here: https://tribot.org/forums/settings/login/?service=11

      Auth0 accounts have been created for most existing users. Please use your forums email address and password to login.

      Important notes

      Make sure to verify your email address upon creating a new Auth0 account

      When we mention your Auth0 account, we mean your account used for auth.tribot.org as displayed below
      • 81 replies
    • To better support the upcoming changes (TRiBot X, new repository), we're switching our login handler to Auth0. Instead of logging in with the standard form, you'll now be required to login through our Auth0 application.

      All existing accounts which have been used within approximately the past year have been imported into Auth0 using the same email and password combination which has been stored on the forums.

      What does this mean for users?

      Your account credentials are now even more securely stored

      You'll be able to login via Facebook, Google, and others in the future

      Is there anything users have to do differently now?

      Existing users: You'll have to login with the standard login, open your Account Settings, then link your Auth0 account

      New users: You'll be redirected to our Auth0 app (auth.tribot.org) where you'll be able to create an account

      Why was this change made?

      The new apps we are creating (such as the new repository) aren't able to use the forums to handle user logins

      To centralize all user accounts in one area

      To ensure that the client login doesn't go down when the forums are having problems

      To speed up our development

      Other considerations

      There's no documentation or official support for using Invision Community combined with Auth0, so there are still a few kinks we're working out

      We're in the works of creating an account management panel specifically for Auth0 accounts (ETA August)

      It's not possible to change email addresses for the time being (this will be resolved this August)

      Changing passwords is a weird process for the time being. To change your password, you'll have to use the "Don't remember your password" tool on the Auth0 login page
        • Like
      • 11 replies
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...