Driver Distance
#1

Hi everyone,
I searched all over the internet, but i can't find any stock function/anything that helps me further.
I am thinking of a stock function, or any function, that counts every 10 metres you drive.
This doesn't have to be accurate(would be cool, but i understand that this is hard to do)..
I hope someone knows how to help me further.

Thanks in advance
Reply
#2

kinda weird.. but nice idea
Reply
#3

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).

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
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.
Reply
#4

Quote:
Originally Posted by Roko_foko
View Post
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).

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
Didn't test if it works good.
This type of function, was exactly what i was looking for..
Thanks alot!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)