[Tutorial] IsPlayerInArea
#1

I have seen a few tutorials for IsPlayerInArea, and some people have a tough time understanding. I recently posted on in another section and it seemed to have done a good job. So here it is..

IsPlayerInArea(playerid,Float:data[4]).

Basically with IsPlayerInArea you are checking a players coordinates, to see if they are in a 2 Dimension "box" shaped area.

The Float:data[4], is 2 sets of X,Y coordinates. One for what i call the "Low" corner and another for a "high" corner.

To avoid confusion and complexity, i usually modify it a bit to remove the Float Array to this:
pawn Код:
IsPlayerInArea(playerid, Float:MinX, Float:MinY, Float:MaxX, Float:MaxY)
{
    new Float:X, Float:Y, Float:Z;

    GetPlayerPos(playerid, X, Y, Z);
    if(X >= MinX && X <= MaxX && Y >= MinY && Y <= MaxY) {
        return 1;
    }
    return 0;
}
First thing you need to do. Go ingame and visualize the area you want to check if a player is in. Go to the most Southwest corner and get the coordinates. This will be your "Low" corner, or your MinX, and MinY values. Next go to the most Northeast corner. Save those too, they will be your "High" corner, or MaxX, MaxY values.

What the function is doing when checking if a player is in the area, is it checks if X is between MinX and MaxX, and same with Y. If the condition is true, it returns 1, 0 if it is not true.

Hope this helps..



In the above image it shows the Low Corner Coordinates at -100, for X, and -100 for Y and the High Corner at 100 for X, and 100 for Y, and the Player Coordinates, 50 for X, and 50 for Y. At this point you plugin the coordinates into IsPlayerInArea. Keep in mind, just like mathematics and graphing, coordinates are read in the following format: (X,Y).

pawn Код:
IsPlayerInArea(playerid,LowCornerX,LowCornerY, HighCornerX,HighCornerY);
If it found that the player was indeed in that 2 Dimension box, it would return 1. If not it would return 0.

If you have more problems, please contact me via IRC or MSN, ill answer any questions you have.
Reply
#2

Nice tutorial
Reply
#3

Yea love that diagram and explanation of the whole thing, great job dude.
Reply
#4

Seems someone has finally put some work in his tutorial, good job on the diagram as it really shows what you're actually doing.

One tip: Also add IsPlayerInCube (3D check) and IsPlayerInRangeOfPoint
Reply
#5

Wow
Impressive tutorial,now honestly,you really putted some work on it xD...I never understood "IsPlayerInArea" but now i do
This tutorial should be used by Sa-mp Wiki too ,i guess it's better than
https://sampwiki.blast.hk/wiki/Areacheck
Reply
#6

Great Tutorial.
Reply
#7

nice tut, help me alot .
Reply
#8

Lol... Take a look at date of the last post.



07/02/2011, 10:20 AM
Reply
#9

I forgot i made this.. please dont bump for future reference.
Reply
#10

You saved my day buddy.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)