PDA

View Full Version : mileage in meters


Skibi184
17/04/2014, 10:12 PM
How to calculate the mileage in meters. I mean how to get the amount of meters the player drove in a car :D

Vince
17/04/2014, 10:52 PM
Every time you update your speedometer, get the player's position. Then compare it with the last known position to calculate the distance between the two points (or disregard it in case the distance is too great). Add the result to a global player variable.

Skibi184
17/04/2014, 11:30 PM
Would something like this work?
new Float:p[3][MAX_PLAYERS],Float:pNow[MAX_PLAYERS],Float:aNow[MAX_PLAYERS],Float:actualDistance[MAX_PLAYERS],Float:newDistance[3][MAX_PLAYERS];

public OnPlayerUpdate(playerid)
{
if(IsPlayerInAnyVehicle(playerid) && GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
{
if(newDistance[0||1||2][playerid] == 0)
{
GetPlayerPos(playerid, newDistance[0][playerid], newDistance[1][playerid], newDistance[2][playerid]);
}
else
{
GetPlayerPos(playerid, p[0][playerid], p[1][playerid], p[2][playerid]);
pNow[playerid] = p[0][playerid]+=p[1][playerid]+=p[2][playerid];
aNow[playerid] = newDistance[0][playerid]+=newDistance[1][playerid]+=newDistance[2][playerid];
actualDistance[playerid] = pNow[playerid]-=aNow[playerid];
newDistance[0&&1&&2][playerid]=0;
p[0&&1&&2][playerid]=0;
}
}
return 1;
}