Jump to content

Entities


Recommended Posts

Posted

So I'm trying to get the player to interact with a trapdoor when it does not have a bucket in its inventory to try out player interaction with entities. only Entity.closest(arg) gives an error simply because closest is not a valid method as seen below.

 

2b4fabf425.png

 

Now my question is, how would one make a player interact with a certain entity in the way described above. Also I'm rather curious as to how one would implent the use of x and y coordinates so that there is no mistake, in the unlikley event of there being mutiple trapdoors, to which trapdoor the player has to interact with.

 

Cheers,

Chazler

Posted (edited)

So I'm trying to get the player to interact with a trapdoor when it does not have a bucket in its inventory to try out player interaction with entities. only Entity.closest(arg) gives an error simply because closest is not a valid method as seen below.

 

2b4fabf425.png

 

Now my question is, how would one make a player interact with a certain entity in the way described above. Also I'm rather curious as to how one would implent the use of x and y coordinates so that there is no mistake, in the unlikley event of there being mutiple trapdoors, to which trapdoor the player has to interact with.

 

Cheers,

Chazler

RS2Object trapdoor = objects.closest("Trapdoor");

A better way to do this is:

if (!myPlayer().isMoving() && inventory.contains("Bucket")) {
   RS2Object trapdoor = objects.closest("Trapdoor");
   if (trapdoor != null)
      if (trapdoor.isVisible())
         trapdoor.interact("Climb-down");
      else
         camera.toEntity(trapdoor);
}

If you want a trapdoor on a specific position you have to use the Filter.

This can filter out everything you want.

 

Example:

if (!myPlayer().isMoving() && inventory.contains("Bucket")) {
   RS2Object trapdoor = objects.closest(new Filter<RS2Object>(){

   @Override
   public boolean match(RS2Object object) {
      return object != null && object.getName().equals("Trapdoor") && object.getPosition().equals(new Position(0, 0, 0));
   }});

   if (trapdoor != null)
      if (trapdoor.isVisible())
         trapdoor.interact("Climb-down");
      else
         camera.toEntity(trapdoor);
}

Goodluck!

Khaleesi

Edited by Khaleesi
  • Like 1
Posted

So I'm trying to get the player to interact with a trapdoor when it does not have a bucket in its inventory to try out player interaction with entities. only Entity.closest(arg) gives an error simply because closest is not a valid method as seen below.

 

2b4fabf425.png

 

Now my question is, how would one make a player interact with a certain entity in the way described above. Also I'm rather curious as to how one would implent the use of x and y coordinates so that there is no mistake, in the unlikley event of there being mutiple trapdoors, to which trapdoor the player has to interact with.

 

Cheers,

Chazler

RS2Object thing = objects.closest("Blah");
Posted
RS2Object trapdoor = objects.closest("Trapdoor");

A better way to do this is:

if (!myPlayer().isMoving() && inventory.contains("Bucket")) {
   RS2Object trapdoor = objects.closest("Trapdoor");
   if (trapdoor != null)
      if (trapdoor.isVisible())
         trapdoor.interact("Climb-down");
      else
         camera.toEntity(trapdoor);
}

If you want a trapdoor on a specific position you have to use the Filter.

This can filter out everything you want.

 

Exmaple:

if (!myPlayer().isMoving() && inventory.contains("Bucket")) {
   RS2Object trapdoor = objects.closest(new Filter<RS2Object>(){

   @Override
   public boolean match(RS2Object object) {
      return object != null && object.getName().equals("Trapdoor") && object.getPosition().equals(new Position(0, 0, 0));
   }});

   if (trapdoor != null)
      if (trapdoor.isVisible())
         trapdoor.interact("Climb-down");
      else
         camera.toEntity(trapdoor);
}

Goodluck!

Khaleesi

 

 

Quick and on the spot as always, much obliged!

Posted (edited)

 

Cmoooon man

	public Filter<RS2Object> pls(Position lel) {
		Filter<RS2Object> wat= new Filter<RS2Object>() {
			@Override
			public boolean match(RS2Object mald) {
				return !mald.getPosition().equals(lel);
			}
		};
		return wat;
	}

you see all that code you have to type up. I got tried of doing that. When now we can simply do getObjects().closest(new PositionFilter(position));

 

edit: i know its easy to create a simple method like that. I simply request for the filter because we have many different filters available. It wasnt there when i look at it. It will be handy to others especially the nubs (like me :troll:) and i mean there is a PolygonArea filter (which the PolygonArea class was just recently released) and not a position filter. Which btw in OSB1 there use to be like a method to get an entity using a position. 

Edited by josedpay
  • 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...