Advertisement
Guest User

Untitled

a guest
Oct 16th, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.67 KB | None | 0 0
  1. ESX = nil
  2. local HasAlreadyEnteredMarker = false
  3. local LastZone = nil
  4. local CurrentAction = nil
  5. local CurrentActionMsg = ''
  6. local CurrentActionData = {}
  7. local isDead = false
  8.  
  9. Citizen.CreateThread(function()
  10. while ESX == nil do
  11. TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)
  12. Citizen.Wait(0)
  13. end
  14. end)
  15.  
  16. function OpenAccessoryMenu()
  17. ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'set_unset_accessory',
  18. {
  19. title = _U('set_unset'),
  20. align = 'top-left',
  21. elements = {
  22. {label = _U('helmet'), value = 'Helmet'},
  23. {label = _U('ears'), value = 'Ears'},
  24. {label = _U('mask'), value = 'Mask'},
  25. {label = _U('glasses'), value = 'Glasses'}
  26. }
  27. }, function(data, menu)
  28. menu.close()
  29. SetUnsetAccessory(data.current.value)
  30.  
  31. end, function(data, menu)
  32. menu.close()
  33. end)
  34. end
  35.  
  36. function SetUnsetAccessory(accessory)
  37. ESX.TriggerServerCallback('esx_accessories:get', function(hasAccessory, accessorySkin)
  38. local _accessory = string.lower(accessory)
  39.  
  40. if hasAccessory then
  41. TriggerEvent('skinchanger:getSkin', function(skin)
  42. local mAccessory = -1
  43. local mColor = 0
  44.  
  45. if _accessory == "mask" then
  46. mAccessory = 0
  47. end
  48.  
  49. if skin[_accessory .. '_1'] == mAccessory then
  50. mAccessory = accessorySkin[_accessory .. '_1']
  51. mColor = accessorySkin[_accessory .. '_2']
  52. end
  53.  
  54. local accessorySkin = {}
  55. accessorySkin[_accessory .. '_1'] = mAccessory
  56. accessorySkin[_accessory .. '_2'] = mColor
  57. TriggerEvent('skinchanger:loadClothes', skin, accessorySkin)
  58. end)
  59. else
  60. ESX.ShowNotification(_U('no_' .. _accessory))
  61. end
  62.  
  63. end, accessory)
  64. end
  65.  
  66. function OpenShopMenu(accessory)
  67. local _accessory = string.lower(accessory)
  68. local restrict = {}
  69.  
  70. restrict = { _accessory .. '_1', _accessory .. '_2' }
  71.  
  72. TriggerEvent('esx_skin:openRestrictedMenu', function(data, menu)
  73.  
  74. menu.close()
  75.  
  76. ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'shop_confirm',
  77. {
  78. title = _U('valid_purchase'),
  79. align = 'top-left',
  80. elements = {
  81. {label = _U('no'), value = 'no'},
  82. {label = _U('yes', ESX.Math.GroupDigits(Config.Price)), value = 'yes'}
  83. }
  84. }, function(data, menu)
  85. menu.close()
  86. if data.current.value == 'yes' then
  87. ESX.TriggerServerCallback('esx_accessories:checkMoney', function(hasEnoughMoney)
  88. if hasEnoughMoney then
  89. TriggerServerEvent('esx_accessories:pay')
  90. TriggerEvent('skinchanger:getSkin', function(skin)
  91. TriggerServerEvent('esx_accessories:save', skin, accessory)
  92. end)
  93. else
  94. TriggerEvent('esx_skin:getLastSkin', function(skin)
  95. TriggerEvent('skinchanger:loadSkin', skin)
  96. end)
  97. ESX.ShowNotification(_U('not_enough_money'))
  98. end
  99. end)
  100. end
  101.  
  102. if data.current.value == 'no' then
  103. local player = PlayerPedId()
  104. TriggerEvent('esx_skin:getLastSkin', function(skin)
  105. TriggerEvent('skinchanger:loadSkin', skin)
  106. end)
  107. if accessory == "Ears" then
  108. ClearPedProp(player, 2)
  109. elseif accessory == "Mask" then
  110. SetPedComponentVariation(player, 1, 0 ,0, 2)
  111. elseif accessory == "Helmet" then
  112. ClearPedProp(player, 0)
  113. elseif accessory == "Glasses" then
  114. SetPedPropIndex(player, 1, -1, 0, 0)
  115. end
  116. end
  117. CurrentAction = 'shop_menu'
  118. CurrentActionMsg = _U('press_access')
  119. CurrentActionData = {}
  120. end, function(data, menu)
  121. menu.close()
  122. CurrentAction = 'shop_menu'
  123. CurrentActionMsg = _U('press_access')
  124. CurrentActionData = {}
  125.  
  126. end)
  127. end, function(data, menu)
  128. menu.close()
  129. CurrentAction = 'shop_menu'
  130. CurrentActionMsg = _U('press_access')
  131. CurrentActionData = {}
  132. end, restrict)
  133. end
  134.  
  135. AddEventHandler('playerSpawned', function()
  136. isDead = false
  137. end)
  138.  
  139. AddEventHandler('esx:onPlayerDeath', function()
  140. isDead = true
  141. end)
  142.  
  143. AddEventHandler('esx_accessories:hasEnteredMarker', function(zone)
  144. CurrentAction = 'shop_menu'
  145. CurrentActionMsg = _U('press_access')
  146. CurrentActionData = { accessory = zone }
  147. end)
  148.  
  149. AddEventHandler('esx_accessories:hasExitedMarker', function(zone)
  150. ESX.UI.Menu.CloseAll()
  151. CurrentAction = nil
  152. end)
  153.  
  154. -- Create Blips --
  155. Citizen.CreateThread(function()
  156. for k,v in pairs(Config.ShopsBlips) do
  157. if v.Pos ~= nil then
  158. for i=1, #v.Pos, 1 do
  159. local blip = AddBlipForCoord(v.Pos[i].x, v.Pos[i].y, v.Pos[i].z)
  160.  
  161. SetBlipSprite (blip, v.Blip.sprite)
  162. SetBlipDisplay(blip, 4)
  163. SetBlipScale (blip, 1.0)
  164. SetBlipColour (blip, v.Blip.color)
  165. SetBlipAsShortRange(blip, true)
  166.  
  167. BeginTextCommandSetBlipName("STRING")
  168. AddTextComponentString(_U('shop', _U(string.lower(k))))
  169. EndTextCommandSetBlipName(blip)
  170. end
  171. end
  172. end
  173. end)
  174.  
  175. -- Display markers
  176. Citizen.CreateThread(function()
  177. while true do
  178. Citizen.Wait(0)
  179. local coords = GetEntityCoords(PlayerPedId())
  180. for k,v in pairs(Config.Zones) do
  181. for i = 1, #v.Pos, 1 do
  182. if(Config.Type ~= -1 and GetDistanceBetweenCoords(coords, v.Pos[i].x, v.Pos[i].y, v.Pos[i].z, true) < Config.DrawDistance) then
  183. 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)
  184. end
  185. end
  186. end
  187. end
  188. end)
  189.  
  190.  
  191. Citizen.CreateThread(function()
  192. while true do
  193. Citizen.Wait(200)
  194.  
  195. local coords = GetEntityCoords(PlayerPedId())
  196. local isInMarker = false
  197. local currentZone = nil
  198. for k,v in pairs(Config.Zones) do
  199. for i = 1, #v.Pos, 1 do
  200. if GetDistanceBetweenCoords(coords, v.Pos[i].x, v.Pos[i].y, v.Pos[i].z, true) < Config.Size.x then
  201. isInMarker = true
  202. currentZone = k
  203. end
  204. end
  205. end
  206.  
  207. if (isInMarker and not HasAlreadyEnteredMarker) or (isInMarker and LastZone ~= currentZone) then
  208. HasAlreadyEnteredMarker = true
  209. LastZone = currentZone
  210. TriggerEvent('esx_accessories:hasEnteredMarker', currentZone)
  211. end
  212.  
  213. if not isInMarker and HasAlreadyEnteredMarker then
  214. HasAlreadyEnteredMarker = false
  215. TriggerEvent('esx_accessories:hasExitedMarker', LastZone)
  216. end
  217.  
  218. end
  219. end)
  220.  
  221. -- Key controls
  222. Citizen.CreateThread(function()
  223. while true do
  224. Citizen.Wait(0)
  225.  
  226. if CurrentAction ~= nil then
  227. ESX.ShowHelpNotification(CurrentActionMsg)
  228.  
  229. if IsControlJustReleased(0, 38) and CurrentActionData.accessory then
  230. OpenShopMenu(CurrentActionData.accessory)
  231. CurrentAction = nil
  232. end
  233. elseif CurrentAction == nil and not Config.EnableControls then
  234. Citizen.Wait(500)
  235. end
  236.  
  237. if Config.EnableControls then
  238. if IsControlJustReleased(0, 311) and IsInputDisabled(0) and not isDead then
  239. OpenAccessoryMenu()
  240. end
  241. end
  242.  
  243. end
  244. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement