FL1K3R

Simlpe speedometer for FiveM

Mar 18th, 2017
927
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.34 KB | None | 0 0
  1. Citizen.CreateThread(function()
  2.     while true do
  3.         Citizen.Wait(0)
  4.         if IsPedSittingInAnyVehicle(GetPlayerPed(-1)) then
  5.             local vehicle = GetVehiclePedIsIn(GetPlayerPed(-1), false)
  6.             if DoesEntityExist(vehicle) and not IsEntityDead(vehicle) then
  7.                 if not HasStreamedTextureDictLoaded("speedo") then
  8.                     RequestStreamedTextureDict("speedo", true) -- unload it
  9.                     while not HasStreamedTextureDictLoaded("speedo") do
  10.                         Wait(0)
  11.                     end
  12.                 else
  13.                     -- everything is ok
  14.                     local degree = 0
  15.                     local step = 2.05833
  16.                     if GetEntitySpeed(vehicle) > 0 then degree=(GetEntitySpeed(vehicle)*2.236936)*step end
  17.                     DrawSprite("speedo", "speedom_001", 0.898,0.752,0.16,0.245, 0.0, 255, 255, 255, 255)
  18.                     if degree > 247 then degree=247 end
  19.                     DrawSprite("speedo", "needle_001", 0.898,0.755,0.116,0.15,43.00001+degree, 255, 255, 255, 200)
  20.                 end
  21.             end
  22.         end
  23.     end
  24. end)
  25.  
  26.  
  27. -- explanations.
  28. --[[
  29. what does 'local step' means?
  30. I detect the minimum needle angle (is 43.0 and maximum - is 290.0).
  31. Difference between min and max angles is 247.0. Then i divide this difference by zero, no wait, divide this
  32. by 120 (how much gradation units we have on our speedometer) and i got local step. It is 2.05833 as you can see.
  33. Then i found on nativeDB how to detect entity speed in MPH.
  34. Thanks for reading this barbarian-english comments.
  35. ]]
Advertisement
Add Comment
Please, Sign In to add comment