traveled distance save
#1

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(vehicleidx2y2z2);
        
        
x1 -= x2;
        
y1 -= y2;
        
z1 -= z2;
        
+= floatsqroot((x1*x1)+(y1*y1)+(z1*z1)) / 1000.0;
        
        
VehicleInfo[vehicleid][vMegtettUt] = d
Reply
#2

I'm not sure what you want, but I think this is what you're looking for.
Reply
#3

uuhm no.. when i am enter a vehicle and drive 1 km, the server save this to vehicleinfo..
Reply
#4

Код:
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.
Reply
#5

thanks! to show, "%.1f" is ok?
Reply
#6

Yep. I forgot to mention that.
Код:
format ( string , sizeof ( string ) , "~w~Kilometers: %.1f" , CarInfo [ peid ] [ cKilometri ] ) ;
Reply
#7

and how long to take 1 km in time?
Reply
#8

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

PHP код:
stock kmsaver(id,vehicleid)
{
    new
    
FloatOldPos MAX_PLAYERS ] [ ] ,
        
FloatDistanceKM MAX_PLAYERS ] ;
    
OldPos id ] [ ] = VehicleOPos id ] [ ] ;
    
OldPos id ] [ ] = VehicleOPos id ] [ ] ;
    
OldPos id ] [ ] = VehicleOPos id ] [ ] ;
    
GetPlayerPos id VehicleOPos id ] [ ] , VehicleOPos id ] [ ] , VehicleOPos id ] [ ] ) ;
    
DistanceKM id ] = GetDistanceBetweenPoints1 OldPos id ] [ ] , OldPos id ] [ ] , OldPos id ] [ ] , VehicleOPos id ] [ ] , VehicleOPos id ] [ ] , VehicleOPos id ] [ ] ) ;
    
VehicleInfo[vehicleid][vMegtettUt] += DistanceKM id ] / 1000 ;
    return 
1;

PHP код:
forward Float:GetDistanceBetweenPoints1 FloatOldX FloatOldY FloatOldZ FloatNewX FloatNewY FloatNewZ ) ;
public 
Float:GetDistanceBetweenPoints1 FloatOldX FloatOldY FloatOldZ FloatNewX FloatNewY FloatNewZ ) {
        return 
floatsqroot floatpower floatabs floatsub NewX OldX ) ) , ) + floatpower floatabs floatsub NewY OldY ) ) , ) +floatpower floatabs floatsub NewZ OldZ ) ) , ) ) ;

OnPlayerStateChange if(newstate == 2):
PHP код:
        SetPVarInt(playerid"kmsaver1"SetTimerEx("kmsaver"100true"i"playerid)); 
why its alwasy 0.0? its not workin for me:/
Reply
#10

anyone?
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)