Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.65 KB | None | 0 0
  1. local screenSize = {guiGetScreenSize()}
  2.  
  3. local mainScale = 1 / 0.3 * screenSize[1] / screenSize[2]
  4. local maxScaleCurve = {{0, 0}, {3, 3}, {13, 5}}
  5.  
  6. local rendering = true
  7. local font = dxCreateFont( "files/Roboto.ttf", 14, true )
  8.  
  9.  
  10. --[[addEventHandler("onClientRender", root, function()
  11.     if rendering then
  12.         for _, car in ipairs(getElementsByType("vehicle")) do
  13.             if types[getVehicleType(car)] and (getElementData(car, "veh:plate") or getVehiclePlateText(car)) then
  14.                 if isElementOnScreen(car) and car ~= getPedOccupiedVehicle(localPlayer) then
  15.                     local plateText = getVehiclePlateText(car) or getElementData(car, "veh:plate")
  16.                     local localPosition = {getElementPosition(localPlayer)}
  17.                     local carPosition = {getElementPosition(car)}
  18.                     local worldPosition = {getScreenFromWorldPosition(carPosition[1], carPosition[2], carPosition[3] + 1.3)}
  19.                     local distance = getDistanceBetweenPoints3D(localPosition[1], localPosition[2], localPosition[3], carPosition[1], carPosition[2], carPosition[3])
  20.                     local scale = 2 / (mainScale * (distance / 100))
  21.                     local scale = curving(scale) / 3
  22.                    
  23.                     if distance <= 15 then
  24.                         local plateTextX = dxGetTextWidth(plateText, 1.4, "default-bold", true)
  25.                        
  26.                         if worldPosition[1] and worldPosition[2] and scale then
  27.                             dxDrawRectangleBox(worldPosition[1]-plateTextX/2-5, worldPosition[2]-10*scale, plateTextX+10, 20)
  28.                             dxDrawText(plateText, worldPosition[1]-plateTextX/2, worldPosition[2]-10*scale, plateTextX+10, 20, tocolor(255,255,255), 1.4, "default-bold")
  29.                         end
  30.                     end
  31.                 end
  32.             end
  33.         end
  34.     end
  35. end)]]--
  36.  
  37.  
  38. local vehicleTable = {}
  39. local vehiclePlate = ''
  40. --local customFont = dxCreateFont('files/icons.ttf',30, false)
  41. local renderVehDistance = 15
  42. local showVehicle = true
  43. local distance = 0
  44.  
  45. function isBike(veh)
  46.     if getElementType(veh) == "vehicle" then
  47.         if getVehicleType(veh) == "Helicopter" or getVehicleType(veh) == "BMX" or getVehicleType(veh) == "Boat" or getVehicleType(veh) == "Quad" then
  48.             return true
  49.         else
  50.             return false
  51.         end
  52.     else
  53.         return false
  54.     end
  55. end
  56.  
  57. function refresVehicleTable(element)
  58.     thisTimer1 = setTimer(function()
  59.     if getElementType(element)=="vehicle" and not isBike(element) then
  60.         vehicleTable[element] = {getVehiclePlateText(element)}
  61.     end
  62.     end,1000,0)
  63. end
  64.  
  65. addEventHandler("onClientElementStreamIn", root, function ()
  66.     local type = getElementType (source)
  67.     if showVehicle then
  68.         if type == "vehicle" then
  69.             refresVehicleTable(source)
  70.             setPlayerNametagShowing (source,false)
  71.         end
  72.     end
  73. end)
  74.  
  75. addEventHandler( "onClientElementStreamOut", root, function ()
  76.     local type = getElementType (source)
  77.     if showVehicle then
  78.         if type == "vehicle"then
  79.             vehicleTable[source] = nil
  80.             setPlayerNametagShowing (source,false)
  81.         end
  82.     end
  83. end)
  84.  
  85. function streamAllVehicles()
  86.     for k,v in ipairs(getElementsByType("vehicle")) do
  87.         if isElementStreamedIn(v) then
  88.             refresVehicleTable(v)
  89.         end
  90.     end
  91.  
  92. end
  93.  
  94. streamAllVehicles()
  95.  
  96. addEventHandler("onClientRender", root, function()
  97.     if showVehicle then
  98.         local px,py,pz = getElementPosition(localPlayer)
  99.         for k,value in pairs(vehicleTable) do
  100.             if isElement(k) then
  101.                 x,y,z = getElementPosition(k)
  102.                 distance = getDistanceBetweenPoints3D(px,py,pz,x,y,z)
  103.                     local plateText = getVehiclePlateText(k) or getElementData(k, "veh:plate")
  104.                     local localPosition = {getElementPosition(localPlayer)}
  105.                     local carPosition = {getElementPosition(k)}
  106.                     local worldPosition = {getScreenFromWorldPosition(carPosition[1], carPosition[2], carPosition[3] + 1.3)}
  107.                     local distance = getDistanceBetweenPoints3D(localPosition[1], localPosition[2], localPosition[3], carPosition[1], carPosition[2], carPosition[3])
  108.                     local scale = 2 / (mainScale * (distance / 100))
  109.                     local scale = curving(scale) / 3
  110.                 if (distance <= renderVehDistance and not(getElementAlpha(k)==0) and isLineOfSightClear(px, py, pz, x, y, z, true, false, false, true, false, false, false) and getPedOccupiedVehicle(localPlayer) ~= k) then
  111.                     local progress = distance/renderVehDistance
  112.                     local size = interpolateBetween (0.8,0,0,0.2,0,0,progress,"OutQuad") * 0.9
  113.                    
  114.                     if size >= 3.5 then
  115.                         size = 3.5
  116.                     end
  117.                    
  118.                     if(tostring(getElementType(k))=="vehicle") and vehicleTable[k] then
  119.                         vehiclePlate = vehicleTable[k][1]
  120.                        
  121.                     else
  122.                         vehiclePlate = "#ffffffIsmeretlen"
  123.                     end
  124.                    
  125.                     local vehpanel = { getScreenFromWorldPosition ( x, y, z+2 ) }
  126.                     if vehpanel[1] and vehpanel[2] then
  127.                         --dxDrawText (vehiclePlate:gsub("#%x%x%x%x%x%x", "") , vehpanel[1]+1, vehpanel[2]+1, vehpanel[1]+1, vehpanel[2]+1, tocolor(0,0,0,255), 1.4, "default-bold", "center","center",false,false,false,true )
  128.                         --dxDrawText (vehiclePlate , vehpanel[1], vehpanel[2], vehpanel[1], vehpanel[2], tocolor(255,255,255,255), 1.4, "default-bold", "center","center",false,false,false,true )
  129.                         local plateTextX = dxGetTextWidth(plateText, 1, "font", true)
  130.                         --dxDrawRectangleBox(worldPosition[1]-plateTextX/2-50, worldPosition[2]-10*scale,150, 25)
  131.                         --dxDrawText(vehiclePlate:gsub("#%x%x%x%x%x%x", ""), worldPosition[1]-plateTextX/2-10, worldPosition[2]-10*scale,150, 25, tocolor(0,0,0),1,font)
  132.                         dxDrawRectangleBox(worldPosition[1]-75, worldPosition[2]-10*scale,150, 25)
  133.                         dxDrawText(vehiclePlate:gsub("#%x%x%x%x%x%x", ""), worldPosition[1]-75, worldPosition[2]-10*scale,worldPosition[1]-75+150, worldPosition[2]-10*scale+25, tocolor(0,0,0),1,font,"center","center")
  134.                     end
  135.                 end
  136.             end
  137.         end
  138.     end
  139. end, true, "low-5")
  140.  
  141. --[[function disabledVehicel()
  142.     showVehicle = not showVehicle
  143. end
  144. addCommandHandler("offplate", disabledVehicel)]]--
  145.  
  146. bindKey("f10", "down", function()
  147.     rendering = not rendering
  148.     showVehicle = not showVehicle
  149. end)
  150.  
  151.  
  152. function dxDrawRectangleBox(left, top, width, height)
  153.     dxDrawRectangle(left, top, width, height, tocolor(255,255,255,240))
  154.     dxDrawRectangle(left-1, top, 1, height, tocolor(0,0,0,220))
  155.     dxDrawRectangle(left+width, top, 1, height, tocolor(0,0,0,220))
  156.     dxDrawRectangle(left, top-1, width, 1, tocolor(0,0,0,220))
  157.     dxDrawRectangle(left, top+height, width, 1, tocolor(0,0,0,220))
  158. end
  159.  
  160. function math.lerp(from, to, alpha)
  161.     return from + (to - from) * alpha
  162. end
  163.  
  164. function curving(scaleCalc)
  165.  
  166.     if scaleCalc < maxScaleCurve[1][1] then
  167.         return maxScaleCurve[1][2]
  168.     end
  169.  
  170.     for idx = 2,#maxScaleCurve do
  171.         if scaleCalc < maxScaleCurve[idx][1] then
  172.             local x1 = maxScaleCurve[idx - 1][1]
  173.             local y1 = maxScaleCurve[idx - 1][2]
  174.             local x2 = maxScaleCurve[idx][1]
  175.             local y2 = maxScaleCurve[idx][2]
  176.  
  177.             local alpha = (scaleCalc - x1)/(x2 - x1);
  178.  
  179.             return math.lerp(y1,y2,alpha)
  180.         end
  181.     end
  182.  
  183.     return maxScaleCurve[#maxScaleCurve][2]
  184. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement