SA-MP Forums Archive
Distance Travelled. - 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: Distance Travelled. (/showthread.php?tid=476769)



Distance Travelled. - RedCounty - 20.11.2013

How can I get the distance travelled by a player? all help is appreciated, thanks


Re: Distance Travelled. - Voxel - 20.11.2013

You could make a timer that contineu's everytime the player moves (using getplayerpos), so lets say every second is 1 meter, you could convert the seconds to meters (if he ran for 60 seconds it means its 60 meters) this is how ever not accurate offcourse , its just a idea, GL!


Re: Distance Travelled. - RedCounty - 20.11.2013

Is there any other ways, due to me using that method already and it's not suffice for me. It doesn't calculate them correctly.

I've seen a few servers with "Distance travelled: %d km", how would they get it? It seems so accurate!


Re: Distance Travelled. - Jakku - 20.11.2013

Imagine it this way:

If you're travelling 100 kilometers per hour, you travel 27,8 meters per second.
If you divide 27,8 by 100, you'll get 0,278.
Therefore, if you drive 1km/h, it's 0,278 meters more for your counter.

If your speed is 55km/h:

55km/h * 0,278 = 15,29 m/s.

This is pseudocode but you'll realize the idea

pawn Код:
SetTimer Distance 1000 1

public Distance()
{
  new Float: speed = float(player's current speed in km/h);
  Float: playerdistance+=0,278*speed;
}