Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function OpenVehicleSpawnerMenu()
- IsInShopMenu = true
- StartShopRestriction()
- ESX.UI.Menu.CloseAll()
- local playerPed = PlayerPedId()
- FreezeEntityPosition(playerPed, true)
- SetEntityVisible(playerPed, false)
- SetEntityCoords(playerPed, previewpoint.Coords)
- local vehiclesByCategory = {}
- local elements = {}
- local firstVehicleData = nil
- local options = {}
- for i=1, #Categories, 1 do
- table.insert(vehiclesByCategory, { category = Categories[i].label })
- end
- for i=1, #Vehicles, 1 do
- if i == 1 then
- firstVehicleData = Vehicles[i]
- end
- if IsModelInCdimage(GetHashKey(Vehicles[i].model)) then
- for k, v in pairs(vehiclesByCategory) do
- if v.category == Vehicles[i].category then
- table.insert(v, Vehicles[i])
- table.insert(options, ('%s <span style="color:green;">%s</span>'):format(Vehicles[i].name, '', 0))
- table.insert(elements, {
- name = Vehicles[i].name,
- label = Vehicles[i].category,
- value = 0,
- type = 'slider',
- max = #v,
- options = options
- })
- end
- end
- else
- print(('[empd] [^3ERROR^7] Vehicle "%s" does not exist'):format(Vehicles[i].model))
- end
- end
- ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'vehicle_shop', {
- title = _U('car_dealer'),
- align = 'top-left',
- elements = elements
- }, function(data, menu)
- local vehicleData = vehiclesByCategory[data.current.name][data.current.value + 1]
- ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'shop_confirm', {
- title = _U('buy_vehicle_shop', vehicleData.name, ESX.Math.GroupDigits(vehicleData.price)),
- align = 'top-left',
- elements = {
- {label = _U('no'), value = 'no'},
- {label = _U('yes'), value = 'yes'}
- }}, function(data2, menu2)
- if data2.current.value == 'yes' then
- if Config.EnablePlayerManagement then
- ESX.TriggerServerCallback('esx_vehicleshop:buyCarDealerVehicle', function(success)
- if success then
- IsInShopMenu = false
- DeleteDisplayVehicleInsideShop()
- CurrentAction = 'shop_menu'
- CurrentActionMsg = _U('shop_menu')
- CurrentActionData = {}
- local playerPed = PlayerPedId()
- FreezeEntityPosition(playerPed, false)
- SetEntityVisible(playerPed, true)
- SetEntityCoords(playerPed, shoppos.Coords)
- menu2.close()
- menu.close()
- ESX.ShowNotification(_U('vehicle_purchased'))
- else
- ESX.ShowNotification(_U('broke_company'))
- end
- end, vehicleData.model)
- else
- local generatedPlate = GeneratePlate()
- ESX.TriggerServerCallback('esx_vehicleshop:buyVehicle', function(success)
- if success then
- IsInShopMenu = false
- menu2.close()
- menu.close()
- DeleteDisplayVehicleInsideShop()
- ESX.Game.SpawnVehicle(vehicleData.model, vehiclespawnpoint.Coords, vehiclespawnpoint.Handling, function(vehicle)
- TaskWarpPedIntoVehicle(playerPed, vehicle, -1)
- SetVehicleNumberPlateText(vehicle, generatedPlate)
- FreezeEntityPosition(playerPed, false)
- SetEntityVisible(playerPed, true)
- end)
- else
- ESX.ShowNotification(_U('not_enough_money'))
- end
- end, vehicleData.model, generatedPlate)
- end
- else
- menu2.close()
- end
- end, function(data2, menu2)
- menu2.close()
- end)
- end, function(data, menu)
- menu.close()
- DeleteDisplayVehicleInsideShop()
- local playerPed = PlayerPedId()
- CurrentAction = 'shop_menu'
- CurrentActionMsg = _U('shop_menu')
- CurrentActionData = {}
- FreezeEntityPosition(playerPed, false)
- SetEntityVisible(playerPed, true)
- SetEntityCoords(playerPed, previewpoint.Coords)
- IsInShopMenu = false
- end, function(data, menu)
- local vehicleData = vehiclesByCategory[data.current.name][data.current.value + 1]
- local playerPed = PlayerPedId()
- DeleteDisplayVehicleInsideShop()
- WaitForVehicleToLoad(vehicleData.model)
- ESX.Game.SpawnLocalVehicle(vehicleData.model, previewpoint.Coords, previewpoint.Handling, function(vehicle)
- currentDisplayVehicle = vehicle
- TaskWarpPedIntoVehicle(playerPed, vehicle, -1)
- FreezeEntityPosition(vehicle, true)
- SetModelAsNoLongerNeeded(vehicleData.model)
- end)
- end)
- DeleteDisplayVehicleInsideShop()
- WaitForVehicleToLoad(firstVehicleData.model)
- ESX.Game.SpawnLocalVehicle(firstVehicleData.model, previewpoint.Coords, previewpoint.Handling, function(vehicle)
- currentDisplayVehicle = vehicle
- TaskWarpPedIntoVehicle(playerPed, vehicle, -1)
- FreezeEntityPosition(vehicle, true)
- SetModelAsNoLongerNeeded(firstVehicleData.model)
- end)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement