traveled distance save -
n00el - 12.05.2014
hy, i want to save the vehicle's travel in km.. but its not the best. i am go to down ant left, its go to negative.. any system for this?
PHP код:
new
Float:d,
Float:x1,
Float:y1,
Float:z1,
Float:x2,
Float:y2,
Float:z2;
x1 = x2;
y1 = y2;
z1 = z2;
GetVehiclePos(vehicleid, x2, y2, z2);
x1 -= x2;
y1 -= y2;
z1 -= z2;
d += floatsqroot((x1*x1)+(y1*y1)+(z1*z1)) / 1000.0;
VehicleInfo[vehicleid][vMegtettUt] = d;
Re: traveled distance save -
DiGiTaL_AnGeL - 12.05.2014
I'm not sure what you want, but I think
this is what you're looking for.
Re: traveled distance save -
n00el - 12.05.2014
uuhm no.. when i am enter a vehicle and drive 1 km, the server save this to vehicleinfo..
Re: traveled distance save -
Koala818 - 12.05.2014
Код:
new Float:VehicleOPos[MAX_PLAYERS][3];
stock VehicleOdometer ( id , vehicleid ) {
new
Float: OldPos [ MAX_PLAYERS ] [ 3 ] ,
Float: DistanceKM [ MAX_PLAYERS ] ;
OldPos [ id ] [ 0 ] = VehicleOPos [ id ] [ 0 ] ;
OldPos [ id ] [ 1 ] = VehicleOPos [ id ] [ 1 ] ;
OldPos [ id ] [ 2 ] = VehicleOPos [ id ] [ 2 ] ;
GetPlayerPos ( id , VehicleOPos [ id ] [ 0 ] , VehicleOPos [ id ] [ 1 ] , VehicleOPos [ id ] [ 2 ] ) ;
DistanceKM [ id ] = GetDistanceBetweenPoints ( OldPos [ id ] [ 0 ] , OldPos [ id ] [ 1 ] , OldPos [ id ] [ 2 ] , VehicleOPos [ id ] [ 0 ] , VehicleOPos [ id ] [ 1 ] , VehicleOPos [ id ] [ 2 ] ) ;
CarInfo [ peid ] [ cKilometri ] += DistanceKM [ id ] / 1000 ;
return 1 ;
}
Код:
forward Float:GetDistanceBetweenPoints ( Float: OldX , Float: OldY , Float: OldZ , Float: NewX , Float: NewY , Float: NewZ ) ;
public Float:GetDistanceBetweenPoints ( Float: OldX , Float: OldY , Float: OldZ , Float: NewX , Float: NewY , Float: NewZ ) {
return floatsqroot ( floatpower ( floatabs ( floatsub ( NewX , OldX ) ) , 2 ) + floatpower ( floatabs ( floatsub ( NewY , OldY ) ) , 2 ) +floatpower ( floatabs ( floatsub ( NewZ , OldZ ) ) , 2 ) ) ;
}
Now call vehicleOdometer when a player is in a car every 100ms or so. Replace the variables with yours.
Re: traveled distance save -
n00el - 12.05.2014
thanks! to show, "%.1f" is ok?
Re: traveled distance save -
Koala818 - 12.05.2014
Yep. I forgot to mention that.
Код:
format ( string , sizeof ( string ) , "~w~Kilometers: %.1f" , CarInfo [ peid ] [ cKilometri ] ) ;
Re: traveled distance save -
n00el - 12.05.2014
and how long to take 1 km in time?
Re: traveled distance save -
Koala818 - 12.05.2014
It's not about time, but about how long does the player travels. If he travels 50 units (oldpos vs actualpos) in the variable will appear 50/1000 = 0,05. So when he travels 1000 units the function will save 1km.
Re: traveled distance save -
n00el - 12.05.2014
PHP код:
stock kmsaver(id,vehicleid)
{
new
Float: OldPos [ MAX_PLAYERS ] [ 3 ] ,
Float: DistanceKM [ MAX_PLAYERS ] ;
OldPos [ id ] [ 0 ] = VehicleOPos [ id ] [ 0 ] ;
OldPos [ id ] [ 1 ] = VehicleOPos [ id ] [ 1 ] ;
OldPos [ id ] [ 2 ] = VehicleOPos [ id ] [ 2 ] ;
GetPlayerPos ( id , VehicleOPos [ id ] [ 0 ] , VehicleOPos [ id ] [ 1 ] , VehicleOPos [ id ] [ 2 ] ) ;
DistanceKM [ id ] = GetDistanceBetweenPoints1 ( OldPos [ id ] [ 0 ] , OldPos [ id ] [ 1 ] , OldPos [ id ] [ 2 ] , VehicleOPos [ id ] [ 0 ] , VehicleOPos [ id ] [ 1 ] , VehicleOPos [ id ] [ 2 ] ) ;
VehicleInfo[vehicleid][vMegtettUt] += DistanceKM [ id ] / 1000 ;
return 1;
}
PHP код:
forward Float:GetDistanceBetweenPoints1 ( Float: OldX , Float: OldY , Float: OldZ , Float: NewX , Float: NewY , Float: NewZ ) ;
public Float:GetDistanceBetweenPoints1 ( Float: OldX , Float: OldY , Float: OldZ , Float: NewX , Float: NewY , Float: NewZ ) {
return floatsqroot ( floatpower ( floatabs ( floatsub ( NewX , OldX ) ) , 2 ) + floatpower ( floatabs ( floatsub ( NewY , OldY ) ) , 2 ) +floatpower ( floatabs ( floatsub ( NewZ , OldZ ) ) , 2 ) ) ;
}
OnPlayerStateChange if(newstate == 2):
PHP код:
SetPVarInt(playerid, "kmsaver1", SetTimerEx("kmsaver", 100, true, "i", playerid));
why its alwasy 0.0? its not workin for me:/
Re: traveled distance save -
n00el - 13.05.2014
anyone?