08.08.2012, 11:20
It's easier to make a function that counts driving distance then "10 metres you drive" and it is more useful( if you want 10 counter just divide it with 10).
Didn't test if it works good.
#define DRIVING_DISTANCE_CHECKER 3000
if you want function to be more accurate lower the time(3000) that will cause more lag(don't think too much)
but it will be accurate.
http://postimage.org/image/neqq3klkx/
http://postimage.org/image/661gd2vuv/
Red line is distance, black is driving way.
pawn Code:
new Float:Distance[MAX_PLAYERS],Float:lx[MAX_PLAYERS],Float:ly[MAX_PLAYERS],Float:lz[MAX_PLAYERS];
new DDTimer[MAX_PLAYERS];
#define DRIVING_DISTANCE_CHECKER 3000
forward public DrivingDistanceTimer(playerid);
public DrivingDistanceTimer(playerid)
{
new id=GetPlayerVehicleID(playerid);
new Float:x,Float:y,Float:z;
GetVehiclePos(id,x,y,z);
Distance[playerid]+=floatsqroot(floatpower(x-lx[playerid],2)+floatpower(y-ly[playerid],2)+floatpower(y-ly[playerid],2));
lx[playerid]=x;ly[playerid]=y;lz[playerid]=z;
}
StartCountingDrivingDistance(playerid)
{
if(IsPlayerInAnyVehicle(playerid))
{
Distance[playerid]=0;
new id=GetPlayerVehicleID(playerid);
GetVehiclePos(id,lx[playerid],ly[playerid],lz[playerid]);
DDTimer[playerid]=SetTimerEx("DrivingDistanceTimer",DRIVING_DISTANCE_CHECKER,true,"d",playerid);
}
}
Float:StopCountingDrivingDistance(playerid)// OnPlayerExitVehicle,OnPlayerDisconnect, When player ejected from vehicle( put in jail, teleported to an event, etc.)
{
new Float:value=Distance[playerid];
Distance[playerid]=0;
KillTimer(DDTimer[playerid]);
return value;
}
//StopCountingDrivingDistance returns the distance
#define DRIVING_DISTANCE_CHECKER 3000
if you want function to be more accurate lower the time(3000) that will cause more lag(don't think too much)
but it will be accurate.
http://postimage.org/image/neqq3klkx/
http://postimage.org/image/661gd2vuv/
Red line is distance, black is driving way.