Jump to content

How do I check if my player is in a certain Position, not Area?


Recommended Posts

Posted

You can define a area with z = 3

Doing this ; new Area(new Position(x y z), new Position(x y z))

OR

Position t = new position(x y z)

Or tile t im not sure, not at home

if (myPlayer().getPosition() == t){

\\something

}

 

Ohh forreal?? That helps a ton. Thanks man!

 

Area AREA = new Area(x1, y1, x2, y2).setPlane(z);

 

Totally missed this post, thanks appreciate it!!

  • Like 1
Posted (edited)

If you're checking a specific Position, don't use Area and don't compare objects using "==". Keep it simple:
 

Position myPos = myPosition();
Position targetPos = new Position(1000, 1000, 3);

if (myPos.equals(targetPos)) {
	// You're at position
} else {
	// You're not at position
}

Edit: After reading your first post, you can simply do this:

Position myPos = myPosition();
if (someArea.contains(myPos) && myPos.getZ() == 3) {
	// You're in an area AND on the 3rd floor
} else {
	// You're not...
}

You can set a plane for the Area, but that's only useful if the Area location is unique to whichever plane you're checking. For instance, if I'm in Lumbridge Castle, my Area will cover the entire castle and I will check the plane using my character's Z value, instead of setting the plane of the Area. Otherwise, I will have to constantly set that value to check what floor I'm on, which is just terrible.

 

Example of how I would handle Lumbridge Castle's many floors to spin flax:

Position myPos = myPosition();
if (lumbridgeCastle.contains(myPos)) {
	switch(myPos.getZ()) {
	case 0:
		// Ground floor
		// Climb staircase UP
	break;
	case 1:
		// First floor
		// Use spinning wheel, or go bank
		// upstairs 
	break;
	case 2:
		// Second floor
		// Withdraw flax, or go to
		// spinning wheel downstairs
	break;
	}
}
Edited by liverare

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