Advertisement
Guest User

Untitled

a guest
Apr 19th, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.16 KB | None | 0 0
  1. ESX = nil
  2. local playersProcessingCannabis = {}
  3. local playersProcessingCocaPlant = {}
  4.  
  5. TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)
  6.  
  7. RegisterServerEvent('esx_drugs:sellDrug')
  8. AddEventHandler('esx_drugs:sellDrug', function(itemName, amount)
  9. local xPlayer = ESX.GetPlayerFromId(source)
  10. local price = Config.DrugDealerItems[itemName]
  11. local xItem = xPlayer.getInventoryItem(itemName)
  12.  
  13. if not price then
  14. print(('esx_drugs: %s attempted to sell an invalid drug!'):format(xPlayer.identifier))
  15. return
  16. end
  17.  
  18. if xItem.count < amount then
  19. TriggerClientEvent('esx:showNotification', source, _U('dealer_notenough'))
  20. return
  21. end
  22.  
  23. price = ESX.Math.Round(price * amount)
  24.  
  25. if Config.GiveBlack then
  26. xPlayer.addAccountMoney('black_money', price)
  27. else
  28. xPlayer.addMoney(price)
  29. end
  30.  
  31. xPlayer.removeInventoryItem(xItem.name, amount)
  32.  
  33. TriggerClientEvent('esx:showNotification', source, _U('dealer_sold', amount, xItem.label, ESX.Math.GroupDigits(price)))
  34. end)
  35.  
  36. ESX.RegisterServerCallback('esx_drugs:buyLicense', function(source, cb, licenseName)
  37. local xPlayer = ESX.GetPlayerFromId(source)
  38. local license = Config.LicensePrices[licenseName]
  39.  
  40. if license == nil then
  41. print(('esx_drugs: %s attempted to buy an invalid license!'):format(xPlayer.identifier))
  42. cb(false)
  43. end
  44.  
  45. if xPlayer.getMoney() >= license.price then
  46. xPlayer.removeMoney(license.price)
  47.  
  48. TriggerEvent('esx_license:addLicense', source, licenseName, function()
  49. cb(true)
  50. end)
  51. else
  52. cb(false)
  53. end
  54. end)
  55.  
  56. RegisterServerEvent('esx_drugs:pickedUpCannabis')
  57. AddEventHandler('esx_drugs:pickedUpCannabis', function()
  58. local xPlayer = ESX.GetPlayerFromId(source)
  59. local xItem = xPlayer.getInventoryItem('cannabis')
  60.  
  61. if xItem.limit ~= -1 and (xItem.count + 1) > xItem.limit then
  62. TriggerClientEvent('esx:showNotification', _source, _U('weed_inventoryfull'))
  63. else
  64. xPlayer.addInventoryItem(xItem.name, 1)
  65. end
  66. end)
  67.  
  68. RegisterServerEvent('esx_drugs:pickedUpCocaPlant')
  69. AddEventHandler('esx_drugs:pickedUpCocaPlant', function()
  70. local xPlayer = ESX.GetPlayerFromId(source)
  71. local xItem = xPlayer.getInventoryItem('cocaplant')
  72.  
  73. if xItem.limit ~= -1 and (xItem.count + 1) > xItem.limit then
  74. TriggerClientEvent('esx:showNotification', _source, _U('coke_inventoryfull'))
  75. else
  76. xPlayer.addInventoryItem(xItem.name, 1)
  77. end
  78. end)
  79.  
  80. RegisterServerEvent('esx_drugs:pickedUpMeth')
  81. AddEventHandler('esx_drugs:pickedUpMeth', function()
  82. local xPlayer = ESX.GetPlayerFromId(source)
  83. local xItem = xPlayer.getInventoryItem('ephedra')
  84.  
  85. if xItem.limit ~= -1 and (xItem.count + 1) > xItem.limit then
  86. TriggerClientEvent('esx:showNotification', _source, _U('meth_inventoryfull'))
  87. else
  88. xPlayer.addInventoryItem(xItem.name, 1)
  89. end
  90. end)
  91.  
  92. ESX.RegisterServerCallback('esx_drugs:canPickUp', function(source, cb, item)
  93. local xPlayer = ESX.GetPlayerFromId(source)
  94. local xItem = xPlayer.getInventoryItem(item)
  95.  
  96. if xItem.limit ~= -1 and xItem.count >= xItem.limit then
  97. cb(false)
  98. else
  99. cb(true)
  100. end
  101. end)
  102.  
  103. RegisterServerEvent('esx_drugs:processCannabis')
  104. AddEventHandler('esx_drugs:processCannabis', function()
  105. if not playersProcessingCannabis[source] then
  106. local _source = source
  107.  
  108. playersProcessingCannabis[_source] = ESX.SetTimeout(Config.Delays.WeedProcessing, function()
  109. local xPlayer = ESX.GetPlayerFromId(_source)
  110. local xCannabis, xMarijuana = xPlayer.getInventoryItem('cannabis'), xPlayer.getInventoryItem('marijuana')
  111.  
  112. if xMarijuana.limit ~= -1 and (xMarijuana.count + 1) >= xMarijuana.limit then
  113. TriggerClientEvent('esx:showNotification', _source, _U('weed_processingfull'))
  114. elseif xCannabis.count < 3 then
  115. TriggerClientEvent('esx:showNotification', _source, _U('weed_processingenough'))
  116. else
  117. xPlayer.removeInventoryItem('cannabis', 3)
  118. xPlayer.addInventoryItem('marijuana', 1)
  119.  
  120. TriggerClientEvent('esx:showNotification', _source, _U('weed_processed'))
  121. end
  122.  
  123. playersProcessingCannabis[_source] = nil
  124. end)
  125. else
  126. print(('esx_drugs: %s attempted to exploit weed processing!'):format(GetPlayerIdentifiers(source)[1]))
  127. end
  128. end)
  129.  
  130. RegisterServerEvent('esx_drugs:processCocaPlant')
  131. AddEventHandler('esx_drugs:processCocaPlant', function()
  132. if not playersProcessingCocaPlant[source] then
  133. local _source = source
  134.  
  135. playersProcessingCocaPlant[_source] = ESX.SetTimeout(Config.Delays.CokeProcessing, function()
  136. local xPlayer = ESX.GetPlayerFromId(_source)
  137. local xCocaPlant, xCocaine = xPlayer.getInventoryItem('cocaplant'), xPlayer.getInventoryItem('cocaine')
  138.  
  139. if xCocaine.limit ~= -1 and (xCocaine.count + 1) >= xCocaine.limit then
  140. TriggerClientEvent('esx:showNotification', _source, _U('coke_processingfull'))
  141. elseif xCocaPlant.count < 3 then
  142. TriggerClientEvent('esx:showNotification', _source, _U('coke_processingenough'))
  143. else
  144. xPlayer.removeInventoryItem('cocaplant', 3)
  145. xPlayer.addInventoryItem('cocaine', 1)
  146.  
  147. TriggerClientEvent('esx:showNotification', _source, _U('coke_processed'))
  148. end
  149.  
  150. playersProcessingCocaPlant[_source] = nil
  151. end)
  152. else
  153. print(('esx_drugs: %s attempted to exploit coke processing!'):format(GetPlayerIdentifiers(source)[1]))
  154. end
  155. end)
  156.  
  157. RegisterServerEvent('esx_drugs:processMeth')
  158. AddEventHandler('esx_drugs:processMeth', function()
  159. if not playersProcessingCocaPlant[source] then
  160. local _source = source
  161.  
  162. playersProcessingMeth[_source] = ESX.SetTimeout(Config.Delays.MethProcessing, function()
  163. local xPlayer = ESX.GetPlayerFromId(_source)
  164. local xMeth, xMethCrystal = xPlayer.getInventoryItem('ephedra'), xPlayer.getInventoryItem('crystal_meth')
  165.  
  166. if xMethCrystal.limit ~= -1 and (xMethCrystal.count + 1) >= xMethCrystal.limit then
  167. TriggerClientEvent('esx:showNotification', _source, _U('meth_processingfull'))
  168. elseif xMeth.count < 3 then
  169. TriggerClientEvent('esx:showNotification', _source, _U('meth_processingenough'))
  170. else
  171. xPlayer.removeInventoryItem('ephedra', 3)
  172. xPlayer.addInventoryItem('crystal_meth', 1)
  173.  
  174. TriggerClientEvent('esx:showNotification', _source, _U('meth_processed'))
  175. end
  176.  
  177. playersProcessingMeth[_source] = nil
  178. end)
  179. else
  180. print(('esx_drugs: %s attempted to exploit coke processing!'):format(GetPlayerIdentifiers(source)[1]))
  181. end
  182. end)
  183.  
  184.  
  185. function CancelProcessing(playerID)
  186. if playersProcessingCannabis[playerID] then
  187. ESX.ClearTimeout(playersProcessingCannabis[playerID])
  188. playersProcessingCannabis[playerID] = nil
  189. end
  190. end
  191.  
  192. function CancelProcessing(playerID)
  193. if playersProcessingCocaPlant[playerID] then
  194. ESX.ClearTimeout(playersProcessingCocaPlant[playerID])
  195. playersProcessingCocaPlant[playerID] = nil
  196. end
  197. end
  198.  
  199. function CancelProcessing(playerID)
  200. if playersProcessingMeth[playerID] then
  201. ESX.ClearTimeout(playersProcessingMeth[playerID])
  202. playersProcessingMeth[playerID] = nil
  203. end
  204. end
  205.  
  206. RegisterServerEvent('esx_drugs:cancelProcessing')
  207. AddEventHandler('esx_drugs:cancelProcessing', function()
  208. CancelProcessing(source)
  209. end)
  210.  
  211. AddEventHandler('esx:playerDropped', function(playerID, reason)
  212. CancelProcessing(playerID)
  213. end)
  214.  
  215. RegisterServerEvent('esx:onPlayerDeath')
  216. AddEventHandler('esx:onPlayerDeath', function(data)
  217. CancelProcessing(source)
  218. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement