Jump to content

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


Vilius

Recommended Posts

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
Link to comment
Share on other sites

  • 9 months later...

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?

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