17.08.2014, 20:33
Hello, any ideas how to get vehicle traveld distance in km?
Use a GetVehicleSpeed function (based on GetVehicleVelocity) and calculate the km per second (that would be km per hour / 3600) and add that value in a 1 second timer to a variable
|
enum ODOMETERINFO {
Float:LastX,
Float:LastY,
Float:LastZ,
Float:LastSpeed,
Float:OdoDist,
}
static OdometerData[MAX_PLAYERS][ODOMETERINFO];
Float:GetVehicleSpeed(playerid)
{
new Float:vx, Float:vy, Float:vz;
GetVehicleVelocity(GetPlayerVehicleID(playerid), vx, vy, vz);
return (floatsqroot(((vx*vx)+(vy*vy))+(vz*vz))* 180.0);
}
public OnPlayerUpdate(playerid)
{
if(IsPlayerInAnyVehicle(playerid) && GetPlayerVehicleSeat(playerid) == 0)
{
new vid = GetPlayerVehicleID(playerid);
OdometerData[playerid][OdoDist] = GetVehicleDistanceFromPoint(vid, OdometerData[playerid][LastX], OdometerData[playerid][LastY], OdometerData[playerid][LastZ]);
GetPlayerPos(OdometerData[playerid][LastX], OdometerData[playerid][LastY], OdometerData[playerid][LastZ]);
OdometerData[playerid][LastSpeed] = GetVehicleSpeed(playerid);
}
return 1;
}
public OnPlayerStateChange(playerid, newstate, oldstate)
{
if(oldstate == PLAYER_STATE_ONFOOT && newstate == PLAYER_STATE_DRIVER)
GetPlayerPos(OdometerData[playerid][LastX], OdometerData[playerid][LastY], OdometerData[playerid][LastZ]);
OdometerData[playerid][LastSpeed] = GetVehicleSpeed(playerid);
}