[HELP] Problem on GetDistance function. (I think) - 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: [HELP] Problem on GetDistance function. (I think) (
/showthread.php?tid=293815)
[HELP] Problem on GetDistance function. (I think) -
Avalanche! - 30.10.2011
I made a GPS system that use a timer and a loop to compare the distance between two players, but when I'll activate this function on ID 0, the distance goes far far away from the real distance.
Код:
stock GetDistance(playerid, playerid2)
{
new Float:x1,Float:y1,Float:z1,Float:x2,Float:y2,Float:z2;
new Float:dis;
GetPlayerPos(playerid,x1,y1,z1);
GetPlayerPos(playerid2,x2,y2,z2);
dis = floatsqroot((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1)+(z2-z1)*(z2-z1));
return floatround(dis);
}
For example: "I typed: /gps 0", the real distance is 60m, but in my textdraw it shows 3000m (m = meters)
sorry 4 my bad english, thanks a lot!!!
Re: [HELP] Problem on GetDistance function. (I think) -
Backwardsman97 - 30.10.2011
Is it really way off or is it still consistent? It may not be super accurate on the game units but as long as it's consistent, it should be fine. You could still format it need be.
Re: [HELP] Problem on GetDistance function. (I think) -
Vince - 30.10.2011
1 unit ingame = 1 meter, considering that when you import a skin into 3D's max its height is 1.85 units. If your friend is really across half the map (SA map is 6000x6000), then that's correct. Otherwise, try this function:
pawn Код:
stock Float:GetDistanceBetweenPlayers(p1, p2)
{
new
Float:x1,
Float:y1,
Float:z1,
Float:x2,
Float:y2,
Float:z2;
if(!GetPlayerPos(p1,x1,y1,z1) || !GetPlayerPos(p2,x2,y2,z2)) return FLOAT_NAN;
return GetDistanceBetweenPoints(x1, y1, z1, x2, y2, z2);
}
stock Float:GetDistanceBetweenPoints(Float:x1, Float:y1, Float:z1, Float:x2, Float:y2, Float:z2)
{
// By ******
x1 -= x2;
y1 -= y2;
z1 -= z2;
return floatsqroot((x1 * x1) + (y1 * y1) + (z1 * z1));
}
stock IsNaN(Float:number)
{
return (number != number);
}