Driver Distance - 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: Driver Distance (
/showthread.php?tid=366952)
Driven Distance -
Jstylezzz - 08.08.2012
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
Re: Driver Distance -
CROSS_Hunter - 08.08.2012
kinda weird.. but nice idea
Re: Driver Distance -
Roko_foko - 08.08.2012
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.
Re: Driver Distance -
Jstylezzz - 08.08.2012
Quote:
Originally Posted by Roko_foko
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!