Weird speed readings... - 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: Weird speed readings... (
/showthread.php?tid=311229)
Weird speed readings... -
Scenario - 15.01.2012
Okay, watch the speed in the video (aka. look at the TDs).
[ame]http://www.youtube.com/watch?v=mpUcxMGwQ8M[/ame]
Notice how the speed is jumping? What could be causing that? Here's the code:
pawn Код:
timer vehicleDashboard[500](playerid, vehicleid)
{
// some other functions here
new szString[23];
format(szString, sizeof(szString), "%d MP/H %d KM/H", GetVehicleSpeed(vehicleid, true), GetVehicleSpeed(vehicleid, false));
TextDrawSetString(vehicleSpeedTD[playerid], szString);
}
stock GetVehicleSpeed(vehicleid, bool:MPH = true)
{
new Float:x, Float:y, Float:z, vel;
GetVehicleVelocity( vehicleid, x, y, z );
if(MPH == true) vel = floatround( floatsqroot( x*x + y*y + z*z ) * 180 / 1.609344 ); // MPH
else vel = floatround( floatsqroot( x*x + y*y + z*z ) * 180 ); // KPH
return vel;
}
Re: Weird speed readings... -
Kar - 15.01.2012
180? try 200 and it's better to use the functions instead of the operators.
pawn Код:
stock GetPlayerSpeed(playerid, bool:kmh)
{
new Float:Speed, Float:x, Float:y, Float:z;
if(IsPlayerInAnyVehicle(playerid)) GetVehicleVelocity(GetPlayerVehicleID(playerid), x, y, z);
else GetPlayerVelocity(playerid, x, y, z);
Speed = floatmul(floatsqroot(floatadd(floatadd(floatpower(x, 2), floatpower(y, 2)), floatpower(z, 2))), 200.0); //100.0
return kmh == true ? floatround(Speed, floatround_floor) : floatround(floatdiv(Speed, 1.609344), floatround_floor);
}
Re: Weird speed readings... -
Babul - 15.01.2012
ask the other player to stop for some time, then i bet it will "jump " to 0 speed constantly (before your textdraw gets written). its most prolly some timer[] bug, idk how i should interpret timer[500], maybe these are mixing up with playerid?