There are various ways to do this, I'll go over 3 main methods.
Using the heightLevel method (heightLevel * instanceId * 4):
This relies on the fact that the server sees the players on different height levels, however, when the server writes the height level it only uses 2 bits. Hence it overflows, and you get the effect of heightLevel % 4. So the client displays the correct height level and only has certain players in it.
This way is a bit messy and I wouldn't reccomend it.
Using the secondary map region packet
The secondary map region packet dynamically creates areas. So you could copy lumbridge, and put it in the coords 40 000, 40 000. If you had multiple target areas where you copied other areas, you could also use instancing. Jagex are believed to do this as when you play minigames the coordinates are seemingly random.
Again, this is messy, I wouldn't reccomend it (however it is good for player owned houses and such!).
Adding another variable (fourth dimension!) - instance
This would involve checking for X, Y, Height and Instance. I'd prefer this method over all of them as it works cleanly without much extra effort. For a server like rs2d or Hyperion it'd be easy to make this due to the use of a Location class. On winterlove it's probably better to use one of the others as it isn't using OOP properly.
Hope that answers your question
. If you need any more detail/have questions pm me back.