Kilometers made...
#1

Hello...
So I have a working speedometer that tells you what speed you are going... Now, I would like (if it is possible) that it would tell you how many kilometers you made...
Reply
#2

Hello!

Try this:
PHP код:
new Float:X1[MAX_VEHICLES],Float:X2[MAX_VEHICLES],Float:Y1[MAX_VEHICLES],Float:Y2[MAX_VEHICLES],Float:Z1[MAX_VEHICLES],Float:Z2[MAX_VEHICLES];
SetTimer("Kilometer",1000,1);
forward Kilometer();
public 
Kilometer()
{
    for(new 
i;i<MAX_VEHICLES;i++)
    {
        
X1[i] = X2[i];
        
Y1[i] = Y2[i];
        
Z1[i] = Z2[i];
        
GetVehiclePos(i,X2[i],Y2[i],Z2[i]);
        
X1[i] -= X2[i];
        
Y1[i] -= Y2[i];
        
Z1[i] -= Z2[i];
        new 
floatsqroot((X1[i]*X1[i])+(Y1[i]*Y1[i])+(Z1[i]*Z1[i]));
        
printf("Vehicle %d has driven %0.1fkm",i,d);
    }
    return 
1;

Mencent
Reply
#3

Let's suppose you got a 1 second timer to show the speed to the user.

Save his last speed on the timer. Sum it with the current speed and divide it by 2.

To calculate the speed he traveled in that second you just have to divide the last result with 3600.

1 hour = 60 minutes = 3600 seconds. If he traveled 120 Km in an hour then in 1 second he traveled 0.033 Km. Keep summing it up every time the timer ticks and you got his total km made.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)