Would this give a realistic kmh speedo
Code:
#define SLOTS 200
enum SavePlayerPosEnum {
Float:LastX,
Float:LastY,
Float:LastZ
}
new SavePlayerPos[SLOTS][SavePlayerPosEnum];
new Text:Speedo[SLOTS];
new UpdateSeconds;
forward UpdateSpeed();
Code:
SetTimer("UpdateSpeed",1000, 1);
Code:
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);
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),"~r~KM/H:%d",floatround(value/1600));
Speedo[i] = TextDrawCreate(560, 380,string);
TextDrawFont(Speedo[i], 1);
TextDrawColor(Speedo[i],COLOR_GREEN);
TextDrawSetShadow(Speedo[i],1);
TextDrawAlignment(Speedo[i],1);
TextDrawShowForPlayer (i, Speedo[i]);
TextDrawSetOutline(Speedo[i],1);
TextDrawBackgroundColor(Speedo[i],COLOR_BLACK);
}
SavePlayerPos[i][LastX] = x;
SavePlayerPos[i][LastY] = y;
SavePlayerPos[i][LastZ] = z;
}
}
Code:
public OnPlayerStateChange(playerid, newstate, oldstate)
{
if(newstate == PLAYER_STATE_ONFOOT)
{
TextDrawHideForPlayer(playerid, Speedo[playerid]);
}
return 1;
}