SA-MP Forums Archive
Kilometers made... - 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: Kilometers made... (/showthread.php?tid=570240)



Kilometers made... - Fjclip99 - 06.04.2015

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


AW: Kilometers made... - Mencent - 06.04.2015

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


Re: Kilometers made... - Kimossab - 06.04.2015

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.