how to get the speed? - 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: how to get the speed? (
/showthread.php?tid=161147)
how to get the speed? -
aNdReSk - 19.07.2010
:P I know speed is = distance/time but how do i manage to get that on samp
I read a couple of speedometers script and I cant fully understand it
Re: how to get the speed? -
(SF)Noobanatior - 19.07.2010
this is how i do it seems to work sweet
pawn Код:
stock GetPlayerSpeed(playerid){ //retuns speed in kmph (for mph use 125)
new Float:xx,Float:yy,Float:zz,Float:pSpeed;
if(IsPlayerInAnyVehicle(playerid))GetVehicleVelocity(GetPlayerVehicleID(playerid),xx,yy,zz);
else GetPlayerVelocity(playerid,xx,yy,zz);
pSpeed = floatmul(floatsqroot(floatpower(xx,2)+floatpower(yy,2)+floatpower(zz,2)),200);
return floatround(pSpeed);
}
change 200 to 125 in the 2nd to last line for mph
enjoy
Re: how to get the speed? -
aNdReSk - 19.07.2010
worked thx

and it's wayyyyyyyyyyyyy cleaner than other scripts i've seen :P
Re: how to get the speed? - [L3th4l] - 19.07.2010
sorry, instead of making another topic.
Using that GetPlayerSpeed Code, how could you do something like this
pawn Код:
if(GetPlayerSpeed(playerid) < 0 ) FuelLevel[vehicleid] --/2;
that code is under a fuel system, as you see if the player is not using speed, the fuel level keeps decreasin, but isntead of the normal decrease i would like to divide that by 2 or 4. im not sure if you put the --/2; or something else.