Jump to content

[Guide]Types of Entities and how to use them correctly


Recommended Posts

Posted (edited)

RuneScape has multiple entity types

NPC's

Objects

GroundItems

 

Determining which one to use is way simpler than people think.

NPC's will have yellow name tags in game

2xcst7n.png

Objects will have blue name tags in game

1rCljtX.png

GroundItems will have orange name tags in game

BOQ56Cg.png

 

Now when it comes to declaring variables what should we use?

For NPC's we would use the NPC class. Our code should look like this

NPC npc = ...

For Objects we would use the RS2Object class. Our Code should look like this

RS2Object object = ...

For GroundItems we would use the GroundItem class. Our code should look like this

GroundItem item = ...

Why would we shy away from using Entity class to define any entity from the game?

Well simply put Entity is just an interface and it might not contain things needed to any specific Entity implementing classes.

Like RS2Object will have getType() method but Entity will not.

 

The main place to use Entity class is when we are passing it to a parameter of a method and making your own lets say interacting methods.

We would use Entity in our parameter to make it accept any Entity type.

public void interactCustom(Entity entity, String action){
    if(entity.isVisible())
        entity.interact(action);
    else
        getCamera().toEntity(entity);
}

Of course again there will come limitations, which are when you are making a method for getting the type of an Object and logging it.

 

Having our code look like this will not work and give us an error.

public void getTypeAndLog(Entity entity){
    log("[Debug] objects type: " + entity.getType();
}

So passing Entity to our parameter wouldn't give us the method getType() which RS2Object has, so we would need to have RS2Object in our parameter

 

So we would need to have RS2Object in our parameter. And our code will work if he have it look like this

public void getTypeAndLog(RS2Object object){
    log("[Debug] objects type: " + object.getType();
}

I hope this guide helped you understand the types of Entities and how to use them correctly smile.png

Edited by Vilius
  • Like 7
  • 9 months later...
Posted

So what
"public void interactCustom(Entity entity, String action){
if(entity.isVisible())
entity.interact(action);
else
getCamera().toEntity(entity);
}"

 

Is basically doing is clicking it no matter what. I am assuming or could you maybe go into more depth of each parameter and its purpose.

This method passes a string called action to it using entity. So its basically clicking it right?

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