Check player position if near area
#1

Hi,

I create a area ( X-,Y-,X+,Y+) I want after a command /test check if the player is near ( radius 100) of this area.


/test

if(player is near < 100 of x y X Y) ok
else no


Tanks for your help.
Reply
#2

pawn Code:
CMD:test(playerid, params[])
{
    if(IsPlayerInRangeOfPoint(playerid, 100.0, X-, Y-, Z-))
    {
    //The rest of code here.
    }
    else return SendClientMessage(playerid, 0xFFFFFFFF, "You are not near the point.");
}
Reply
#3

I suggest you to use "IsPlayerInRangeOfPoint"

IsPlayerInRangeOfPoint(playerid, Float:distance/range, Float:X, Float:Y, Float:Z);
Reply
#4

that will not do an area!!

@op

check the "Useful functions" topic i know
there are a few
IsPlayerInArea() functions.
Reply
#5

Quote:
Originally Posted by Jonny5
View Post
that will not do an area!!
He isn't asking for that he asked if player is near an area.
Reply
#6

and how are you suppose to make
IsPlayerInRangeOfPoint work for that?

you cant, not like they stated,
the x,y are not the center of the area so that wont work like that,

with some math i can see you getting the center of the area to use this function,

regards
Reply
#7

I know but there's more chance of it working with IsPlayerInRangeOfPoint than IsPlayerInArea.
Reply
#8

He is giving us 3 positions, and asking how to check if player is around it in a range of 100.0, so yeah, IsPlayerInRangeOfPoint will serve him.
Reply
#9

If you want the center area you just need to find the difference between the maxx/minx or maxy/minx coordinates (with subtraction) then add that to the smallest value = your center coordinate(s).

But to check if a player is near the edge of an area I have no idea.
Reply
#10

@iggy
Please dont take me wrong,
I have seen some of your work and have respect for you,
im just trying to wrap my head around this,

my thought is this
an area is not a single point on the map,
so using IsPlayerInRangeOfPoint is basically useless to me unless i was checking from a single point like
the center of an area.



Quote:
Originally Posted by ricardo178
View Post
He is giving us 3 positions, and asking how to check if player is around it in a range of 100.0, so yeah, IsPlayerInRangeOfPoint will serve him.
you might want to reread
he gives 4 positions
none of them include Z


Code:
X-,Y-,X+,Y+
Reply
#11

IsPlayerInRangeOfPoint is definitely not ideal. Really you would need some math function that can tell you how far away from the area. It wouldn't be an easy function to make, and i have never seen one.

@ Jonny thanks. IsPlayerInRangeOfPoint does check if your near a single point, but if you increase the range that point can become very large (not the actual point but you get what i mean i hope) or bigger than the area at least. But its still not ideal i agree.

@ombre why do you want to check if a player is near an area? Cant you create a bigger area around it? Or a few smaller areas surrounding it?
Reply
#12

Can't you just make another area, that is bigger than the old one? For example

Area: 100, -100, 100, -100

To check if they are 10 meters away from the edge of the area check if they are in area 110, -110, 110, -110?
Reply
#13

EDIT:

Re-read the post.
Reply
#14

Quote:
Originally Posted by Jonny5
View Post
that will not do an area!!

@op

check the "Useful functions" topic i know
there are a few
IsPlayerInArea() functions.
It's not my question. Near no IN.

Quote:
Originally Posted by iggy1
View Post
@ombre why do you want to check if a player is near an area? Cant you create a bigger area around it? Or a few smaller areas surrounding it?
There are some areas, simple geometric figures such as rectangles and I need to check if the players is nears of this zones. I have an accurate idea

IsPlayerInRangeOfPoint use X Y Z I need Xmini Xmax Ymini Ymaxi
Reply
#15

Use mapandreas to get the Z position, GetDistanceBetweenPoints(get distance from the center of area to another point of the area) and IsPlayerInRangeOfPoint, the range would be 50 for example + the result of GetDistanceBetweenPoints, just a theory.
Reply
#16

stock Float:GetDistanceBetweenPoints(Float,Float:y,Flo at:tx,Float:ty)
{
new Float:temp1, Float:temp2;
temp1 = x-tx;temp2 = y-ty;
return floatsqroot(temp1*temp1+temp2*temp2);
}

ex:
new Float:temp = GetDistanceBetweenPoints(x,y,tx,ty);
if(temp < 200)
{
vehicleid = i;
distance = temp;
}

how best to associate with IsPlayerInRangeOfPoint?
Reply
#17

Use IsPlayerInRangeOfPoint .
Reply
#18

pawn Code:
stock GetMiddlePos( Float: X, Float: Y, Float: X2, Float: Y2, &Float: vX, &Float: vY )
{
    vX = ( X + X2 ) / 2;
    vY = ( Y + Y2 ) / 2;
}
This function can be handy, after you get the X, Y of the area's center points; you just need to do the IsPlayerInRangeOfPoint check.
Reply
#19

thanks but i don't understand how to use it.

my aera is Xmin 2000 Xmax 2500 Ymini -1500 Ymax -1000

how to associate with IsPlayerInRangeOfPoint and the stock?
Reply
#20

thx.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)