/*Las Venturas Freeroam
 *Created By Assasin
 *All Rights Reserved(2006)
 *
*/

#if defined _dutils_included
  #endinput
#endif


enum SavePlayerPosEnum
{
    Float:LastX,
    Float:LastY,
    Float:LastZ
}
new SavePlayerPos[MAX_PLAYERS][SavePlayerPosEnum];
new SpeedMode = 0; 
new UpdateSeconds = 1;

    public UpdateSpeed(){
     new Float:x,Float:y,Float:z;
     new Float:distance,value,string[256];
     for(new i=0; i<MAX_PLAYERS; i++){
       if(IsPlayerConnected(i) && IsPlayerInAnyVehicle(i)){
       GetPlayerPos(i, x, y, z);
       distance = floatsqroot(floatpower(floatabs(floatsub(x,SavePlayerPos[i][LastX])),2)+floatpower(floatabs(floatsub(y,SavePlayerPos[i][LastY])),2)+floatpower(floatabs(floatsub(z,SavePlayerPos[i][LastZ])),2));
       value = floatround(distance * 3600);
     if(UpdateSeconds > 1){
       value = floatround(value / UpdateSeconds);
       }
     if(SpeedMode){
        format(string,sizeof(string),"~r~%d ~g~MP/~r~H",floatround(value/1600));
        GameTextForPlayer(i, string, 1100, 6);
       }
     else{
        format(string,sizeof(string),"~r~%d ~g~KM/~r~H",floatround(value/1000));
        GameTextForPlayer(i, string, 1100, 6);
       }
        SavePlayerPos[i][LastX] = x;
        SavePlayerPos[i][LastY] = y;
        SavePlayerPos[i][LastZ] = z;
       } 
    }    
 } 
public Float:GetDistanceBetweenPlayers(p1,p2){
new Float:x1,Float:y1,Float:z1,Float:x2,Float:y2,Float:z2;
if (!IsPlayerConnected(p1) || !IsPlayerConnected(p2)){
return -1.00;
}
GetPlayerPos(p1,x1,y1,z1);
GetPlayerPos(p2,x2,y2,z2);
return floatsqroot(floatpower(floatabs(floatsub(x2,x1)),2)+floatpower(floatabs(floatsub(y2,y1)),2)+floatpower(floatabs(floatsub(z2,z1)),2));
}
