Advertisement
Guest User

weed

a guest
Dec 19th, 2018
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.01 KB | None | 0 0
  1. local spawnedWeeds = 0
  2. local weedPlants = {}
  3. local isPickingUp, isProcessing = false, false
  4.  
  5.  
  6. Citizen.CreateThread(function()
  7. while true do
  8. Citizen.Wait(10)
  9. local coords = GetEntityCoords(PlayerPedId())
  10.  
  11. if GetDistanceBetweenCoords(coords, Config.CircleZones.WeedField.coords, true) < 50 then
  12. SpawnWeedPlants()
  13. Citizen.Wait(500)
  14. else
  15. Citizen.Wait(500)
  16. end
  17. end
  18. end)
  19.  
  20. Citizen.CreateThread(function()
  21. while true do
  22. Citizen.Wait(10)
  23. local playerPed = PlayerPedId()
  24. local coords = GetEntityCoords(playerPed)
  25.  
  26. if GetDistanceBetweenCoords(coords, Config.CircleZones.WeedProcessing.coords, true) < 1 then
  27. if not isProcessing then
  28. ESX.ShowHelpNotification(_U('weed_processprompt'))
  29. end
  30.  
  31. if IsControlJustReleased(0, Keys['E']) and not isProcessing then
  32.  
  33. if Config.LicenseEnable then
  34. ESX.TriggerServerCallback('esx_license:checkLicense', function(hasProcessingLicense)
  35. if hasProcessingLicense then
  36. ProcessWeed()
  37. else
  38. OpenBuyLicenseMenu('weed_processing')
  39. end
  40. end, GetPlayerServerId(PlayerId()), 'weed_processing')
  41. else
  42. ProcessWeed()
  43. end
  44.  
  45. end
  46. else
  47. Citizen.Wait(500)
  48. end
  49. end
  50. end)
  51.  
  52. function ProcessWeed()
  53. isProcessing = true
  54.  
  55. ESX.ShowNotification(_U('weed_processingstarted'))
  56. TriggerServerEvent('esx_drugs:processCannabis')
  57. local timeLeft = Config.Delays.WeedProcessing / 1000
  58. local playerPed = PlayerPedId()
  59.  
  60. while timeLeft > 0 do
  61. Citizen.Wait(1000)
  62. timeLeft = timeLeft - 1
  63.  
  64. if GetDistanceBetweenCoords(GetEntityCoords(playerPed), Config.CircleZones.WeedProcessing.coords, false) > 4 then
  65. ESX.ShowNotification(_U('weed_processingtoofar'))
  66. TriggerServerEvent('esx_drugs:cancelProcessing')
  67. break
  68. end
  69. end
  70.  
  71. isProcessing = false
  72. end
  73.  
  74. Citizen.CreateThread(function()
  75. while true do
  76. Citizen.Wait(10)
  77. local playerPed = PlayerPedId()
  78. local coords = GetEntityCoords(playerPed)
  79. local nearbyObject, nearbyID = nil, nil
  80.  
  81. for i=1, #weedPlants, 1 do
  82. if GetDistanceBetweenCoords(coords, GetEntityCoords(weedPlants[i]), false) < 1 then
  83. nearbyObject, nearbyID = weedPlants[i], i
  84. end
  85. end
  86.  
  87. if nearbyObject and IsPedOnFoot(playerPed) then
  88.  
  89. if not isPickingUp then
  90. ESX.ShowHelpNotification(_U('weed_pickupprompt'))
  91. end
  92.  
  93. if IsControlJustReleased(0, Keys['E']) and not isPickingUp then
  94. isPickingUp = true
  95.  
  96. ESX.TriggerServerCallback('esx_drugs:canPickUp', function(canPickUp)
  97.  
  98. if canPickUp then
  99. TaskStartScenarioInPlace(playerPed, 'world_human_gardener_plant', 0, false)
  100.  
  101. Citizen.Wait(2000)
  102. ClearPedTasks(playerPed)
  103. Citizen.Wait(1500)
  104.  
  105. ESX.Game.DeleteObject(nearbyObject)
  106.  
  107. table.remove(weedPlants, nearbyID)
  108. spawnedWeeds = spawnedWeeds - 1
  109.  
  110. TriggerServerEvent('esx_drugs:pickedUpCannabis')
  111. else
  112. ESX.ShowNotification(_U('weed_inventoryfull'))
  113. end
  114.  
  115. isPickingUp = false
  116.  
  117. end, 'cannabis')
  118. end
  119.  
  120. end
  121.  
  122. end
  123.  
  124. end)
  125.  
  126. AddEventHandler('onResourceStop', function(resource)
  127. if resource == GetCurrentResourceName() then
  128. for k, v in pairs(weedPlants) do
  129. ESX.Game.DeleteObject(v)
  130. end
  131. end
  132. end)
  133.  
  134. function SpawnWeedPlants()
  135. while spawnedWeeds < 25 do
  136. Citizen.Wait(0)
  137. local weedCoords = GenerateWeedCoords()
  138.  
  139. ESX.Game.SpawnLocalObject('prop_weed_02', weedCoords, function(obj)
  140. PlaceObjectOnGroundProperly(obj)
  141. FreezeEntityPosition(obj, true)
  142.  
  143. table.insert(weedPlants, obj)
  144. spawnedWeeds = spawnedWeeds + 1
  145. end)
  146. end
  147. end
  148.  
  149. function ValidateWeedCoord(plantCoord)
  150. if spawnedWeeds > 0 then
  151. local validate = true
  152.  
  153. for k, v in pairs(weedPlants) do
  154. if GetDistanceBetweenCoords(plantCoord, GetEntityCoords(v), true) < 5 then
  155. validate = false
  156. end
  157. end
  158.  
  159. if GetDistanceBetweenCoords(plantCoord, Config.CircleZones.WeedField.coords, false) > 50 then
  160. validate = false
  161. end
  162.  
  163. return validate
  164. else
  165. return true
  166. end
  167. end
  168.  
  169. function GenerateWeedCoords()
  170. while true do
  171. Citizen.Wait(1)
  172.  
  173. local weedCoordX, weedCoordY
  174.  
  175. math.randomseed(GetGameTimer())
  176. local modX = math.random(-90, 90)
  177.  
  178. Citizen.Wait(100)
  179.  
  180. math.randomseed(GetGameTimer())
  181. local modY = math.random(-90, 90)
  182.  
  183. if modX > 0 then
  184. weedCoordX = Config.CircleZones.WeedField.coords.x + modX
  185. else
  186. weedCoordX = Config.CircleZones.WeedField.coords.x - modX
  187. end
  188.  
  189. if modY > 0 then
  190. weedCoordY = Config.CircleZones.WeedField.coords.y + modY
  191. else
  192. weedCoordY = Config.CircleZones.WeedField.coords.y - modY
  193. end
  194.  
  195. local coordZ = GetCoordZ(weedCoordX, weedCoordY)
  196. local coord = vector3(weedCoordX, weedCoordY, coordZ)
  197.  
  198. if ValidateWeedCoord(coord) then
  199. return coord
  200. end
  201. end
  202. end
  203.  
  204. function GetCoordZ(x, y)
  205. local groundCheckHeights = { 40.0, 41.0, 42.0, 43.0, 44.0, 45.0, 46.0, 47.0, 48.0, 49.0, 50.0 }
  206.  
  207. for i, height in ipairs(groundCheckHeights) do
  208. local foundGround, z = GetGroundZFor_3dCoord(x, y, height)
  209.  
  210. if foundGround then
  211. return z
  212. end
  213. end
  214.  
  215. return 43.0
  216. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement