Advertisement
Guest User

Untitled

a guest
May 11th, 2019
1,522
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.30 KB | None | 0 0
  1. -- SCREEN POSITION PARAMETERS
  2. local screenPosX = 0.165 -- X coordinate (top left corner of HUD)
  3. local screenPosY = 0.882 -- Y coordinate (top left corner of HUD)
  4.  
  5. -- SPEEDOMETER PARAMETERS
  6. local speedLimit = 100.0 -- Speed limit for changing speed color
  7. local speedColorText = {255, 255, 255} -- Color used to display speed label text
  8. local speedColorUnder = {160, 255, 160} -- Color used to display speed when under speedLimit
  9. local speedColorOver = {255, 96, 96} -- Color used to display speed when over speedLimit
  10.  
  11. -- FUEL PARAMETERS
  12. local fuelWarnLimit = 25.0 -- Fuel limit for triggering warning color
  13. local fuelColorText = {255, 255, 255} -- Color used to display fuel text
  14. local fuelColorOver = {160, 255, 160} -- Color used to display fuel when good
  15. local fuelColorUnder = {255, 96, 96} -- Color used to display fuel warning
  16.  
  17. -- SEATBELT PARAMETERS
  18. local seatbeltInput = 311 -- Toggle seatbelt on/off with K
  19. local seatbeltEjectSpeed = 45 -- Speed threshold to eject player (MPH)
  20. local seatbeltEjectAccel = 100 -- Acceleration threshold to eject player (G's)
  21. local seatbeltColorOn = {160, 255, 160} -- Color used when seatbelt is on
  22. local seatbeltColorOff = {255, 96, 96} -- Color used when seatbelt is off
  23.  
  24. -- CRUISE CONTROL PARAMETERS
  25. local cruiseInput = 137 -- Toggle cruise on/off with CAPSLOCK or A button (controller)
  26. local cruiseColorOn = {160, 255, 160} -- Color used when seatbelt is on
  27. local cruiseColorOff = {255, 96, 96} -- Color used when seatbelt is off
  28.  
  29. -- LOCATION PARAMETERS
  30. local locationColorText = {255, 255, 255} -- Color used to display location string
  31.  
  32. -- Lookup tables for direction and zone
  33. local directions = { [0] = 'N', [1] = 'W', [2] = 'S', [3] = 'E', [4] = 'N' }
  34. local zones = { ['AIRP'] = "Los Santos International Airport", ['ALAMO'] = "Alamo Sea", ['ALTA'] = "Alta", ['ARMYB'] = "Fort Zancudo", ['BANHAMC'] = "Banham Canyon Dr", ['BANNING'] = "Banning", ['BEACH'] = "Vespucci Beach", ['BHAMCA'] = "Banham Canyon", ['BRADP'] = "Braddock Pass", ['BRADT'] = "Braddock Tunnel", ['BURTON'] = "Burton", ['CALAFB'] = "Calafia Bridge", ['CANNY'] = "Raton Canyon", ['CCREAK'] = "Cassidy Creek", ['CHAMH'] = "Chamberlain Hills", ['CHIL'] = "Vinewood Hills", ['CHU'] = "Chumash", ['CMSW'] = "Chiliad Mountain State Wilderness", ['CYPRE'] = "Cypress Flats", ['DAVIS'] = "Davis", ['DELBE'] = "Del Perro Beach", ['DELPE'] = "Del Perro", ['DELSOL'] = "La Puerta", ['DESRT'] = "Grand Senora Desert", ['DOWNT'] = "Downtown", ['DTVINE'] = "Downtown Vinewood", ['EAST_V'] = "East Vinewood", ['EBURO'] = "El Burro Heights", ['ELGORL'] = "El Gordo Lighthouse", ['ELYSIAN'] = "Elysian Island", ['GALFISH'] = "Galilee", ['GOLF'] = "GWC and Golfing Society", ['GRAPES'] = "Grapeseed", ['GREATC'] = "Great Chaparral", ['HARMO'] = "Harmony", ['HAWICK'] = "Hawick", ['HORS'] = "Vinewood Racetrack", ['HUMLAB'] = "Humane Labs and Research", ['JAIL'] = "Bolingbroke Penitentiary", ['KOREAT'] = "Little Seoul", ['LACT'] = "Land Act Reservoir", ['LAGO'] = "Lago Zancudo", ['LDAM'] = "Land Act Dam", ['LEGSQU'] = "Legion Square", ['LMESA'] = "La Mesa", ['LOSPUER'] = "La Puerta", ['MIRR'] = "Mirror Park", ['MORN'] = "Morningwood", ['MOVIE'] = "Richards Majestic", ['MTCHIL'] = "Mount Chiliad", ['MTGORDO'] = "Mount Gordo", ['MTJOSE'] = "Mount Josiah", ['MURRI'] = "Murrieta Heights", ['NCHU'] = "North Chumash", ['NOOSE'] = "N.O.O.S.E", ['OCEANA'] = "Pacific Ocean", ['PALCOV'] = "Paleto Cove", ['PALETO'] = "Paleto Bay", ['PALFOR'] = "Paleto Forest", ['PALHIGH'] = "Palomino Highlands", ['PALMPOW'] = "Palmer-Taylor Power Station", ['PBLUFF'] = "Pacific Bluffs", ['PBOX'] = "Pillbox Hill", ['PROCOB'] = "Procopio Beach", ['RANCHO'] = "Rancho", ['RGLEN'] = "Richman Glen", ['RICHM'] = "Richman", ['ROCKF'] = "Rockford Hills", ['RTRAK'] = "Redwood Lights Track", ['SANAND'] = "San Andreas", ['SANCHIA'] = "San Chianski Mountain Range", ['SANDY'] = "Sandy Shores", ['SKID'] = "Mission Row", ['SLAB'] = "Stab City", ['STAD'] = "Maze Bank Arena", ['STRAW'] = "Strawberry", ['TATAMO'] = "Tataviam Mountains", ['TERMINA'] = "Terminal", ['TEXTI'] = "Textile City", ['TONGVAH'] = "Tongva Hills", ['TONGVAV'] = "Tongva Valley", ['VCANA'] = "Vespucci Canals", ['VESP'] = "Vespucci", ['VINE'] = "Vinewood", ['WINDF'] = "Ron Alternates Wind Farm", ['WVINE'] = "West Vinewood", ['ZANCUDO'] = "Zancudo River", ['ZP_ORT'] = "Port of South Los Santos", ['ZQ_UAR'] = "Davis Quartz" }
  35.  
  36. -- STATE VARIABLES
  37. local currentFuel = 0.0
  38. local cruiseIsOn = false
  39. local seatbeltIsOn = false
  40.  
  41. -- Main thread
  42. Citizen.CreateThread(function()
  43. -- Initialize local variable
  44. local currSpeed = 0.0
  45. local cruiseSpeed = 999.0
  46. local prevVelocity = {x = 0.0, y = 0.0, z = 0.0}
  47.  
  48. while true do
  49. -- Loop forever and update HUD every frame
  50. Citizen.Wait(0)
  51.  
  52. -- Get player PED, position and vehicle and save to locals
  53. local player = GetPlayerPed(-1)
  54. local position = GetEntityCoords(player)
  55. local vehicle = GetVehiclePedIsIn(player, false)
  56.  
  57. -- Display HUD only when in vehicle
  58. if (IsPedInAnyVehicle(player, false)) then
  59. -- Save previous speed and get current speed
  60. local prevSpeed = currSpeed
  61. currSpeed = GetEntitySpeed(vehicle)
  62.  
  63. -- Check if seatbelt button pressed, toggle state and handle seatbelt logic
  64. if IsControlJustReleased(0, seatbeltInput) then seatbeltIsOn = not seatbeltIsOn end
  65. if not seatbeltIsOn then
  66. -- Eject PED when moving forward, vehicle was going over 45 MPH and acceleration over 100 G's
  67. local vehIsMovingFwd = GetEntitySpeedVector(vehicle, true).y > 1.0
  68. local vehAcc = (prevSpeed - currSpeed) / GetFrameTime()
  69. if (vehIsMovingFwd and (prevSpeed > (seatbeltEjectSpeed/2.237)) and (vehAcc > (seatbeltEjectAccel*9.81))) then
  70. SetEntityCoords(player, position.x, position.y, position.z - 0.47, true, true, true)
  71. SetEntityVelocity(player, prevVelocity.x, prevVelocity.y, prevVelocity.z)
  72. Citizen.Wait(1)
  73. SetPedToRagdoll(player, 1000, 1000, 0, 0, 0, 0)
  74. else
  75. -- Update previous velocity for ejecting player
  76. prevVelocity = GetEntityVelocity(vehicle)
  77. end
  78. else
  79. -- Disable vehicle exit when seatbelt is on
  80. DisableControlAction(0, 75)
  81. end
  82.  
  83. -- When player in driver seat, handle cruise control
  84. if (GetPedInVehicleSeat(vehicle, -1) == player) then
  85. -- Check if cruise control button pressed, toggle state and set maximum speed appropriately
  86. if IsControlJustReleased(0, cruiseInput) then
  87. cruiseIsOn = not cruiseIsOn
  88. cruiseSpeed = currSpeed
  89. end
  90. local maxSpeed = cruiseIsOn and cruiseSpeed or GetVehicleHandlingFloat(vehicle,"CHandlingData","fInitialDriveMaxFlatVel")
  91. SetEntityMaxSpeed(vehicle, maxSpeed)
  92. else
  93. -- Reset cruise control
  94. cruiseIsOn = false
  95. end
  96.  
  97. -- Get vehicle speed in KMH and draw speedometer
  98. local speed = GetEntitySpeed(GetVehiclePedIsIn(player, false))*3.6
  99. speedColor = (speed >= speedLimit) and speedColorOver or speedColorUnder
  100. drawTxt(("%.3d"):format(math.ceil(speed)), 2, speedColor, 0.9, screenPosX, screenPosY)
  101. drawTxt("KMH", 2, speedColorText, 0.4, screenPosX + 0.035, screenPosY + 0.024)
  102.  
  103. -- Draw fuel gauge; always displays 100 but can be modified by setting currentFuel with an API call
  104. currentFuel = GetVehicleFuelLevel(vehicle)
  105. fuelColor = (currentFuel >= fuelWarnLimit) and fuelColorOver or fuelColorUnder
  106. drawTxt(("%.3d"):format(math.ceil(currentFuel)), 2, fuelColor, 0.8, screenPosX + 0.050, screenPosY + 0.000)
  107. drawTxt("FUEL", 2, fuelColorText, 0.4, screenPosX + 0.080, screenPosY + 0.020)
  108.  
  109. -- Get time and display
  110. local hour = GetClockHours()
  111. local minute = GetClockMinutes()
  112. local timeText = ("%.2d"):format((hour == 0) and 12 or hour) .. ":" .. ("%.2d"):format( minute) .. ((hour < 12) and " AM" or " PM")
  113. drawTxt(timeText, 4, {255,255,255}, 0.4, screenPosX, screenPosY + 0.048)
  114.  
  115. -- Draw cruise control status
  116. cruiseColor = cruiseIsOn and cruiseColorOn or cruiseColorOff
  117. drawTxt("CRUISE", 2, cruiseColor, 0.4, screenPosX + 0.040, screenPosY + 0.048)
  118.  
  119. -- Draw seatbelt status
  120. seatbeltColor = seatbeltIsOn and seatbeltColorOn or seatbeltColorOff
  121. drawTxt("SEATBELT", 2, seatbeltColor, 0.4, screenPosX + 0.080, screenPosY + 0.048)
  122.  
  123. -- Get heading and zone from lookup tables and street name from hash
  124. local heading = directions[math.floor((GetEntityHeading(player) + 45.0) / 90.0)]
  125. local zoneNameFull = zones[GetNameOfZone(position.x, position.y, position.z)]
  126. local streetName = GetStreetNameFromHashKey(GetStreetNameAtCoord(position.x, position.y, position.z))
  127.  
  128. -- Display heading, street name and zone when possible
  129. local locationText = heading
  130. locationText = (streetName == "" or streetName == nil) and (locationText) or (locationText .. " | " .. streetName)
  131. locationText = (zoneNameFull == "" or zoneNameFull == nil) and (locationText) or (locationText .. " | " .. zoneNameFull)
  132. drawTxt(locationText, 4, locationColorText, 0.5, screenPosX, screenPosY + 0.074)
  133. else
  134. -- Reset states when not in car
  135. cruiseIsOn = false
  136. seatbeltIsOn = false
  137. end
  138. end
  139. end)
  140.  
  141. -- Helper function to draw text to screen
  142. function drawTxt(content, font, colour, scale, x, y)
  143. SetTextFont(font)
  144. SetTextScale(scale, scale)
  145. SetTextColour(colour[1],colour[2],colour[3], 255)
  146. SetTextEntry("STRING")
  147. SetTextDropShadow(0, 0, 0, 0,255)
  148. SetTextDropShadow()
  149. SetTextEdge(4, 0, 0, 0, 255)
  150. SetTextOutline()
  151. AddTextComponentString(content)
  152. DrawText(x, y)
  153. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement