Advertisement
rcs2112

Untitled

Dec 10th, 2018
330
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.18 KB | None | 0 0
  1. local Keys = {
  2. ["ESC"] = 322, ["BACKSPACE"] = 177, ["E"] = 38, ["ENTER"] = 18, ["LEFT"] = 174, ["RIGHT"] = 175, ["TOP"] = 27, ["DOWN"] = 173
  3. }
  4.  
  5. local menuIsShowed = false
  6. local hasAlreadyEnteredMarker = false
  7. local lastZone = nil
  8. local isInJoblistingMarker = false
  9.  
  10. ESX = nil
  11.  
  12. Citizen.CreateThread(function()
  13. while ESX == nil do
  14. TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)
  15. Citizen.Wait(0)
  16. end
  17. end)
  18.  
  19. function ShowJobListingMenu()
  20. ESX.TriggerServerCallback('esx_joblisting:getJobsList', function(data)
  21. local elements = {}
  22.  
  23. for i = 1, #data, 1 do
  24. table.insert(elements, {
  25. label = data[i].label,
  26. job = data[i].job
  27. })
  28. end
  29.  
  30. ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'joblisting', {
  31. title = _U('job_center'),
  32. align = 'top-left',
  33. elements = elements
  34. }, function(data, menu)
  35. TriggerServerEvent('esx_joblisting:setJob', data.current.job)
  36. ESX.ShowNotification(_U('new_job'))
  37. menu.close()
  38. end, function(data, menu)
  39. menu.close()
  40. end)
  41.  
  42. end)
  43. end
  44.  
  45. AddEventHandler('esx_joblisting:hasExitedMarker', function(zone)
  46. ESX.UI.Menu.CloseAll()
  47. end)
  48.  
  49. -- Display markers
  50. Citizen.CreateThread(function()
  51. while true do
  52. Citizen.Wait(1)
  53. local coords = GetEntityCoords(PlayerPedId())
  54. for i=1, #Config.Zones, 1 do
  55. if GetDistanceBetweenCoords(coords, Config.Zones[i].x, Config.Zones[i].y, Config.Zones[i].z, true) < Config.DrawDistance then
  56. DrawMarker(Config.MarkerType, Config.Zones[i].x, Config.Zones[i].y, Config.Zones[i].z, 0.0, 0.0, 0.0, 0, 0.0, 0.0, Config.ZoneSize.x, Config.ZoneSize.y, Config.ZoneSize.z, Config.MarkerColor.r, Config.MarkerColor.g, Config.MarkerColor.b, 100, false, true, 2, false, false, false, false)
  57. end
  58. end
  59. end
  60. end)
  61.  
  62. -- Activate menu when player is inside marker
  63. Citizen.CreateThread(function()
  64. while true do
  65. Citizen.Wait(1)
  66.  
  67. local coords, currentZone = GetEntityCoords(PlayerPedId()), nil
  68.  
  69. for i=1, #Config.Zones, 1 do
  70. if GetDistanceBetweenCoords(coords, Config.Zones[i].x, Config.Zones[i].y, Config.Zones[i].z, true) < (Config.ZoneSize.x / 2) then
  71. isInJoblistingMarker = true
  72. ESX.ShowHelpNotification(_U('access_job_center'))
  73. end
  74. end
  75.  
  76. if isInJoblistingMarker and not hasAlreadyEnteredMarker then
  77. hasAlreadyEnteredMarker = true
  78. end
  79.  
  80. if not isInJoblistingMarker and hasAlreadyEnteredMarker then
  81. hasAlreadyEnteredMarker = false
  82. TriggerEvent('esx_joblisting:hasExitedMarker')
  83. end
  84. end
  85. end)
  86.  
  87. -- Create blips
  88. Citizen.CreateThread(function()
  89. for i=1, #Config.Zones, 1 do
  90. local blip = AddBlipForCoord(Config.Zones[i].x, Config.Zones[i].y, Config.Zones[i].z)
  91.  
  92. SetBlipSprite (blip, 407)
  93. SetBlipDisplay(blip, 4)
  94. SetBlipScale (blip, 1.2)
  95. SetBlipColour (blip, 27)
  96. SetBlipAsShortRange(blip, true)
  97.  
  98. BeginTextCommandSetBlipName("STRING")
  99. AddTextComponentString(_U('job_center'))
  100. EndTextCommandSetBlipName(blip)
  101. end
  102. end)
  103.  
  104. -- Menu Controls
  105. Citizen.CreateThread(function()
  106. while true do
  107. Citizen.Wait(10)
  108.  
  109. if IsControlJustReleased(0, Keys['E']) and isInJoblistingMarker and not menuIsShowed then
  110. ESX.UI.Menu.CloseAll()
  111. ShowJobListingMenu()
  112. end
  113. end
  114. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement