Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function OpenCarMenue(type, station, part, partNum)
- local playerCoords = GetEntityCoords(PlayerPedId())
- PlayerData = ESX.GetPlayerData()
- local elements = {
- {label = _U('garage_storeditem'), action = 'garage'},
- {label = _U('garage_storeitem'), action = 'store_garage'}
- }
- ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'vehicle', {
- title = _U('garage_title'),
- align = 'top-left',
- elements = elements
- }, function(data, menu)
- if data.current.action == 'garage' then
- local garage = {}
- ESX.TriggerServerCallback('esx_vehicleshop:retrieveJobVehicles', function(jobVehicles)
- if #jobVehicles > 0 then
- for k,v in ipairs(jobVehicles) do
- local props = json.decode(v.vehicle)
- local fuellvl = json.decode(v.fuellevel)
- local dmglvl = json.decode(v.damage)
- local vehicleName = GetLabelText(GetDisplayNameFromVehicleModel(props.model))
- local label = ('%s - <span style="color:darkgoldenrod;">%s</span>: '):format(vehicleName, props.plate)
- if v.state then
- label = label .. ('<span style="color:green;">%s</span>'):format(_U('garage_stored'))
- else
- label = label .. ('<span style="color:darkred;">%s</span>'):format(_U('garage_notstored'))
- end
- table.insert(garage, {
- label = label,
- stored = v.state,
- model = props.model,
- vehicleProps = props,
- damage = dmglvl,
- fuelg = fuellvl
- })
- print(fuellvl)
- end
- ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'vehicle_garage', {
- title = _U('garage_title'),
- align = 'top-left',
- elements = garage
- }, function(data2, menu2)
- if data2.current.stored then
- local spawnP = Config.VehicleSpawnPoint.Pos
- local headingP = Config.VehicleSpawnPoint.heading
- menu2.close()
- TriggerEvent('fuel:setGarageFuel', data2.current.fuelg)
- print('SPAWN AHEAD')
- print(headingP)
- print(spawnP)
- ESX.Game.SpawnVehicle(data2.current.model, spawnP, headingP, function(vehicle)
- ESX.Game.SetVehicleProperties(vehicle, data2.current.vehicleProps)
- SetVehicleEngineHealth(vehicle, data2.current.damage + .0)
- TriggerServerEvent('esx_vehicleshop:setJobVehicleState', data2.current.vehicleProps.plate, false)
- ESX.ShowNotification('Auto Ausgeparkt')
- end)
- else
- ESX.ShowNotification(_U('garage_notavailable'))
- end
- end, function(data2, menu2)
- menu2.close()
- end)
- else
- ESX.ShowNotification(_U('garage_empty'))
- end
- end, 'car')
- elseif data.current.action == 'store_garage' then
- StoreNearbyVehicle(playerCoords)
- end
- end, function(data, menu)
- menu.close()
- end)
- end
- function StoreNearbyVehicle(playerCoords)
- local vehicles, vehiclePlates = ESX.Game.GetVehiclesInArea(playerCoords, 30.0), {}
- local fuellev = nil
- local damagelev = nil
- local lastdrivenveh = GetLastDrivenVehicle()
- local lastveh = nil
- local vehplate = GetVehicleNumberPlateText(lastdrivenveh)
- if #vehicles > 0 then
- for k,v in ipairs(vehicles) do
- -- Make sure the vehicle we're saving is empty, or else it wont be deleted
- if GetVehicleNumberOfPassengers(v) == 0 and IsVehicleSeatFree(v, -1) then
- table.insert(vehiclePlates, {
- vehicle = v,
- plate = ESX.Math.Trim(GetVehicleNumberPlateText(v))
- })
- end
- if GetVehicleNumberPlateText(v) == vehplate then
- lastveh = v
- else
- lastveh = nil
- end
- end
- else
- ESX.ShowNotification(_U('garage_store_nearby'))
- return
- end
- if lastveh == nil then
- ESX.ShowNotification('~r~Du musst zuerst mit dem Fahrzeug Gefahren sein, welches du einparken willst.')
- return
- else
- fuellev = GetVehicleFuelLevel(lastveh)
- damagelev = GetVehicleEngineHealth(lastveh)
- print('CAR FUEL - ' .. fuellev)
- print('CAR dmg - ' .. damagelev)
- end
- ESX.TriggerServerCallback('esx_policejob:storeNearbyVehicle', function(storeSuccess, foundNum)
- if storeSuccess then
- local vehicleId = vehiclePlates[foundNum]
- local attempts = 0
- ESX.Game.DeleteVehicle(vehicleId.vehicle)
- IsBusy = true
- Citizen.CreateThread(function()
- while IsBusy do
- Citizen.Wait(0)
- drawLoadingText(_U('garage_storing'), 255, 255, 255, 255)
- end
- end)
- -- Workaround for vehicle not deleting when other players are near it.
- while DoesEntityExist(vehicleId.vehicle) do
- Citizen.Wait(500)
- attempts = attempts + 1
- -- Give up
- if attempts > 30 then
- break
- end
- vehicles = ESX.Game.GetVehiclesInArea(playerCoords, 30.0)
- if #vehicles > 0 then
- for k,v in ipairs(vehicles) do
- if ESX.Math.Trim(GetVehicleNumberPlateText(v)) == vehicleId.plate then
- ESX.Game.DeleteVehicle(v)
- break
- end
- end
- end
- end
- IsBusy = false
- ESX.ShowNotification(_U('garage_has_stored'))
- else
- ESX.ShowNotification(_U('garage_has_notstored'))
- end
- end, vehiclePlates, damagelev, fuellev)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement