SA-MP Forums Archive
mileage in meters - 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: mileage in meters (/showthread.php?tid=507490)



mileage in meters - Skibi184 - 17.04.2014

How to calculate the mileage in meters. I mean how to get the amount of meters the player drove in a car


Re: mileage in meters - Vince - 17.04.2014

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.


Re: mileage in meters - Skibi184 - 17.04.2014

Would something like this work?
Quote:

new Float[3][MAX_PLAYERS],FloatNow[MAX_PLAYERS],Float:aNow[MAX_PLAYERS],Float:actualDistance[MAX_PLAYERS],Float:newDistance[3][MAX_PLAYERS];

Quote:

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;
}