Advertisement
lowheartrate

Untitled

May 16th, 2019
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.65 KB | None | 0 0
  1. local Keys = {
  2.     ["ESC"] = 322, ["F1"] = 288, ["F2"] = 289, ["F3"] = 170, ["F5"] = 166, ["F6"] = 167, ["F7"] = 168, ["F8"] = 169, ["F9"] = 56, ["F10"] = 57,
  3.     ["~"] = 243, ["1"] = 157, ["2"] = 158, ["3"] = 160, ["4"] = 164, ["5"] = 165, ["6"] = 159, ["7"] = 161, ["8"] = 162, ["9"] = 163, ["-"] = 84, ["="] = 83, ["BACKSPACE"] = 177,
  4.     ["TAB"] = 37, ["Q"] = 44, ["W"] = 32, ["E"] = 38, ["R"] = 45, ["T"] = 245, ["Y"] = 246, ["U"] = 303, ["P"] = 199, ["["] = 39, ["]"] = 40, ["ENTER"] = 18,
  5.     ["CAPS"] = 137, ["A"] = 34, ["S"] = 8, ["D"] = 9, ["F"] = 23, ["G"] = 47, ["H"] = 74, ["K"] = 311, ["L"] = 182,
  6.     ["LEFTSHIFT"] = 21, ["Z"] = 20, ["X"] = 73, ["C"] = 26, ["V"] = 0, ["B"] = 29, ["N"] = 249, ["M"] = 244, [","] = 82, ["."] = 81,
  7.     ["LEFTCTRL"] = 36, ["LEFTALT"] = 19, ["SPACE"] = 22, ["RIGHTCTRL"] = 70,
  8.     ["HOME"] = 213, ["PAGEUP"] = 10, ["PAGEDOWN"] = 11, ["DELETE"] = 178,
  9.     ["LEFT"] = 174, ["RIGHT"] = 175, ["TOP"] = 27, ["DOWN"] = 173,
  10.     ["NENTER"] = 201, ["N4"] = 108, ["N5"] = 60, ["N6"] = 107, ["N+"] = 96, ["N-"] = 97, ["N7"] = 117, ["N8"] = 61, ["N9"] = 118
  11. }
  12.  
  13. ESX                           = nil
  14. local HasAlreadyEnteredMarker = false
  15. local LastZone                = nil
  16. local CurrentAction           = nil
  17. local CurrentActionMsg        = ''
  18. local CurrentActionData       = {}
  19.  
  20. Citizen.CreateThread(function()
  21.     while ESX == nil do
  22.         TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)
  23.         Citizen.Wait(0)
  24.     end
  25.  
  26.     Citizen.Wait(5000)
  27.  
  28.     ESX.TriggerServerCallback('esx_shops:requestDBItems', function(ShopItems)
  29.         for k,v in pairs(ShopItems) do
  30.             Config.Zones[k].Items = v
  31.         end
  32.     end)
  33. end)
  34.  
  35. function OpenShopMenu(zone)
  36.     local elements = {}
  37.     for i=1, #Config.Zones[zone].Items, 1 do
  38.         local item = Config.Zones[zone].Items[i]
  39.  
  40.         if item.limit == -1 then
  41.             item.limit = 100
  42.         end
  43.  
  44.         table.insert(elements, {
  45.             label      = ('%s - <span style="color:green;">%s</span>'):format(item.label, _U('shop_item', ESX.Math.GroupDigits(item.price))),
  46.             label_real = item.label,
  47.             item       = item.item,
  48.             price      = item.price,
  49.  
  50.             -- menu properties
  51.             value      = 1,
  52.             type       = 'slider',
  53.             min        = 1,
  54.             max        = item.limit
  55.         })
  56.     end
  57.  
  58.     ESX.UI.Menu.CloseAll()
  59.     ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'shop', {
  60.         title    = _U('shop'),
  61.         align    = 'bottom-right',
  62.         elements = elements
  63.     }, function(data, menu)
  64.         ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'shop_confirm', {
  65.             title    = _U('shop_confirm', data.current.value, data.current.label_real, ESX.Math.GroupDigits(data.current.price * data.current.value)),
  66.             align    = 'bottom-right',
  67.             elements = {
  68.                 {label = _U('no'),  value = 'no'},
  69.                 {label = _U('yes'), value = 'yes'}
  70.             }
  71.         }, function(data2, menu2)
  72.             if data2.current.value == 'yes' then
  73.                 TriggerServerEvent('esx_shops:buyItem', data.current.item, data.current.value, zone)
  74.             end
  75.  
  76.             menu2.close()
  77.         end, function(data2, menu2)
  78.             menu2.close()
  79.         end)
  80.     end, function(data, menu)
  81.         menu.close()
  82.  
  83.         CurrentAction     = 'shop_menu'
  84.         CurrentActionMsg  = _U('press_menu')
  85.         CurrentActionData = {zone = zone}
  86.     end)
  87. end
  88.  
  89. AddEventHandler('esx_shops:hasEnteredMarker', function(zone)
  90.     CurrentAction     = 'shop_menu'
  91.     CurrentActionMsg  = _U('press_menu')
  92.     CurrentActionData = {zone = zone}
  93. end)
  94.  
  95. AddEventHandler('esx_shops:hasExitedMarker', function(zone)
  96.     CurrentAction = nil
  97.     ESX.UI.Menu.CloseAll()
  98. end)
  99.  
  100. -- Create Blips
  101. Citizen.CreateThread(function()
  102.     for k,v in pairs(Config.Zones) do
  103.         for i = 1, #v.Pos, 1 do
  104.             local blip = AddBlipForCoord(v.Pos[i].x, v.Pos[i].y, v.Pos[i].z)
  105.             SetBlipSprite (blip, 52)
  106.             SetBlipDisplay(blip, 4)
  107.             SetBlipScale  (blip, 1.0)
  108.             SetBlipColour (blip, 2)
  109.             SetBlipAsShortRange(blip, true)
  110.             BeginTextCommandSetBlipName("STRING")
  111.             AddTextComponentString(Config.Zones[i].Name)
  112.             EndTextCommandSetBlipName(blip)
  113.         end
  114.     end
  115. end)
  116.  
  117. -- Display markers
  118. Citizen.CreateThread(function()
  119.     while true do
  120.         Citizen.Wait(0)
  121.         local coords = GetEntityCoords(PlayerPedId())
  122.  
  123.         for k,v in pairs(Config.Zones) do
  124.             for i = 1, #v.Pos, 1 do
  125.                 if(Config.Type ~= -1 and GetDistanceBetweenCoords(coords, v.Pos[i].x, v.Pos[i].y, v.Pos[i].z, true) < Config.DrawDistance) then
  126.                     DrawMarker(Config.Type, v.Pos[i].x, v.Pos[i].y, v.Pos[i].z, 0.0, 0.0, 0.0, 0, 0.0, 0.0, Config.Size.x, Config.Size.y, Config.Size.z, Config.Color.r, Config.Color.g, Config.Color.b, 100, false, true, 2, false, false, false, false)
  127.                 end
  128.             end
  129.         end
  130.     end
  131. end)
  132.  
  133. -- Enter / Exit marker events
  134. Citizen.CreateThread(function()
  135.     while true do
  136.         Citizen.Wait(0)
  137.         local coords      = GetEntityCoords(PlayerPedId())
  138.         local isInMarker  = false
  139.         local currentZone = nil
  140.  
  141.         for k,v in pairs(Config.Zones) do
  142.             for i = 1, #v.Pos, 1 do
  143.                 if(GetDistanceBetweenCoords(coords, v.Pos[i].x, v.Pos[i].y, v.Pos[i].z, true) < Config.Size.x) then
  144.                     isInMarker  = true
  145.                     ShopItems   = v.Items
  146.                     currentZone = k
  147.                     LastZone    = k
  148.                 end
  149.             end
  150.         end
  151.         if isInMarker and not HasAlreadyEnteredMarker then
  152.             HasAlreadyEnteredMarker = true
  153.             TriggerEvent('esx_shops:hasEnteredMarker', currentZone)
  154.         end
  155.         if not isInMarker and HasAlreadyEnteredMarker then
  156.             HasAlreadyEnteredMarker = false
  157.             TriggerEvent('esx_shops:hasExitedMarker', LastZone)
  158.         end
  159.     end
  160. end)
  161.  
  162. -- Key Controls
  163. Citizen.CreateThread(function()
  164.     while true do
  165.         Citizen.Wait(0)
  166.  
  167.         if CurrentAction ~= nil then
  168.             ESX.ShowHelpNotification(CurrentActionMsg)
  169.  
  170.             if IsControlJustReleased(0, Keys['E']) then
  171.                 if CurrentAction == 'shop_menu' then
  172.                     OpenShopMenu(CurrentActionData.zone)
  173.                 end
  174.  
  175.                 CurrentAction = nil
  176.             end
  177.         else
  178.             Citizen.Wait(500)
  179.         end
  180.     end
  181. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement