20.12.2010, 00:28
If i wanted to measure the distance from player to player what function would i use.
Thanks in advance.
Thanks in advance.
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);
}
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;
}
I am not sure exactly, but you may wish to give this a try:
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));
}