Announcement

Collapse
No announcement yet.

Recreate GetVehicleForwardSpeed in ServerSide

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Recreate GetVehicleForwardSpeed in ServerSide

    Hello, I'm trying to get the same value as the GetVehicleForwardSpeed function but on the server side, but by the way, the velocity doesn't work very well.
    Code:
            local speed = math.tointeger(math.floor(GetVehicleForwardSpeed(GetPlayerVehicle())))
            AddPlayerChat("Speed: "..speed.." km/h")
    
            local x, y, z = GetVehicleVelocity(GetPlayerVehicle())
            x = math.abs(x)
            y = math.abs(y)
            z = math.abs(z)
            local hmh = math.floor((190*math.abs(x+y+z))/ 5320.7950973511)
            AddPlayerChat("Velocity: "..hmh)
            AddPlayerChat("------------------------------")
    Click image for larger version

Name:	unknown.png
Views:	372
Size:	315.4 KB
ID:	1801

    #2
    Try this

    Code:
    local x, y, z = GetVehicleVelocity(vehicle)
    local len = math.sqrt(x * x + y * y + z * z)
    local kmh = len * 36.0

    Comment


      #3
      Thanks Talos , it works but not in reverse
      Code:
      function GetSpeedVehicle(vehicle)
          local x, y, z = GetVehicleVelocity(vehicle)
          local len = math.sqrt(x * x + y * y + z * z)
          local kmh = string.sub(math.ceil(len * 36.0), 1, 2)
          if tonumber(kmh) > 99 then
              kmh = string.sub(kmh, 1, 3)
          end
          return kmh
      end

      Comment


        #4
        Oh, replace
        Code:
        local len = math.sqrt(x * x + y * y + z * z)
        with
        Code:
        local len = math.sqrt(math.abs(x * x + y * y + z * z))

        Comment


          #5
          Doesn't make much difference, (the goal would be to get the - )
          Last edited by Eikop; 01-09-2020, 07:44 PM.

          Comment

          Working...
          X