Advertisement
Guest User

Untitled

a guest
Dec 14th, 2019
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.08 KB | None | 0 0
  1. function OpenCarMenue(type, station, part, partNum)
  2. local playerCoords = GetEntityCoords(PlayerPedId())
  3. PlayerData = ESX.GetPlayerData()
  4. local elements = {
  5. {label = _U('garage_storeditem'), action = 'garage'},
  6. {label = _U('garage_storeitem'), action = 'store_garage'}
  7.  
  8. }
  9.  
  10. ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'vehicle', {
  11. title = _U('garage_title'),
  12. align = 'top-left',
  13. elements = elements
  14. }, function(data, menu)
  15.  
  16. if data.current.action == 'garage' then
  17. local garage = {}
  18.  
  19. ESX.TriggerServerCallback('esx_vehicleshop:retrieveJobVehicles', function(jobVehicles)
  20. if #jobVehicles > 0 then
  21. for k,v in ipairs(jobVehicles) do
  22. local props = json.decode(v.vehicle)
  23. local fuellvl = json.decode(v.fuellevel)
  24. local dmglvl = json.decode(v.damage)
  25. local vehicleName = GetLabelText(GetDisplayNameFromVehicleModel(props.model))
  26. local label = ('%s - <span style="color:darkgoldenrod;">%s</span>: '):format(vehicleName, props.plate)
  27.  
  28. if v.state then
  29. label = label .. ('<span style="color:green;">%s</span>'):format(_U('garage_stored'))
  30. else
  31. label = label .. ('<span style="color:darkred;">%s</span>'):format(_U('garage_notstored'))
  32. end
  33.  
  34. table.insert(garage, {
  35. label = label,
  36. stored = v.state,
  37. model = props.model,
  38. vehicleProps = props,
  39. damage = dmglvl,
  40. fuelg = fuellvl
  41. })
  42.  
  43. print(fuellvl)
  44. end
  45.  
  46. ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'vehicle_garage', {
  47. title = _U('garage_title'),
  48. align = 'top-left',
  49. elements = garage
  50. }, function(data2, menu2)
  51. if data2.current.stored then
  52. local spawnP = Config.VehicleSpawnPoint.Pos
  53. local headingP = Config.VehicleSpawnPoint.heading
  54.  
  55.  
  56. menu2.close()
  57.  
  58. TriggerEvent('fuel:setGarageFuel', data2.current.fuelg)
  59.  
  60. print('SPAWN AHEAD')
  61. print(headingP)
  62. print(spawnP)
  63. ESX.Game.SpawnVehicle(data2.current.model, spawnP, headingP, function(vehicle)
  64. ESX.Game.SetVehicleProperties(vehicle, data2.current.vehicleProps)
  65. SetVehicleEngineHealth(vehicle, data2.current.damage + .0)
  66. TriggerServerEvent('esx_vehicleshop:setJobVehicleState', data2.current.vehicleProps.plate, false)
  67. ESX.ShowNotification('Auto Ausgeparkt')
  68. end)
  69.  
  70.  
  71. else
  72. ESX.ShowNotification(_U('garage_notavailable'))
  73. end
  74. end, function(data2, menu2)
  75. menu2.close()
  76. end)
  77.  
  78. else
  79. ESX.ShowNotification(_U('garage_empty'))
  80. end
  81. end, 'car')
  82.  
  83. elseif data.current.action == 'store_garage' then
  84. StoreNearbyVehicle(playerCoords)
  85. end
  86.  
  87. end, function(data, menu)
  88. menu.close()
  89. end)
  90.  
  91. end
  92.  
  93. function StoreNearbyVehicle(playerCoords)
  94. local vehicles, vehiclePlates = ESX.Game.GetVehiclesInArea(playerCoords, 30.0), {}
  95. local fuellev = nil
  96. local damagelev = nil
  97.  
  98. local lastdrivenveh = GetLastDrivenVehicle()
  99.  
  100. local lastveh = nil
  101. local vehplate = GetVehicleNumberPlateText(lastdrivenveh)
  102.  
  103. if #vehicles > 0 then
  104. for k,v in ipairs(vehicles) do
  105.  
  106. -- Make sure the vehicle we're saving is empty, or else it wont be deleted
  107. if GetVehicleNumberOfPassengers(v) == 0 and IsVehicleSeatFree(v, -1) then
  108.  
  109. table.insert(vehiclePlates, {
  110. vehicle = v,
  111. plate = ESX.Math.Trim(GetVehicleNumberPlateText(v))
  112. })
  113. end
  114.  
  115. if GetVehicleNumberPlateText(v) == vehplate then
  116. lastveh = v
  117. else
  118. lastveh = nil
  119. end
  120. end
  121. else
  122. ESX.ShowNotification(_U('garage_store_nearby'))
  123. return
  124. end
  125.  
  126.  
  127. if lastveh == nil then
  128.  
  129. ESX.ShowNotification('~r~Du musst zuerst mit dem Fahrzeug Gefahren sein, welches du einparken willst.')
  130. return
  131.  
  132. else
  133. fuellev = GetVehicleFuelLevel(lastveh)
  134. damagelev = GetVehicleEngineHealth(lastveh)
  135. print('CAR FUEL - ' .. fuellev)
  136. print('CAR dmg - ' .. damagelev)
  137.  
  138. end
  139.  
  140. ESX.TriggerServerCallback('esx_policejob:storeNearbyVehicle', function(storeSuccess, foundNum)
  141. if storeSuccess then
  142. local vehicleId = vehiclePlates[foundNum]
  143. local attempts = 0
  144.  
  145.  
  146.  
  147. ESX.Game.DeleteVehicle(vehicleId.vehicle)
  148. IsBusy = true
  149.  
  150. Citizen.CreateThread(function()
  151. while IsBusy do
  152. Citizen.Wait(0)
  153. drawLoadingText(_U('garage_storing'), 255, 255, 255, 255)
  154. end
  155. end)
  156.  
  157. -- Workaround for vehicle not deleting when other players are near it.
  158. while DoesEntityExist(vehicleId.vehicle) do
  159. Citizen.Wait(500)
  160. attempts = attempts + 1
  161.  
  162. -- Give up
  163. if attempts > 30 then
  164. break
  165. end
  166.  
  167. vehicles = ESX.Game.GetVehiclesInArea(playerCoords, 30.0)
  168. if #vehicles > 0 then
  169. for k,v in ipairs(vehicles) do
  170. if ESX.Math.Trim(GetVehicleNumberPlateText(v)) == vehicleId.plate then
  171. ESX.Game.DeleteVehicle(v)
  172. break
  173. end
  174. end
  175. end
  176. end
  177.  
  178. IsBusy = false
  179. ESX.ShowNotification(_U('garage_has_stored'))
  180. else
  181. ESX.ShowNotification(_U('garage_has_notstored'))
  182. end
  183. end, vehiclePlates, damagelev, fuellev)
  184. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement