Guest User

Untitled

a guest
Nov 2nd, 2016
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.70 KB | None | 0 0
  1. local enteredMarkerData = {}
  2.  
  3. addEvent("tuning->ResetMarker", true)
  4. addEvent("tuning->OpticalUpgrade", true)
  5. addEvent("tuning->PerformanceUpgrade", true)
  6. addEvent("tuning->HandlingUpdate", true)
  7. addEvent("tuning->WheelWidth", true)
  8. addEvent("tuning->OffroadAbility", true)
  9. addEvent("tuning->Color", true)
  10. addEvent("tuning->LicensePlate", true)
  11.  
  12. addEventHandler("onResourceStart", resourceRoot, function()
  13.     for i = 1, #availableTuningMarkers do
  14.         local currentTuning = availableTuningMarkers[i]
  15.        
  16.         if currentTuning then
  17.             local tuningMarker = createMarker(currentTuning[1], currentTuning[2], currentTuning[3] - 1, "cylinder", 2.5, 0, 0, 0, 100)
  18.            
  19.             setElementData(tuningMarker, "tuningMarkerSettings", {true, currentTuning[4]})
  20.            
  21.             addEventHandler("onMarkerHit", tuningMarker, hitTuningMarker)
  22.         end
  23.     end
  24. end)
  25.  
  26. addEventHandler("onPlayerQuit", root, function()
  27.     resetTuningMarker(source)
  28. end)
  29.  
  30. addEventHandler("tuning->ResetMarker", root, function(player)
  31.     resetTuningMarker(player)
  32. end)
  33.  
  34. addEventHandler("tuning->OpticalUpgrade", root, function(vehicle, type, upgrade)
  35.     if vehicle then
  36.         if upgrade then
  37.             if type == "add" then
  38.                 addVehicleUpgrade(vehicle, upgrade)
  39.             elseif type == "remove" then
  40.                 removeVehicleUpgrade(vehicle, upgrade)
  41.             end
  42.         end
  43.     end
  44. end)
  45.  
  46. addEventHandler("tuning->PerformanceUpgrade", root, function(vehicle, data)
  47.     if vehicle then
  48.         if data then
  49.             local vehicleModel = getElementModel(vehicle)
  50.            
  51.             if not data[1][2] then -- Default upgrade
  52.                 for _, property in ipairs(data) do
  53.                     setVehicleHandling(vehicle, property[1], nil, false)
  54.                 end
  55.             else
  56.                 for _, property in ipairs(data) do
  57.                     local defaultHandling = getOriginalHandling(vehicleModel)[property[1]]
  58.                    
  59.                     setVehicleHandling(vehicle, property[1], defaultHandling, false)
  60.                     setVehicleHandling(vehicle, property[1], defaultHandling + property[2], false)
  61.                 end
  62.             end
  63.         end
  64.     end
  65. end)
  66.  
  67. addEventHandler("tuning->HandlingUpdate", root, function(vehicle, property, value)
  68.     if vehicle then
  69.         if property then
  70.             if value then
  71.                 setVehicleHandling(vehicle, property, value, false)
  72.             else
  73.                 setVehicleHandling(vehicle, property, getOriginalHandling(getElementModel(vehicle))[property], false)
  74.             end
  75.         end
  76.     end
  77. end)
  78.  
  79. addEventHandler("tuning->WheelWidth", root, function(vehicle, side, type)
  80.     if vehicle then
  81.         if type then
  82.             if type == "verynarrow" then type = 1
  83.                 elseif type == "narrow" then type = 2
  84.                 elseif type == "wide" then type = 4
  85.                 elseif type == "verywide" then type = 8
  86.                 elseif type == "default" then type = 0
  87.             end
  88.        
  89.             if side then
  90.                 if side == "front" then
  91.                     setVehicleHandlingFlags(vehicle, 3, type)
  92.                 elseif side == "rear" then
  93.                     setVehicleHandlingFlags(vehicle, 4, type)
  94.                 else
  95.                     setVehicleHandlingFlags(vehicle, {3, 4}, type)
  96.                 end
  97.             else
  98.                 setVehicleHandlingFlags(vehicle, {3, 4}, type)
  99.             end
  100.         else
  101.             setVehicleHandlingFlags(vehicle, {3, 4}, 0)
  102.         end
  103.     end
  104. end)
  105.  
  106. addEventHandler("tuning->OffroadAbility", root, function(vehicle, type)
  107.     if vehicle then
  108.         if type then
  109.             if type == "dirt" then type = 1
  110.                 elseif type == "sand" then type = 2
  111.                 elseif type == "default" then type = 0
  112.             end
  113.            
  114.             setVehicleHandlingFlags(vehicle, 6, type)
  115.         else
  116.             setVehicleHandlingFlags(vehicle, 6, 0)
  117.         end
  118.     end
  119. end)
  120.  
  121. addEventHandler("tuning->Color", root, function(vehicle, color, headlightColor)
  122.     if vehicle then
  123.         setVehicleColor(vehicle, color[1], color[2], color[3], color[4], color[5], color[6], color[7], color[8], color[9])
  124.         setVehicleHeadLightColor(vehicle, headlightColor[1], headlightColor[2], headlightColor[3])
  125.     end
  126. end)
  127.  
  128. addEventHandler("tuning->LicensePlate", root, function(vehicle, text)
  129.     if vehicle and text then
  130.         setVehiclePlateText(vehicle, text)
  131.     end
  132. end)
  133.  
  134. function setVehicleHandlingFlags(vehicle, byte, value)
  135.     if vehicle then
  136.         local handlingFlags = string.format("%X", getVehicleHandling(vehicle)["handlingFlags"])
  137.         local reversedFlags = string.reverse(handlingFlags) .. string.rep("0", 8 - string.len(handlingFlags))
  138.         local currentByte, flags = 1, ""
  139.        
  140.         for values in string.gmatch(reversedFlags, ".") do
  141.             if type(byte) == "table" then
  142.                 for _, v in ipairs(byte) do
  143.                     if currentByte == v then
  144.                         values = string.format("%X", tonumber(value))
  145.                     end
  146.                 end
  147.             else
  148.                 if currentByte == byte then
  149.                     values = string.format("%X", tonumber(value))
  150.                 end
  151.             end
  152.            
  153.             flags = flags .. values
  154.             currentByte = currentByte + 1
  155.         end
  156.        
  157.         setVehicleHandling(vehicle, "handlingFlags", tonumber("0x" .. string.reverse(flags)), false)
  158.     end
  159. end
  160.  
  161. function hitTuningMarker(element)
  162.     if isElement(element) then
  163.         if getElementType(element) == "vehicle" then
  164.             if getVehicleController(element) then
  165.                 local vehicleController = getVehicleController(element)
  166.                 local markerX, markerY, markerZ = getElementPosition(source)
  167.                 local markerRotation = getElementData(source, "tuningMarkerSettings")[2] or 0
  168.                
  169.                 enteredMarkerData[vehicleController] = {source, element}
  170.                
  171.                 setElementFrozen(element, true)
  172.                 setVehicleDamageProof(element, true)
  173.                 setElementPosition(element, markerX, markerY, markerZ + 1)
  174.                 setElementRotation(element, 0, 0, markerRotation)
  175.                
  176.                 setElementDimension(source, 65535)
  177.                
  178.                 triggerClientEvent(vehicleController, "tuning->ShowMenu", vehicleController, element)
  179.             end
  180.         end
  181.     end
  182. end
  183.  
  184. function resetTuningMarker(player)
  185.     if player then
  186.         if enteredMarkerData[player] then
  187.             setElementDimension(enteredMarkerData[player][1], 0)
  188.            
  189.             setElementFrozen(enteredMarkerData[player][2], false)
  190.             setVehicleDamageProof(enteredMarkerData[player][2], false)
  191.        
  192.             enteredMarkerData[player] = nil
  193.         end
  194.     end
  195. end
Add Comment
Please, Sign In to add comment