Advertisement
Guest User

Untitled

a guest
May 26th, 2020
256
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.61 KB | None | 0 0
  1. function OpenVehicleSpawnerMenu()
  2. IsInShopMenu = true
  3.  
  4.     StartShopRestriction()
  5.     ESX.UI.Menu.CloseAll()
  6.  
  7.     local playerPed = PlayerPedId()
  8.  
  9.     FreezeEntityPosition(playerPed, true)
  10.     SetEntityVisible(playerPed, false)
  11.     SetEntityCoords(playerPed, previewpoint.Coords)
  12.  
  13.     local vehiclesByCategory = {}
  14.     local elements           = {}
  15.     local firstVehicleData   = nil
  16.     local options = {}
  17.  
  18.     for i=1, #Categories, 1 do
  19.         table.insert(vehiclesByCategory, { category = Categories[i].label })
  20.     end
  21.  
  22.     for i=1, #Vehicles, 1 do
  23.         if i == 1 then
  24.             firstVehicleData = Vehicles[i]
  25.         end
  26.        
  27.         if IsModelInCdimage(GetHashKey(Vehicles[i].model)) then
  28.             for k, v in pairs(vehiclesByCategory) do
  29.                 if v.category == Vehicles[i].category then
  30.                     table.insert(v, Vehicles[i])
  31.  
  32.                     table.insert(options, ('%s <span style="color:green;">%s</span>'):format(Vehicles[i].name, '', 0))
  33.  
  34.                     table.insert(elements, {
  35.                         name    = Vehicles[i].name,
  36.                         label   = Vehicles[i].category,
  37.                         value   = 0,
  38.                         type    = 'slider',
  39.                         max     = #v,
  40.                         options = options
  41.                     })
  42.                 end
  43.             end
  44.         else
  45.             print(('[empd] [^3ERROR^7] Vehicle "%s" does not exist'):format(Vehicles[i].model))
  46.         end
  47.     end
  48.  
  49. ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'vehicle_shop', {
  50.         title    = _U('car_dealer'),
  51.         align    = 'top-left',
  52.         elements = elements
  53.     }, function(data, menu)
  54.         local vehicleData = vehiclesByCategory[data.current.name][data.current.value + 1]
  55.  
  56.         ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'shop_confirm', {
  57.             title = _U('buy_vehicle_shop', vehicleData.name, ESX.Math.GroupDigits(vehicleData.price)),
  58.             align = 'top-left',
  59.             elements = {
  60.                 {label = _U('no'),  value = 'no'},
  61.                 {label = _U('yes'), value = 'yes'}
  62.         }}, function(data2, menu2)
  63.             if data2.current.value == 'yes' then
  64.                 if Config.EnablePlayerManagement then
  65.                     ESX.TriggerServerCallback('esx_vehicleshop:buyCarDealerVehicle', function(success)
  66.                         if success then
  67.                             IsInShopMenu = false
  68.                             DeleteDisplayVehicleInsideShop()
  69.  
  70.                             CurrentAction     = 'shop_menu'
  71.                             CurrentActionMsg  = _U('shop_menu')
  72.                             CurrentActionData = {}
  73.  
  74.                             local playerPed = PlayerPedId()
  75.                             FreezeEntityPosition(playerPed, false)
  76.                             SetEntityVisible(playerPed, true)
  77.                             SetEntityCoords(playerPed, shoppos.Coords)
  78.  
  79.                             menu2.close()
  80.                             menu.close()
  81.                             ESX.ShowNotification(_U('vehicle_purchased'))
  82.                         else
  83.                             ESX.ShowNotification(_U('broke_company'))
  84.                         end
  85.                     end, vehicleData.model)
  86.                 else
  87.                     local generatedPlate = GeneratePlate()
  88.  
  89.                     ESX.TriggerServerCallback('esx_vehicleshop:buyVehicle', function(success)
  90.                         if success then
  91.                             IsInShopMenu = false
  92.                             menu2.close()
  93.                             menu.close()
  94.                             DeleteDisplayVehicleInsideShop()
  95.  
  96.                             ESX.Game.SpawnVehicle(vehicleData.model, vehiclespawnpoint.Coords, vehiclespawnpoint.Handling, function(vehicle)
  97.                                 TaskWarpPedIntoVehicle(playerPed, vehicle, -1)
  98.                                 SetVehicleNumberPlateText(vehicle, generatedPlate)
  99.  
  100.                                 FreezeEntityPosition(playerPed, false)
  101.                                 SetEntityVisible(playerPed, true)
  102.                             end)
  103.                         else
  104.                             ESX.ShowNotification(_U('not_enough_money'))
  105.                         end
  106.                     end, vehicleData.model, generatedPlate)
  107.                 end
  108.             else
  109.                 menu2.close()
  110.             end
  111.         end, function(data2, menu2)
  112.             menu2.close()
  113.         end)
  114.     end, function(data, menu)
  115.         menu.close()
  116.         DeleteDisplayVehicleInsideShop()
  117.         local playerPed = PlayerPedId()
  118.  
  119.         CurrentAction     = 'shop_menu'
  120.         CurrentActionMsg  = _U('shop_menu')
  121.         CurrentActionData = {}
  122.  
  123.         FreezeEntityPosition(playerPed, false)
  124.         SetEntityVisible(playerPed, true)
  125.         SetEntityCoords(playerPed, previewpoint.Coords)
  126.  
  127.         IsInShopMenu = false
  128.     end, function(data, menu)
  129.         local vehicleData = vehiclesByCategory[data.current.name][data.current.value + 1]
  130.         local playerPed   = PlayerPedId()
  131.  
  132.         DeleteDisplayVehicleInsideShop()
  133.         WaitForVehicleToLoad(vehicleData.model)
  134.  
  135.         ESX.Game.SpawnLocalVehicle(vehicleData.model, previewpoint.Coords, previewpoint.Handling, function(vehicle)
  136.             currentDisplayVehicle = vehicle
  137.             TaskWarpPedIntoVehicle(playerPed, vehicle, -1)
  138.             FreezeEntityPosition(vehicle, true)
  139.             SetModelAsNoLongerNeeded(vehicleData.model)
  140.         end)
  141.     end)
  142.  
  143.     DeleteDisplayVehicleInsideShop()
  144.     WaitForVehicleToLoad(firstVehicleData.model)
  145.  
  146.     ESX.Game.SpawnLocalVehicle(firstVehicleData.model, previewpoint.Coords, previewpoint.Handling, function(vehicle)
  147.         currentDisplayVehicle = vehicle
  148.         TaskWarpPedIntoVehicle(playerPed, vehicle, -1)
  149.         FreezeEntityPosition(vehicle, true)
  150.         SetModelAsNoLongerNeeded(firstVehicleData.model)
  151.     end)
  152.     end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement