What function would i use. -
Haydz - 20.12.2010
If i wanted to measure the distance from player to player what function would i use.
Thanks in advance.
Re: What function would i use. -
blackwave - 20.12.2010
IsPlayerInRangeOfPoint(playerid, distance, x, y, z)) // X,y,z = you need to get the distance from the player you want
Re: What function would i use. -
Haydz - 20.12.2010
Quote:
Originally Posted by blackwave
IsPlayerInRangeOfPoint(playerid, distance, x, y, z)) // X,y,z = you need to get the distance from the player you want
|
Ohk, i thought i might have to use that but thought there might be another function i could use, thanks anyways.
Re: What function would i use. -
Lorenc_ - 20.12.2010
pawn Код:
stock Float:GetPointAngleToPoint(Float:x2, Float:y2, Float:X, Float:Y)
{
new Float:DX, Float:DY;
new Float:angle;
DX = floatabs(floatsub(x2,X));
DY = floatabs(floatsub(y2,Y));
if (DY == 0.0 || DX == 0.0)
{
if(DY == 0 && DX > 0) angle = 0.0;
else if(DY == 0 && DX < 0) angle = 180.0;
else if(DY > 0 && DX == 0) angle = 90.0;
else if(DY < 0 && DX == 0) angle = 270.0;
else if(DY == 0 && DX == 0) angle = 0.0;
}
else
{
angle = atan(DX/DY);
if(X > x2 && Y <= y2) angle += 90.0;
else if(X <= x2 && Y < y2) angle = floatsub(90.0, angle);
else if(X < x2 && Y >= y2) angle -= 90.0;
else if(X >= x2 && Y > y2) angle = floatsub(270.0, angle);
}
return floatadd(angle, 90.0);
}
Maybe this, a friend gave it to me.
Re: What function would i use. -
Calgon - 20.12.2010
IsPlayerInRangeOfPoint is the most sufficient function for distance checking.
Quote:
Originally Posted by Lorenc_
pawn Код:
stock Float:GetPointAngleToPoint(Float:x2, Float:y2, Float:X, Float:Y) { new Float:DX, Float:DY; new Float:angle; DX = floatabs(floatsub(x2,X)); DY = floatabs(floatsub(y2,Y)); if (DY == 0.0 || DX == 0.0) { if(DY == 0 && DX > 0) angle = 0.0; else if(DY == 0 && DX < 0) angle = 180.0; else if(DY > 0 && DX == 0) angle = 90.0; else if(DY < 0 && DX == 0) angle = 270.0; else if(DY == 0 && DX == 0) angle = 0.0; } else { angle = atan(DX/DY); if(X > x2 && Y <= y2) angle += 90.0; else if(X <= x2 && Y < y2) angle = floatsub(90.0, angle); else if(X < x2 && Y >= y2) angle -= 90.0; else if(X >= x2 && Y > y2) angle = floatsub(270.0, angle); } return floatadd(angle, 90.0); }
Maybe this, a friend gave it to me.
|
You realize that's for facing angles and not player positions, right?
Re: What function would i use. -
Scenario - 20.12.2010
I am not sure exactly, but you may wish to give this a try:
pawn Код:
stock IsPlayerInRangeOfPlayer(playerid, otherid, Float:range)
{
new Float:Pos[3];
GetPlayerPos(otherid, Pos[0], Pos[1], Pos[2]);
if(IsPlayerInRangeOfPoint(playerid, range, Pos[0], Pos[1], Pos[2])) return true;
return false;
}
Re: What function would i use. -
Sledge - 20.12.2010
Quote:
Originally Posted by RealCop228
I am not sure exactly, but you may wish to give this a try:
pawn Код:
stock IsPlayerInRangeOfPlayer(playerid, otherid, Float:range) { new Float:Pos[3]; GetPlayerPos(otherid, Pos[0], Pos[1], Pos[2]); if(IsPlayerInRangeOfPoint(playerid, range, Pos[0], Pos[1], Pos[2])) return true; return false; }
|
that checks to see if you're near another player^^
Re: What function would i use. -
CrucixTM - 20.12.2010
You all fail.
IsPlayerInRangeOfPoint checks if the player is within a certain range.
OP wants to find out what the range is.
You will need a custom stock I'm afraid, but I can't seem to find any
Re: What function would i use. -
Lorenc_ - 20.12.2010
Quote:
Originally Posted by Calgon
IsPlayerInRangeOfPoint is the most sufficient function for distance checking.
You realize that's for facing angles and not player positions, right?
|
o.0 I fayul! Sorry about that..
Re: What function would i use. -
Nibblet - 20.12.2010
Maybe this?
pawn Код:
forward Float:GetDistanceBetweenPlayers(playerid,targetplayerid);
public Float:GetDistanceBetweenPlayers(playerid,targetplayerid)
{
new Float:x1,Float:y1,Float:z1,Float:x2,Float:y2,Float:z2;
if(!IsPlayerConnected(playerid) || !IsPlayerConnected(targetplayerid)) {
return -1.00;
}
GetPlayerPos(playerid,x1,y1,z1);
GetPlayerPos(targetplayerid,x2,y2,z2);
return floatsqroot(floatpower(floatabs(floatsub(x2,x1)),2)+floatpower(floatabs(floatsub(y2,y1)),2)+floatpower(floatabs(floatsub(z2,z1)),2));
}