Explanation ? - 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: Explanation ? (
/showthread.php?tid=74750)
Explanation ? -
Bearfist - 25.04.2009
Could someone explain me this..I added it from a speedometer..
want to understand it ^^
Код:
distance = floatsqroot(floatpower(floatabs(floatsub(x,SavePlayerPos[i][LastX])),2)+floatpower(floatabs(floatsub(y,SavePlayerPos[i][LastY])),2)+floatpower(floatabs(floatsub(z,SavePlayerPos[i][LastZ])),2));
value = floatround(distance * 5000);
Bearfist
PS:Please explain x'D
Re: Explanation ? -
yom - 25.04.2009
http://www.purplemath.com/modules/distform.htm
Re: Explanation ? -
Weirdosport - 25.04.2009
It works out the difference in x y and z, squares them and then routes the whole thing. It's Pythagoras's theorem used for 3D co-ordinates. I still don't know why floatabs is there, as squaring a number makes it positive anyway.. maybe floatpower can't cope with negative numbers..
Re: Explanation ? -
Bearfist - 25.04.2009
alright thanks to both ..
then i will learn it
....what is FloatPower doing in that function ??
Bearfist
Re: Explanation ? -
Weirdosport - 25.04.2009
Floatpower provides the squared bit.
That squares the thing, thing^2. If it was a 3 not a 2 it would be cubed.
Re: Explanation ? -
yom - 25.04.2009
equivalent to:
Re: Explanation ? -
Bearfist - 25.04.2009
Thanks a lot ..
now I understanded the hole function =)
*happy* xD
Bearfist
Re: Explanation ? -
Weirdosport - 25.04.2009
Yeah it looks pretty messy at first
Re: Explanation ? -
Bearfist - 25.04.2009
yeah so I got these (speedo)function
Код:
public UpdateSpeed()
{
new Float:x,Float:y,Float:z;
new Float:distance,value,string[256];
new Float:health;
for(new i=0; i<SLOTS; i++)
{
if(IsPlayerConnected(i) && IsPlayerInAnyVehicle(i))
{
TextDrawDestroy(Speedo[i]);
}
}
for(new i=0; i<SLOTS; i++)
{
if(IsPlayerConnected(i) && IsPlayerInAnyVehicle(i))
{
GetPlayerPos(i, x, y, z);
GetVehicleHealth(GetPlayerVehicleID(i), health);
distance = floatsqroot(floatpower(floatabs(floatsub(x,SavePlayerPos[i][LastX])),2)+floatpower(floatabs(floatsub(y,SavePlayerPos[i][LastY])),2)+floatpower(floatabs(floatsub(z,SavePlayerPos[i][LastZ])),2));
value = floatround(distance * 5000);
if(UpdateSeconds > 1)
{
value = floatround(value / UpdateSeconds);
}
format(string,sizeof(string),"~g~Vehicle : ~w~%s ~n~~b~MPH : ~w~%d / ~b~KM/H : ~w~%d~n~~y~Altitude:~w~ %.1f ~n~~r~Vehicle Health:~w~ %.2f",CarName[GetVehicleModel(GetPlayerVehicleID(i))-400],floatround(value/1600),floatround(value/1000),z,health);
Speedo[i] = TextDrawCreate(320.00, 380.00, string);
TextDrawSetOutline(Speedo[i], 0);
TextDrawFont(Speedo[i], 3);
TextDrawSetProportional(Speedo[i], 2);
TextDrawAlignment(Speedo[i], 2);
TextDrawShowForPlayer (i, Speedo[i]);
}
SavePlayerPos[i][LastX] = x;
SavePlayerPos[i][LastY] = y;
SavePlayerPos[i][LastZ] = z;
}
}
...but i only want to have the speed ...
I tried to delete the others from it ...
but the km/h isn't the same before deleting the lines =(
Need help
Bearfist