SA-MP Forums Archive
Check player position if near area - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Check player position if near area (/showthread.php?tid=348857)



Check player position if near area - ombre - 06.06.2012

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.


Re: Check player position if near area - ricardo178 - 06.06.2012

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.");
}



Re: Check player position if near area - Youice - 06.06.2012

I suggest you to use "IsPlayerInRangeOfPoint"

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


Re: Check player position if near area - Jonny5 - 06.06.2012

that will not do an area!!

@op

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


Re: Check player position if near area - iggy1 - 06.06.2012

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.


Re: Check player position if near area - Jonny5 - 06.06.2012

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


Re: Check player position if near area - iggy1 - 06.06.2012

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


Re: Check player position if near area - ricardo178 - 06.06.2012

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.


Re: Check player position if near area - MP2 - 06.06.2012

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.


Re: Check player position if near area - Jonny5 - 06.06.2012

@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+



Re: Check player position if near area - iggy1 - 06.06.2012

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?


Re: Check player position if near area - MP2 - 07.06.2012

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?


Re: Check player position if near area - ReneG - 07.06.2012

EDIT:

Re-read the post.


Re : Re: Check player position if near area - ombre - 07.06.2012

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


Re: Check player position if near area - Marricio - 07.06.2012

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.


Re : Check player position if near area - ombre - 07.06.2012

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?


AW: Check player position if near area - Josh_Main - 07.06.2012

Use IsPlayerInRangeOfPoint .


Re: Check player position if near area - Lorenc_ - 07.06.2012

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.


Re : Check player position if near area - ombre - 07.06.2012

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?


Re : Check player position if near area - ombre - 07.06.2012

thx.