Jump to content

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


imancity

Recommended Posts

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

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