Jump to content

Entities


Chazler

Recommended Posts

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

Link to comment
Share on other sites

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

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

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!

Link to comment
Share on other sites

i know i love it, but just know we never had the position filter until now http://osbot.org/forum/topic/65624-suggesting-another-filter/

 

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

 

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