Measure distance - 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)
+---- Forum: Help Archive (
https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Measure distance (
/showthread.php?tid=269226)
Measure distance -
blackwave - 15.07.2011
I'm here asking how to measure a certain distance, as i saw on gamerx the race stats, showing the track lenght of the race: 6.21km. So, i'd like to know how to measure a certain lenght on KM.
Re: Measure distance -
Mojzesz - 15.07.2011
There are few ways to do this, based on timers. You can, for example, check player's vehicle speed every second and depending on it, you can add some values to the distance variable. Look for mileages filterscripts on forums and edit it for your own needs.
Re: Measure distance -
Lorenc_ - 15.07.2011
You'll need a algorithm, its not that easy finding a distance from one point to another and calculating the KM. No, you don't need a timer for this.
Re: Measure distance -
RyDeR` - 15.07.2011
You just have to calculate the distance between all checkpoints and add it with each other. Easy as that.
Re: Measure distance -
Sascha - 15.07.2011
pawn Код:
stock GetDistance(Float:x1, Float:y1, Float:z1, Float:x2, Float:y2, Float:z2)
{
new Float:rst, Float:xd, Float:yd, Float:zd;
x1 = floatabs(x1); x2 = floatabs(x2); y1 = floatabs(y1); y2 = floatabs(y2); z1 = floatabs(z1); z2 = floatabs(z2);
xd = x2 - x1; xd = floatabs(xd);
yd = y2 - y1; yd = floatabs(yd);
zd = z2 - z2; zd = floatabs(zd);
rst = ((xd * xd) + (yd * yd*) + (zd * zd));
return rst;
}
a code to calculate the distance between each checkpoint... I have no clue whether this actually works however you might want to try it out xD
Re: Measure distance -
blackwave - 15.07.2011
thanks 4all
Re: Measure distance -
Donya - 15.07.2011
ohh yea <<< post after this
Re: Measure distance -
Backwardsman97 - 16.07.2011
Yeah but most races aren't just a straight shot. You need to do what the earlier post said. Add the distances from each checkpoint to the next. You don't even need to do it during run-time unless you're lazy. It might take time but it's not hard.
pawn Код:
dist = sqrt((x2-x1)^2 + (y2-y1)^2 + (z2-z1)^2)
There's a 3d distance formula.
Re: Measure distance -
dowster - 16.07.2011
Quote:
Originally Posted by Sascha
pawn Код:
stock GetDistance(Float:x1, Float:y1, Float:z1, Float:x2, Float:y2, Float:z2) { new Float:rst, Float:xd, Float:yd, Float:zd; x1 = floatabs(x1); x2 = floatabs(x2); y1 = floatabs(y1); y2 = floatabs(y2); z1 = floatabs(z1); z2 = floatabs(z2); xd = x2 - x1; xd = floatabs(xd); yd = y2 - y1; yd = floatabs(yd); zd = z2 - z2; zd = floatabs(zd); rst = ((xd * xd) + (yd * yd*) + (zd * zd)); return rst; }
a code to calculate the distance between each checkpoint... I have no clue whether this actually works however you might want to try it out xD
|
Код:
#define DISTANCE(%1,%2,%3,%4,%5,%6) floatsqroot((%1-%4)*(%1-%4) + (%2-%5)*(%2-%5) + (%3-%6)*(%3-%6))
KAPOW!! one line XD
just use like distance = DISTANCE( x1, y1, z1, x2, y2, z2);