#undef MAX_PLAYERS // Undefines MAX_PLAYERS
#define MAX_PLAYERS YourTrueLimitOfPlayer // Setting th MAX_PLAYERS to your true limit, but you can't write that you have to put your value for YourTrueLimitOfPlayer in
new PlayerText:Velocity[MAX_PLAYERS];
Velocity[playerid] = CreatePlayerTextDraw(playerid,520,320,"_~N~Velocity: 0~N~Health: 0~N~_");
PlayerTextDrawTextSize(playerid,Velocity[playerid],630,0);
PlayerTextDrawUseBox(playerid,Velocity[playerid],1);
PlayerTextDrawBoxColor(playerid,Velocity[playerid],0x00000066);
PlayerTextDrawHide(playerid,Velocity[playerid]);
public OnPlayerConnect(playerid)
{
Velocity[playerid] = CreatePlayerTextDraw(playerid,520,320,"_~N~Velocity: 0~N~Health: 0~N~_");
PlayerTextDrawTextSize(playerid,Velocity[playerid],630,0);
PlayerTextDrawUseBox(playerid,Velocity[playerid],1);
PlayerTextDrawBoxColor(playerid,Velocity[playerid],0x00000066);
PlayerTextDrawHide(playerid,Velocity[playerid]);
return 1;
}
forward VehicleUpdate();
SetTimer("VehicleUpdate",1*500,1);
public VehicleUpdate()
{
for(new i = 0;i < MAX_PLAYERS; i++)
{
}
return 1;
}
public VehicleUpdate()
{
for(new i = 0;i < MAX_PLAYERS; i++) // i is the playerid
{
if(IsPlayerInAnyVehicle(i) == 1) // You could also write if(IsPlayerInAnyVehicle(i))
{
}
else if(!IsPlayerInAnyVehicle(i)) // You could also write else if(IsPlayerInAnyVehicle(i) == 0))
{
PlayerTextDrawHide(i,Velocity[i]); // The TextDraw has to be hidden
}
}
return 1;
}
new vehicleid = GetPlayerVehicleID(i);
stock GetMph(vehicleid)
{
}
stock GetMph(vehicleid)
{
new Float:x,Float:y,Float:z; // Creating Float variables
GetVehicleVelocity(vehicleid,x,y,z); // Writing in the x,y,z coordinates the speed values.
return floatround(floatsqroot((x*x)+(y*y)+(z*z))*156.666667); // It returns the mph of the vehicle, floatround converts a float into a integer
}
public VehicleUpdate()
{
for(new i = 0;i < MAX_PLAYERS; i++) // i is the playerid
{
if(IsPlayerInAnyVehicle(i) == 1) // You could also write if(IsPlayerInAnyVehicle(i))
{
new vehicleid = GetPlayerVehicleID(i); // Getting the vehicleid, and write it into the vehicleid variable
new mph = GetMph(vehicleid); // Using our function to get the mph velocity of our vehicle
}
else if(!IsPlayerInAnyVehicle(i)) // You could also write else if(IsPlayerInAnyVehicle(i) == 0))
{
PlayerTextDrawHide(i,Velocity[i]); // The TextDraw has to be hidden
}
}
return 1;
}
new Float:health;
GetVehicleHealth(vehicleid,health); //writing in health the health of the vehicle
new string[256];
format(string,sizeof(string),"_~N~Velocity: %i~N~Health: %i%%~N~_",mph,floatround(health / 10)); // %i if you want to write an integer variable into the string, %% if you want to write a %, we want to show health with per cents so we have to to 'health / 10'
PlayerTextDrawSetString(i,Velocity[i],string);
PlayerTextDrawShow(i,Velocity[i]);
public VehicleUpdate()
{
for(new i = 0;i < MAX_PLAYERS; i++) // i is the playerid
{
if(IsPlayerInAnyVehicle(i) == 1) // You could also write if(IsPlayerInAnyVehicle(i))
{
new vehicleid = GetPlayerVehicleID(i); // Getting the vehicleid, and write it into the vehicleid variable
new mph = GetMph(vehicleid); // Using our function to get the mph velocity of our vehicle
new Float:health;
GetVehicleHealth(vehicleid,health); //Getting the vehicle's health
new string[256];
format(string,sizeof(string),"_~N~Velocity: %i~N~Health: %i%%~N~_",mph,floatround(health / 10)); // %i if you want to write an integer variable into the string, %% if you want to write a %, we want to show health with per cents so we have to to 'health / 10'
PlayerTextDrawSetString(i,Velocity[i],string); // setting the PlayerTextDraw string
PlayerTextDrawShow(i,Velocity[i]); // Showing the TextDraw to the player i
}
else if(!IsPlayerInAnyVehicle(i)) // You could also write else if(IsPlayerInAnyVehicle(i) == 0))
{
PlayerTextDrawHide(i,Velocity[i]); // The TextDraw has to be hidden
}
}
return 1;
}
public VehicleUpdate()
{
for(new i = 0;i < MAX_PLAYERS; i++) // i is the playerid
{
if(IsPlayerConnected(i)) // the same as if(IsPlayerConnected(i) == 1)
{
if(IsPlayerInAnyVehicle(i) == 1) // You could also write if(IsPlayerInAnyVehicle(i))
{
new vehicleid = GetPlayerVehicleID(i); // Getting the vehicleid, and write it into the vehicleid variable
new mph = GetMph(vehicleid); // Using our function to get the mph velocity of our vehicle
new Float:health;
GetVehicleHealth(vehicleid,health); //writing in health the health of the vehicle
new string[256];
format(string,sizeof(string),"_~N~Velocity: %i~N~Health: %i%%~N~_",mph,floatround(health / 10)); // %i if you want to write an integer variable into the string, %% if you want to write a %, we want to show health with per cents so we have to to 'health / 10'
PlayerTextDrawSetString(i,Velocity[i],string); // setting the PlayerTextDraw string
PlayerTextDrawShow(i,Velocity[i]); // Showing the TextDraw to the player i
}
else if(!IsPlayerInAnyVehicle(i)) // You could also write else if(IsPlayerInAnyVehicle(i) == 0))
{
PlayerTextDrawHide(i,Velocity[i]); // The TextDraw has to be hidden
}
}
else if(!IsPlayerConnected(i)) //same as if(IsPlayerConnected(i) == 0)
{
PlayerTextDrawHide(i,Velocity[i]); // The TextDraw has to be hidden
}
}
return 1;
}
#undef MAX_PLAYERS // Undefines MAX_PLAYERS
#define MAX_PLAYERS YourTrueLimitOfPlayer // Setting th MAX_PLAYERS to your true limit, but you can't write that you have to put your value for YourTrueLimitOfPlayer in
new PlayerText:Velocity[MAX_PLAYERS];
forward VehicleUpdate(); // forwarding VehicleUpdate();
public OnGameModeInit()
{
SetTimer("VehicleUpdate",1*500,1);
return 1;
}
public OnPlayerConnect(playerid)
{
Velocity[playerid] = CreatePlayerTextDraw(playerid,520,320,"_~N~Velocity: 0~N~Health: 0~N~_");
PlayerTextDrawTextSize(playerid,Velocity[playerid],630,0);
PlayerTextDrawUseBox(playerid,Velocity[playerid],1);
PlayerTextDrawBoxColor(playerid,Velocity[playerid],0x00000066);
PlayerTextDrawHide(playerid,Velocity[playerid]);
return 1;
}
stock GetMph(vehicleid)
{
new Float:x,Float:y,Float:z; // Creating Float variables
GetVehicleVelocity(vehicleid,x,y,z); // Writing in the x,y,z coordinates the speed values.
return floatround(floatsqroot((x*x)+(y*y)+(z*z))*156.666667); // It returns the mph of the vehicle
}
public VehicleUpdate()
{
for(new i = 0;i < MAX_PLAYERS; i++) // i is the playerid
{
if(IsPlayerConnected(i)) // the same as if(IsPlayerConnected(i) == 1)
{
if(IsPlayerInAnyVehicle(i) == 1) // You could also write if(IsPlayerInAnyVehicle(i))
{
new vehicleid = GetPlayerVehicleID(i); // Getting the vehicleid, and write it into the vehicleid variable
new mph = GetMph(vehicleid); // Using our function to get the mph velocity of our vehicle
new Float:health;
GetVehicleHealth(vehicleid,health); //writing in health the health of the vehicle
new string[256];
format(string,sizeof(string),"_~N~Velocity: %i~N~Health: %i%%~N~_",mph,floatround(health / 10)); // %i if you want to write an integer variable into the string, %% if you want to write a %, we want to show health with per cents so we have to to 'health / 10'
PlayerTextDrawSetString(i,Velocity[i],string); // setting the PlayerTextDraw string
PlayerTextDrawShow(i,Velocity[i]); // Showing the TextDraw to the player i
}
else if(!IsPlayerInAnyVehicle(i)) // You could also write else if(IsPlayerInAnyVehicle(i) == 0))
{
PlayerTextDrawHide(i,Velocity[i]); // The TextDraw has to be hidden
}
}
else if(!IsPlayerConnected(i)) //same as if(IsPlayerConnected(i) == 0)
{
PlayerTextDrawHide(i,Velocity[i]); // The TextDraw has to be hidden
}
}
return 1;
}
Now we need the formula to find out the kph.
It's floatsqroot((x*x)+(y*y)+(z*z))*156.666667; This is incorrect it is floatsqroot((x*x)+(y*y)+(z*z))*180.0; I suggest fixing it so the noobs get it right. |
Now we need the formula to find out the kph.
It's floatsqroot((x*x)+(y*y)+(z*z))*156.666667; This is incorrect it is floatsqroot((x*x)+(y*y)+(z*z))*180.0; I suggest fixing it so the noobs get it right. |
Well if you look at this include.
https://sampforum.blast.hk/showthread.php?tid=486060 It has all the correct top speeds for vehicles. The reason everyone uses the incorrect formula is because of posts like this that uses the incorrect formula people just copy paste code. If you use 180 it will show approximately the correct values. |