Advertisement
Guest User

Gta

a guest
Feb 20th, 2019
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 21.23 KB | None | 0 0
  1. local CurrentAction, CurrentActionMsg, CurrentActionData = nil, '', {}
  2. local HasAlreadyEnteredMarker, LastBuilding, LastPart, LastPartNum
  3. local IsBusy = false
  4. local spawnedVehicles, isInShopMenu = {}, false
  5.  
  6. function OpenFirefighterActionsMenu()
  7.     local elements = {
  8.         {label = _U('cloakroom'), value = 'cloakroom'}
  9.     }
  10.  
  11.     if Config.EnablePlayerManagement and ESX.PlayerData.job.grade_name == 'boss' then
  12.         table.insert(elements, {label = _U('boss_actions'), value = 'boss_actions'})
  13.     end
  14.  
  15.     ESX.UI.Menu.CloseAll()
  16.  
  17.     ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'firefighter_actions',
  18.     {
  19.         title       = _U('firefighter'),
  20.         align       = 'top-left',
  21.         elements    = elements
  22.     }, function(data, menu)
  23.         if data.current.value == 'cloakroom' then
  24.             OpenCloakroomMenu()
  25.         elseif data.current.value == 'boss_actions' then
  26.             TriggerEvent('esx_society:openBossMenu', 'firefighter', function(data, menu)
  27.                 menu.close()
  28.             end, {wash = false})
  29.         end
  30.     end, function(data, menu)
  31.         menu.close()
  32.     end)
  33. end
  34.  
  35. function FastTravel(coords, heading)
  36.     TeleportFadeEffect(PlayerPedId(), coords, heading)
  37. end
  38.  
  39. function TeleportFadeEffect(entity, coords, heading)
  40.     Citizen.CreateThread(function()
  41.         DoScreenFadeOut(800)
  42.  
  43.         while not IsScreenFadedOut() do
  44.             Citizen.Wait(0)
  45.         end
  46.  
  47.         ESX.Game.Teleport(entity, coords, function()
  48.             DoScreenFadeIn(800)
  49.  
  50.             if heading then
  51.                 SetEntityHeading(entity, heading)
  52.             end
  53.         end)
  54.     end)
  55. end
  56.  
  57. -- Draw markers & Marker logic
  58. Citizen.CreateThread(function()
  59.     while true do
  60.         Citizen.Wait(0)
  61.         local playerCoords = GetEntityCoords(PlayerPedId())
  62.         local canSleep, isInMarker, hasExited = true, false, false
  63.         local currentBuilding, currentPart, currentPartNum
  64.  
  65.         for buildingNum,building in pairs(Config.Buildings) do
  66.  
  67.             -- Firefighter Actions
  68.             for k,v in ipairs(building.FirefighterActions) do
  69.                 local distance = GetDistanceBetweenCoords(playerCoords, v, true)
  70.  
  71.                 if distance < Config.DrawDistance then
  72.                     DrawMarker(Config.Marker.type, v, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, Config.Marker.x, Config.Marker.y, Config.Marker.z, Config.Marker.r, Config.Marker.g, Config.Marker.b, Config.Marker.a, false, false, 2, Config.Marker.rotate, nil, nil, false)
  73.                     canSleep = false
  74.                 end
  75.  
  76.                 if distance < Config.Marker.x then
  77.                     isInMarker, currentBuilding, currentPart, currentPartNum = true, buildingNum, 'FirefighterActions', k
  78.                 end
  79.             end
  80.  
  81.             -- Vehicle Spawners
  82.             for k,v in ipairs(building.Vehicles) do
  83.                 local distance = GetDistanceBetweenCoords(playerCoords, v.Spawner, true)
  84.  
  85.                 if distance < Config.DrawDistance then
  86.                     DrawMarker(v.Marker.type, v.Spawner, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, v.Marker.x, v.Marker.y, v.Marker.z, v.Marker.r, v.Marker.g, v.Marker.b, v.Marker.a, false, false, 2, v.Marker.rotate, nil, nil, false)
  87.                     canSleep = false
  88.                 end
  89.  
  90.                 if distance < v.Marker.x then
  91.                     isInMarker, currentBuilding, currentPart, currentPartNum = true, buildingNum, 'Vehicles', k
  92.                 end
  93.             end
  94.            
  95.             for k,v in ipairs(building.Vehicles2) do
  96.                 local distance = GetDistanceBetweenCoords(playerCoords, v.Spawner, true)
  97.  
  98.                 if distance < Config.DrawDistance then
  99.                     DrawMarker(v.Marker.type, v.Spawner, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, v.Marker.x, v.Marker.y, v.Marker.z, v.Marker.r, v.Marker.g, v.Marker.b, v.Marker.a, false, false, 2, v.Marker.rotate, nil, nil, false)
  100.                     canSleep = false
  101.                 end
  102.  
  103.                 if distance < v.Marker.x then
  104.                     isInMarker, currentBuilding, currentPart, currentPartNum = true, buildingNum, 'Vehicles2', k
  105.                 end
  106.             end
  107.  
  108.             -- Helicopter Spawners
  109.             for k,v in ipairs(building.Helicopters) do
  110.                 local distance = GetDistanceBetweenCoords(playerCoords, v.Spawner, true)
  111.  
  112.                 if distance < Config.DrawDistance then
  113.                     DrawMarker(v.Marker.type, v.Spawner, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, v.Marker.x, v.Marker.y, v.Marker.z, v.Marker.r, v.Marker.g, v.Marker.b, v.Marker.a, false, false, 2, v.Marker.rotate, nil, nil, false)
  114.                     canSleep = false
  115.                 end
  116.  
  117.                 if distance < v.Marker.x then
  118.                     isInMarker, currentBuilding, currentPart, currentPartNum = true, buildingNum, 'Helicopters', k
  119.                 end
  120.             end
  121.  
  122.             -- Fast Travels
  123.             for k,v in ipairs(building.FastTravels) do
  124.                 local distance = GetDistanceBetweenCoords(playerCoords, v.From, true)
  125.  
  126.                 if distance < Config.DrawDistance then
  127.                     DrawMarker(v.Marker.type, v.From, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, v.Marker.x, v.Marker.y, v.Marker.z, v.Marker.r, v.Marker.g, v.Marker.b, v.Marker.a, false, false, 2, v.Marker.rotate, nil, nil, false)
  128.                     canSleep = false
  129.                 end
  130.  
  131.  
  132.                 if distance < v.Marker.x then
  133.                     FastTravel(v.To.coords, v.To.heading)
  134.                 end
  135.             end
  136.  
  137.             -- Fast Travels (Prompt)
  138. --          for k,v in ipairs(building.FastTravelsPrompt) do
  139. --              local distance = GetDistanceBetweenCoords(playerCoords, v.From, true)
  140. --
  141. --              if distance < Config.DrawDistance then
  142. --                  DrawMarker(v.Marker.type, v.From, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, v.Marker.x, v.Marker.y, v.Marker.z, v.Marker.r, v.Marker.g, v.Marker.b, v.Marker.a, false, false, 2, v.Marker.rotate, nil, nil, false)
  143. --                  canSleep = false
  144. --              end
  145. --
  146. --              if distance < v.Marker.x then
  147. --                  isInMarker, currentBuilding, currentPart, currentPartNum = true, buildingNum, 'FastTravelsPrompt', k
  148. --              end
  149. --          end
  150.  
  151.             -- Logic for exiting & entering markers
  152.             if isInMarker and not HasAlreadyEnteredMarker or (isInMarker and (LastBuilding ~= currentBuilding or LastPart ~= currentPart or LastPartNum ~= currentPartNum)) then
  153.  
  154.                 if
  155.                     (LastBuilding ~= nil and LastPart ~= nil and LastPartNum ~= nil) and
  156.                     (LastBuilding ~= currentBuilding or LastPart ~= currentPart or LastPartNum ~= currentPartNum)
  157.                 then
  158.                     TriggerEvent('esx_firefighterjob:hasExitedMarker', LastBuilding, LastPart, LastPartNum)
  159.                     hasExited = true
  160.                 end
  161.  
  162.                 HasAlreadyEnteredMarker, LastBuilding, LastPart, LastPartNum = true, currentBuilding, currentPart, currentPartNum
  163.  
  164.                 TriggerEvent('esx_firefighterjob:hasEnteredMarker', currentBuilding, currentPart, currentPartNum)
  165.  
  166.             end
  167.  
  168.             if not hasExited and not isInMarker and HasAlreadyEnteredMarker then
  169.                 HasAlreadyEnteredMarker = false
  170.                 TriggerEvent('esx_firefighterjob:hasExitedMarker', LastBuilding, LastPart, LastPartNum)
  171.             end
  172.  
  173.         end
  174.     end
  175. end)
  176.  
  177. AddEventHandler('esx_firefighterjob:hasEnteredMarker', function(building, part, partNum)
  178.     if ESX.PlayerData.job and ESX.PlayerData.job.name == 'firefighter' then
  179.         if part == 'FirefighterActions' then
  180.             CurrentAction = part
  181.             CurrentActionMsg = _U('actions_prompt')
  182.             CurrentActionData = {}
  183.         elseif part == 'Pharmacy' then
  184.             CurrentAction = part
  185.             CurrentActionMsg = _U('open_pharmacy')
  186.             CurrentActionData = {}
  187.         elseif part == 'Vehicles' then
  188.             CurrentAction = part
  189.             CurrentActionMsg = _U('garage_prompt')
  190.             CurrentActionData = {building = building, partNum = partNum}
  191.         elseif part == 'Vehicles2' then
  192.             CurrentAction = part
  193.             CurrentActionMsg = _U('garage_prompt')
  194.             CurrentActionData = {building = building, partNum = partNum}
  195.         elseif part == 'Helicopters' then
  196.             CurrentAction = part
  197.             CurrentActionMsg = _U('helicopter_prompt')
  198.             CurrentActionData = {building = building, partNum = partNum}
  199.         elseif part == 'FastTravelsPrompt' then
  200.             local travelItem = Config.Buildings[building][part][partNum]
  201.  
  202.             CurrentAction = part
  203.             CurrentActionMsg = travelItem.Prompt
  204.             CurrentActionData = {to = travelItem.To.coords, heading = travelItem.To.heading}
  205.         end
  206.     end
  207. end)
  208.  
  209. AddEventHandler('esx_firefighterjob:hasExitedMarker', function(building, part, partNum)
  210.     if not isInShopMenu then
  211.         ESX.UI.Menu.CloseAll()
  212.     end
  213.  
  214.     CurrentAction = nil
  215. end)
  216.  
  217. -- Key Controls
  218. Citizen.CreateThread(function()
  219.     while true do
  220.         Citizen.Wait(0)
  221.  
  222.         if CurrentAction then
  223.             ESX.ShowHelpNotification(CurrentActionMsg)
  224.  
  225.             if IsControlJustReleased(0, Keys['E']) then
  226.  
  227.                 if CurrentAction == 'FirefighterActions' then
  228.                     OpenFirefighterActionsMenu()
  229.                 elseif CurrentAction == 'Vehicles' then
  230.                     OpenVehicleSpawnerMenu(CurrentActionData.building, CurrentActionData.partNum)
  231.                 elseif CurrentAction == 'Vehicles2' then
  232.                     OpenVehicleSpawnerMenu2(CurrentActionData.building, CurrentActionData.partNum)
  233.                 elseif CurrentAction == 'Helicopters' then
  234.                     OpenHelicopterSpawnerMenu(CurrentActionData.building, CurrentActionData.partNum)
  235.                 elseif CurrentAction == 'FastTravelsPrompt' then
  236.                     FastTravel(CurrentActionData.to, CurrentActionData.heading)
  237.                 end
  238.  
  239.                 CurrentAction = nil
  240.  
  241.             end
  242.  
  243.         elseif ESX.PlayerData.job ~= nil and ESX.PlayerData.job.name == 'firefighter' and not IsDead then
  244.             if IsControlJustReleased(0, Keys['F6']) then
  245.                 OpenMobileFirefighterActionsMenu()
  246.             end
  247.         else
  248.             Citizen.Wait(500)
  249.         end
  250.     end
  251. end)
  252.  
  253. function OpenCloakroomMenu()
  254.     ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'cloakroom',
  255.     {
  256.         title       = _U('cloakroom'),
  257.         align       = 'top-left',
  258.         elements = {
  259.             {label = _U('ems_clothes_civil'), value = 'citizen_wear'},
  260.             {label = _U('ems_clothes_ems'), value = 'firefighter_wear'},
  261.         }
  262.     }, function(data, menu)
  263.         if data.current.value == 'citizen_wear' then
  264.             ESX.TriggerServerCallback('esx_skin:getPlayerSkin', function(skin, jobSkin)
  265.                 TriggerEvent('skinchanger:loadSkin', skin)
  266.             end)
  267.         elseif data.current.value == 'firefighter_wear' then
  268.             ESX.TriggerServerCallback('esx_skin:getPlayerSkin', function(skin, jobSkin)
  269.                 if skin.sex == 0 then
  270.                     TriggerEvent('skinchanger:loadClothes', skin, jobSkin.skin_male)
  271.                 else
  272.                     TriggerEvent('skinchanger:loadClothes', skin, jobSkin.skin_female)
  273.                 end
  274.             end)
  275.         end
  276.  
  277.         menu.close()
  278.     end, function(data, menu)
  279.         menu.close()
  280.     end)
  281. end
  282.  
  283. function OpenVehicleSpawnerMenu(building, partNum)
  284.     local playerCoords = GetEntityCoords(PlayerPedId())
  285.     local elements = {
  286.         {label = ("Firetruck"), action = 'spawnFiretruck'}
  287.     }
  288.  
  289.     ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'vehicle', {
  290.         title    = ("Vehicle list"),
  291.         align    = 'top-left',
  292.         elements = elements
  293.     }, function(data, menu)
  294.         if data.current.action == 'spawnFiretruck' then
  295.             vehiclehash = GetHashKey("firetruk")
  296.             RequestModel(vehiclehash)
  297.             Citizen.CreateThread(function()
  298.                 local waiting = 0
  299.                 while not HasModelLoaded(vehiclehash) do
  300.                     waiting = waiting + 100
  301.                     Citizen.Wait(100)
  302.                     if waiting > 5000 then
  303.                         ShowNotification("~r~Could not load the vehicle model in time, a crash was prevented.")
  304.                         break
  305.                     end
  306.                 end
  307.                 local selectedPlayer = PlayerPedId()
  308.                 local spawnVeh = CreateVehicle(vehiclehash, 209.31, -1647.15, 29.8, 319.06, true, true)
  309.                 menu.close()
  310.                 SetPedIntoVehicle(selectedPlayer, spawnVeh, -1)
  311.                 --SetEntityAsNoLongerNeeded(vehicle)
  312.                 SetModelAsNoLongerNeeded(vehiclehash)
  313.             end)
  314.         end
  315.     end, function(data, menu)
  316.         menu.close()
  317.     end)
  318.  
  319. end
  320.  
  321. function OpenVehicleSpawnerMenu2(building, partNum)
  322.     local playerCoords = GetEntityCoords(PlayerPedId())
  323.     local elements = {
  324.         {label = ("Firetruck"), action = 'spawnFiretruck'}
  325.     }
  326.  
  327.     ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'vehicle', {
  328.         title    = _U('garage_title'),
  329.         align    = 'top-left',
  330.         elements = elements
  331.     }, function(data, menu)
  332.         if data.current.action == 'spawnFiretruck' then
  333.             vehiclehash = GetHashKey("firetruk")
  334.             RequestModel(vehiclehash)
  335.             Citizen.CreateThread(function()
  336.                 local waiting = 0
  337.                 while not HasModelLoaded(vehiclehash) do
  338.                     waiting = waiting + 100
  339.                     Citizen.Wait(100)
  340.                     if waiting > 5000 then
  341.                         ShowNotification("~r~Could not load the vehicle model in time, a crash was prevented.")
  342.                         break
  343.                     end
  344.                 end
  345.                 local selectedPlayer = PlayerPedId()
  346.                 local spawnVeh = CreateVehicle(vehiclehash, 212.48, -1649.78, 29.8, 319.06, true, true)
  347.                 menu.close()
  348.                 SetPedIntoVehicle(selectedPlayer, spawnVeh, -1)
  349.                 --SetEntityAsNoLongerNeeded(vehicle)
  350.                 SetModelAsNoLongerNeeded(vehiclehash)
  351.             end)
  352.         end
  353.     end, function(data, menu)
  354.         menu.close()
  355.     end)
  356.  
  357. end
  358.  
  359. function StoreNearbyVehicle(playerCoords)
  360.     local vehicles, vehiclePlates = ESX.Game.GetVehiclesInArea(playerCoords, 30.0), {}
  361.  
  362.     if #vehicles > 0 then
  363.         for k,v in ipairs(vehicles) do
  364.  
  365.             -- Make sure the vehicle we're saving is empty, or else it wont be deleted
  366.             if GetVehicleNumberOfPassengers(v) == 0 and IsVehicleSeatFree(v, -1) then
  367.                 table.insert(vehiclePlates, {
  368.                     vehicle = v,
  369.                     plate = ESX.Math.Trim(GetVehicleNumberPlateText(v))
  370.                 })
  371.             end
  372.         end
  373.     else
  374.         ESX.ShowNotification(_U('garage_store_nearby'))
  375.         return
  376.     end
  377.  
  378.     ESX.TriggerServerCallback('esx_firefighterjob:storeNearbyVehicle', function(storeSuccess, foundNum)
  379.         if storeSuccess then
  380.             local vehicleId = vehiclePlates[foundNum]
  381.             local attempts = 0
  382.             ESX.Game.DeleteVehicle(vehicleId.vehicle)
  383.             IsBusy = true
  384.  
  385.             Citizen.CreateThread(function()
  386.                 while IsBusy do
  387.                     Citizen.Wait(0)
  388.                     drawLoadingText(_U('garage_storing'), 255, 255, 255, 255)
  389.                 end
  390.             end)
  391.  
  392.             -- Workaround for vehicle not deleting when other players are near it.
  393.             while DoesEntityExist(vehicleId.vehicle) do
  394.                 Citizen.Wait(500)
  395.                 attempts = attempts + 1
  396.  
  397.                 -- Give up
  398.                 if attempts > 30 then
  399.                     break
  400.                 end
  401.  
  402.                 vehicles = ESX.Game.GetVehiclesInArea(playerCoords, 30.0)
  403.                 if #vehicles > 0 then
  404.                     for k,v in ipairs(vehicles) do
  405.                         if ESX.Math.Trim(GetVehicleNumberPlateText(v)) == vehicleId.plate then
  406.                             ESX.Game.DeleteVehicle(v)
  407.                             break
  408.                         end
  409.                     end
  410.                 end
  411.             end
  412.  
  413.             IsBusy = false
  414.             ESX.ShowNotification(_U('garage_has_stored'))
  415.         else
  416.             ESX.ShowNotification(_U('garage_has_notstored'))
  417.         end
  418.     end, vehiclePlates)
  419. end
  420.  
  421. function GetAvailableVehicleSpawnPoint(building, part, partNum)
  422.     local spawnPoints = Config.Buildings[building][part][partNum].SpawnPoints
  423.     local found, foundSpawnPoint = false, nil
  424.  
  425.     for i=1, #spawnPoints, 1 do
  426.         if ESX.Game.IsSpawnPointClear(spawnPoints[i].coords, spawnPoints[i].radius) then
  427.             found, foundSpawnPoint = true, spawnPoints[i]
  428.             break
  429.         end
  430.     end
  431.  
  432.     if found then
  433.         return true, foundSpawnPoint
  434.     else
  435.         ESX.ShowNotification(_U('garage_blocked'))
  436.         return false
  437.     end
  438. end
  439.  
  440. function OpenHelicopterSpawnerMenu(building, partNum)
  441.     local playerCoords = GetEntityCoords(PlayerPedId())
  442.     ESX.PlayerData = ESX.GetPlayerData()
  443.     local elements = {
  444.         {label = _U('helicopter_garage'), action = 'garage'},
  445.         {label = _U('helicopter_store'), action = 'store_garage'},
  446.         {label = _U('helicopter_buy'), action = 'buy_helicopter'}
  447.     }
  448.  
  449.     ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'helicopter_spawner', {
  450.         title    = _U('helicopter_title'),
  451.         align    = 'top-left',
  452.         elements = elements
  453.     }, function(data, menu)
  454.  
  455.         if data.current.action == 'buy_helicopter' then
  456.             local shopCoords = Config.Buildings[building].Helicopters[partNum].InsideShop
  457.             local shopElements = {}
  458.  
  459.             local authorizedHelicopters = Config.AuthorizedHelicopters[ESX.PlayerData.job.grade_name]
  460.  
  461.             if #authorizedHelicopters > 0 then
  462.                 for k,helicopter in ipairs(authorizedHelicopters) do
  463.                     table.insert(shopElements, {
  464.                         label = ('%s - <span style="color:green;">%s</span>'):format(helicopter.label, _U('shop_item', ESX.Math.GroupDigits(helicopter.price))),
  465.                         name  = helicopter.label,
  466.                         model = helicopter.model,
  467.                         price = helicopter.price,
  468.                         type  = 'helicopter'
  469.                     })
  470.                 end
  471.             else
  472.                 ESX.ShowNotification(_U('helicopter_notauthorized'))
  473.                 return
  474.             end
  475.  
  476.             OpenShopMenu(shopElements, playerCoords, shopCoords)
  477.         elseif data.current.action == 'garage' then
  478.             local garage = {}
  479.  
  480.             ESX.TriggerServerCallback('esx_vehicleshop:retrieveJobVehicles', function(jobVehicles)
  481.                 if #jobVehicles > 0 then
  482.                     for k,v in ipairs(jobVehicles) do
  483.                         local props = json.decode(v.vehicle)
  484.                         local vehicleName = GetLabelText(GetDisplayNameFromVehicleModel(props.model))
  485.                         local label = ('%s - <span style="color:darkgoldenrod;">%s</span>: '):format(vehicleName, props.plate)
  486.  
  487.                         if v.stored then
  488.                             label = label .. ('<span style="color:green;">%s</span>'):format(_U('garage_stored'))
  489.                         else
  490.                             label = label .. ('<span style="color:darkred;">%s</span>'):format(_U('garage_notstored'))
  491.                         end
  492.  
  493.                         table.insert(garage, {
  494.                             label = label,
  495.                             stored = v.stored,
  496.                             model = props.model,
  497.                             vehicleProps = props
  498.                         })
  499.                     end
  500.  
  501.                     ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'helicopter_garage', {
  502.                         title    = _U('helicopter_garage_title'),
  503.                         align    = 'top-left',
  504.                         elements = garage
  505.                     }, function(data2, menu2)
  506.                         if data2.current.stored then
  507.                             local foundSpawn, spawnPoint = GetAvailableVehicleSpawnPoint(building, 'Helicopters', partNum)
  508.  
  509.                             if foundSpawn then
  510.                                 menu2.close()
  511.  
  512.                                 ESX.Game.SpawnVehicle(data2.current.model, spawnPoint.coords, spawnPoint.heading, function(vehicle)
  513.                                     ESX.Game.SetVehicleProperties(vehicle, data2.current.vehicleProps)
  514.  
  515.                                     TriggerServerEvent('esx_vehicleshop:setJobVehicleState', data2.current.vehicleProps.plate, false)
  516.                                     ESX.ShowNotification(_U('garage_released'))
  517.                                 end)
  518.                             end
  519.                         else
  520.                             ESX.ShowNotification(_U('garage_notavailable'))
  521.                         end
  522.                     end, function(data2, menu2)
  523.                         menu2.close()
  524.                     end)
  525.  
  526.                 else
  527.                     ESX.ShowNotification(_U('garage_empty'))
  528.                 end
  529.             end, 'helicopter')
  530.  
  531.         elseif data.current.action == 'store_garage' then
  532.             StoreNearbyVehicle(playerCoords)
  533.         end
  534.  
  535.     end, function(data, menu)
  536.         menu.close()
  537.     end)
  538.  
  539. end
  540.  
  541. function OpenShopMenu(elements, restoreCoords, shopCoords)
  542.     local playerPed = PlayerPedId()
  543.     isInShopMenu = true
  544.  
  545.     ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'vehicle_shop', {
  546.         title    = _U('vehicleshop_title'),
  547.         align    = 'top-left',
  548.         elements = elements
  549.     }, function(data, menu)
  550.  
  551.         ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'vehicle_shop_confirm',
  552.         {
  553.             title    = _U('vehicleshop_confirm', data.current.name, data.current.price),
  554.             align    = 'top-left',
  555.             elements = {
  556.                 { label = _U('confirm_no'), value = 'no' },
  557.                 { label = _U('confirm_yes'), value = 'yes' }
  558.             }
  559.         }, function(data2, menu2)
  560.  
  561.             if data2.current.value == 'yes' then
  562.                 local newPlate = exports['esx_vehicleshop']:GeneratePlate()
  563.                 local vehicle  = GetVehiclePedIsIn(playerPed, false)
  564.                 local props    = ESX.Game.GetVehicleProperties(vehicle)
  565.                 props.plate    = newPlate
  566.  
  567.                 ESX.TriggerServerCallback('esx_firefighterjob:buyJobVehicle', function (bought)
  568.                     if bought then
  569.                         ESX.ShowNotification(_U('vehicleshop_bought', data.current.name, ESX.Math.GroupDigits(data.current.price)))
  570.  
  571.                         isInShopMenu = false
  572.                         ESX.UI.Menu.CloseAll()
  573.                
  574.                         DeleteSpawnedVehicles()
  575.                         FreezeEntityPosition(playerPed, false)
  576.                         SetEntityVisible(playerPed, true)
  577.                
  578.                         ESX.Game.Teleport(playerPed, restoreCoords)
  579.                     else
  580.                         ESX.ShowNotification(_U('vehicleshop_money'))
  581.                         menu2.close()
  582.                     end
  583.                 end, props, data.current.type)
  584.             else
  585.                 menu2.close()
  586.             end
  587.  
  588.         end, function(data2, menu2)
  589.             menu2.close()
  590.         end)
  591.  
  592.         end, function(data, menu)
  593.         isInShopMenu = false
  594.         ESX.UI.Menu.CloseAll()
  595.  
  596.         DeleteSpawnedVehicles()
  597.         FreezeEntityPosition(playerPed, false)
  598.         SetEntityVisible(playerPed, true)
  599.  
  600.         ESX.Game.Teleport(playerPed, restoreCoords)
  601.     end, function(data, menu)
  602.         DeleteSpawnedVehicles()
  603.  
  604.         WaitForVehicleToLoad(data.current.model)
  605.         ESX.Game.SpawnLocalVehicle(data.current.model, shopCoords, 0.0, function(vehicle)
  606.             table.insert(spawnedVehicles, vehicle)
  607.             TaskWarpPedIntoVehicle(playerPed, vehicle, -1)
  608.             FreezeEntityPosition(vehicle, true)
  609.         end)
  610.     end)
  611.  
  612.     WaitForVehicleToLoad(elements[1].model)
  613.     ESX.Game.SpawnLocalVehicle(elements[1].model, shopCoords, 0.0, function(vehicle)
  614.         table.insert(spawnedVehicles, vehicle)
  615.         TaskWarpPedIntoVehicle(playerPed, vehicle, -1)
  616.         FreezeEntityPosition(vehicle, true)
  617.     end)
  618. end
  619.  
  620. Citizen.CreateThread(function()
  621.     while true do
  622.         Citizen.Wait(0)
  623.  
  624.         if isInShopMenu then
  625.             DisableControlAction(0, 75, true)  -- Disable exit vehicle
  626.             DisableControlAction(27, 75, true) -- Disable exit vehicle
  627.         else
  628.             Citizen.Wait(500)
  629.         end
  630.     end
  631. end)
  632.  
  633. function DeleteSpawnedVehicles()
  634.     while #spawnedVehicles > 0 do
  635.         local vehicle = spawnedVehicles[1]
  636.         ESX.Game.DeleteVehicle(vehicle)
  637.         table.remove(spawnedVehicles, 1)
  638.     end
  639. end
  640.  
  641. function WaitForVehicleToLoad(modelHash)
  642.     modelHash = (type(modelHash) == 'number' and modelHash or GetHashKey(modelHash))
  643.  
  644.     if not HasModelLoaded(modelHash) then
  645.         RequestModel(modelHash)
  646.  
  647.         while not HasModelLoaded(modelHash) do
  648.             Citizen.Wait(0)
  649.  
  650.             DisableControlAction(0, Keys['TOP'], true)
  651.             DisableControlAction(0, Keys['DOWN'], true)
  652.             DisableControlAction(0, Keys['LEFT'], true)
  653.             DisableControlAction(0, Keys['RIGHT'], true)
  654.             DisableControlAction(0, 176, true) -- ENTER key
  655.             DisableControlAction(0, Keys['BACKSPACE'], true)
  656.  
  657.             drawLoadingText(_U('vehicleshop_awaiting_model'), 255, 255, 255, 255)
  658.         end
  659.     end
  660. end
  661.  
  662. function drawLoadingText(text, red, green, blue, alpha)
  663.     SetTextFont(4)
  664.     SetTextProportional(0)
  665.     SetTextScale(0.0, 0.5)
  666.     SetTextColour(red, green, blue, alpha)
  667.     SetTextDropShadow(0, 0, 0, 0, 255)
  668.     SetTextEdge(1, 0, 0, 0, 255)
  669.     SetTextDropShadow()
  670.     SetTextOutline()
  671.     SetTextCentre(true)
  672.  
  673.     BeginTextCommandDisplayText("STRING")
  674.     AddTextComponentSubstringPlayerName(text)
  675.     EndTextCommandDisplayText(0.5, 0.5)
  676. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement