Jordang1690

Untitled

Jul 5th, 2025
6
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.30 KB | None | 0 0
  1. local QBCore = exports['qb-core']:GetCoreObject()
  2. local LocalPotData = {}
  3. local PlantEntities = {}
  4. local PotEntitiesById = {}
  5. local TargetedPots = {}
  6. local PendingPotSync = {}
  7.  
  8. local PlantModels = {
  9. [2] = "prop_weed_02",
  10. [3] = "prop_weed_01"
  11. }
  12.  
  13. local SlotOffsets = {
  14. [1] = { vector3(0.0, 0.0, 0.0) },
  15. [2] = { vector3(-0.2, -0.2, 0.0), vector3(0.2, 0.2, 0.0) },
  16. [3] = { vector3(-0.3, -0.2, 0.0), vector3(0.0, 0.3, 0.0), vector3(0.3, -0.2, 0.0) }
  17. }
  18.  
  19. RegisterNetEvent('weed:updatePotData', function(potId, potData)
  20. print("[DEBUG] updatePotData received:", potId)
  21. LocalPotData[potId] = potData
  22.  
  23. if PlantEntities[potId] then
  24. for _, ent in pairs(PlantEntities[potId]) do
  25. if DoesEntityExist(ent) then DeleteEntity(ent) end
  26. end
  27. end
  28. PlantEntities[potId] = {}
  29.  
  30. if not potData then return end
  31.  
  32. local pot = PotEntitiesById[potId]
  33. if not pot or not DoesEntityExist(pot) then
  34. PendingPotSync[potId] = potData
  35. return
  36. end
  37.  
  38. local slots = Config.PotTypes[potData.type].slots
  39. for i = 1, slots do
  40. local seed = potData.seeds[i]
  41. if seed then
  42. local offset = SlotOffsets[slots][i] or vector3(0.0, 0.0, 0.0)
  43. local base = GetEntityCoords(pot)
  44. local pos = base + offset
  45.  
  46. if PlantModels[seed.stage] then
  47. local model = GetHashKey(PlantModels[seed.stage])
  48. RequestModel(model) while not HasModelLoaded(model) do Wait(0) end
  49. local obj = CreateObject(model, pos, false, true, false)
  50. SetEntityHeading(obj, GetEntityHeading(pot))
  51. FreezeEntityPosition(obj, true)
  52. SetEntityAlpha(obj, 220, false)
  53. PlantEntities[potId][i] = obj
  54. elseif seed.stage == 1 then
  55. UseParticleFxAssetNextCall("core")
  56. StartParticleFxNonLoopedAtCoord("ent_anim_dusty_hands", pos.x, pos.y, pos.z + 0.1, 0.0, 0.0, 0.0, 0.7, false, false, false)
  57. end
  58. end
  59. end
  60.  
  61. -- 📦 Attach interaction via box zone
  62. if not TargetedPots[potId] then
  63. local coords = GetEntityCoords(pot)
  64. local heading = GetEntityHeading(pot)
  65.  
  66. exports['qb-target']:AddBoxZone("pot_" .. potId, coords, 1.2, 1.2, {
  67. name = "pot_" .. potId,
  68. heading = heading,
  69. debugPoly = false,
  70. minZ = coords.z - 0.5,
  71. maxZ = coords.z + 1.2
  72. }, {
  73. options = {
  74. {
  75. label = "🌱 Plant Seed",
  76. icon = "fas fa-seedling",
  77. item = "weed_seed",
  78. canInteract = function()
  79. local pot = LocalPotData[potId]
  80. if not pot or type(pot.seeds) ~= "table" then return false end
  81. for i = 1, Config.PotTypes[pot.type].slots do
  82. local seed = pot.seeds[i]
  83. if not seed or seed.stage == nil then return true end
  84. end
  85. return false
  86. end,
  87. action = function()
  88. print("[DEBUG] Plant Seed action triggered for:", potId)
  89. TriggerServerEvent('weed:insertSeed', potId)
  90. end
  91. },
  92. {
  93. label = "💧 Water Plant",
  94. icon = "fas fa-tint",
  95. item = "watering_can",
  96. canInteract = function()
  97. local pot = LocalPotData[potId]
  98. if not pot or type(pot.seeds) ~= "table" then return false end
  99. for _, seed in pairs(pot.seeds) do
  100. if seed and not seed.watered and (seed.waterCount or 0) < 3 then return true end
  101. end
  102. return false
  103. end,
  104. action = function()
  105. TriggerServerEvent('weed:waterSeed', potId)
  106. end
  107. },
  108. {
  109. label = "🌿 Fertilize",
  110. icon = "fas fa-leaf",
  111. item = "weed_fertilizer",
  112. canInteract = function()
  113. local pot = LocalPotData[potId]
  114. if not pot or type(pot.seeds) ~= "table" then return false end
  115. for _, seed in pairs(pot.seeds) do
  116. if seed and not seed.fertilized then return true end
  117. end
  118. return false
  119. end,
  120. action = function()
  121. TriggerServerEvent('weed:fertilizeSeed', potId)
  122. end
  123. },
  124. {
  125. label = "💬 Check Progress",
  126. icon = "fas fa-leaf",
  127. canInteract = function()
  128. local pot = LocalPotData[potId]
  129. return pot and type(pot.seeds) == "table" and next(pot.seeds) ~= nil
  130. end,
  131. action = function()
  132. ShowPotStatus(potId)
  133. end
  134. },
  135. {
  136. label = "✂️ Harvest Plant",
  137. icon = "fas fa-cut",
  138. canInteract = function()
  139. local pot = LocalPotData[potId]
  140. if not pot or type(pot.seeds) ~= "table" then return false end
  141. for _, seed in pairs(pot.seeds) do
  142. if seed and seed.stage == Config.GrowthStages and (seed.waterCount or 0) >= 3 then return true end
  143. end
  144. return false
  145. end,
  146. action = function()
  147. TriggerServerEvent('weed:harvestPlant', potId)
  148. end
  149. },
  150. {
  151. label = "🗑️ Remove Pot",
  152. icon = "fas fa-trash",
  153. action = function()
  154. DeleteEntity(pot)
  155. TriggerServerEvent('weed:removePot', potId)
  156. end
  157. }
  158. },
  159. distance = 3.5
  160. })
  161.  
  162. TargetedPots[potId] = true
  163. end
  164. end)
  165.  
  166. RegisterNetEvent('weed:placePotFinal', function(potType, coords, heading, potId)
  167. local model = Config.PotTypes[potType].model
  168. local hash = GetHashKey(model)
  169.  
  170. RequestModel(hash)
  171. while not HasModelLoaded(hash) do Wait(0) end
  172.  
  173. local pot = CreateObject(hash, coords.x, coords.y, coords.z + 0.2, true, true, false)
  174. SetEntityHeading(pot, heading)
  175. PlaceObjectOnGroundProperly(pot)
  176. FreezeEntityPosition(pot, true)
  177. print("[DEBUG] Pot entity created:", potId, DoesEntityExist(pot))
  178.  
  179. PotEntitiesById[potId] = pot
  180.  
  181. if PendingPotSync[potId] then
  182. TriggerEvent('weed:updatePotData', potId, PendingPotSync[potId])
  183. PendingPotSync[potId] = nil
  184. end
  185. end)
  186.  
  187. RegisterNetEvent('weed:previewPot', function(potType, itemSlot)
  188. local ped = PlayerPedId()
  189. local model = Config.PotTypes[potType].model
  190. local hash = GetHashKey(model)
  191. RequestModel(hash) while not HasModelLoaded(hash) do Wait(0) end
  192.  
  193. local preview = CreateObject(hash, GetEntityCoords(ped), false, false, false)
  194. SetEntityAlpha(preview, 150, false)
  195. FreezeEntityPosition(preview, true)
  196. SetEntityCollision(preview, false, false)
  197.  
  198. local placing = true
  199. local heading = 0.0
  200.  
  201. CreateThread(function()
  202. while placing do
  203. Wait(0)
  204. local pos = GetOffsetFromEntityInWorldCoords(ped, 0.0, 1.5, -1.0)
  205. SetEntityCoords(preview, pos, false, false, false, false)
  206. heading = heading + (IsControlPressed(0, 108) and 1 or IsControlPressed(0, 109) and -1 or 0)
  207. SetEntityHeading(preview, heading)
  208. DrawText3D(pos.x, pos.y, pos.z + 1.0, "~g~[E]~s~ place | ~r~[X]~s~ cancel")
  209.  
  210. if IsControlJustPressed(0, 38) then
  211. placing = false
  212. DeleteEntity(preview)
  213. TriggerServerEvent('weed:consumePotItem', potType, itemSlot, pos, heading)
  214. elseif IsControlJustPressed(0, 73) then
  215. placing = false
  216. DeleteEntity(preview)
  217. end
  218. end
  219. end)
  220. end)
  221.  
  222. RegisterNetEvent('weed:tryRefillCan', function()
  223. local ped = PlayerPedId()
  224. if IsEntityInWater(ped) then
  225. TriggerServerEvent('weed:refillCan')
  226. else
  227. QBCore.Functions.Notify('Find water to refill the can.', 'error')
  228. end
  229. end)
  230.  
  231. function ShowPotStatus(potId)
  232. local pot = LocalPotData[potId]
  233. if not pot then
  234. QBCore.Functions.Notify("Unknown pot", 'error')
  235. return
  236. end
  237.  
  238. local msg = "🌾 Pot Progress:"
  239. for slot, seed in pairs(pot.seeds) do
  240. if seed then
  241. local stage = seed.stage == 1 and "Seedling"
  242. or seed.stage == 2 and "Growing"
  243. or seed.stage == 3 and "Ready"
  244. or "?"
  245. local water = seed.watered and "💧 Watered (awaiting growth)"
  246. or string.format("💧 %d/3", seed.waterCount or 0)
  247. local fert = seed.fertilized and "🌿 Fertilized" or "No Fertilizer"
  248. msg = msg .. ("\nSlot %d: %s | %s | %s"):format(slot, stage, water, fert)
  249. end
  250. end
  251.  
  252. QBCore.Functions.Notify(msg, 'primary', 8000)
  253. end
  254.  
  255. function DrawText3D(x, y, z, text)
  256. local onScreen, _x, _y = World3dToScreen2d(x, y, z)
  257. local p = GetGameplayCamCoords()
  258. local dist = #(vector3(x, y, z) - p)
  259.  
  260. if dist > 15.0 or not onScreen then return end
  261.  
  262. local scale = (1 / dist) * 1.7
  263. scale = scale * (1 / GetGameplayCamFov()) * 100
  264.  
  265. SetTextScale(0.40, 0.40)
  266. SetTextFont(4)
  267. SetTextProportional(1)
  268. SetTextColour(255, 255, 255, 255)
  269. SetTextCentre(true)
  270. SetTextDropshadow(0, 0, 0, 0, 255)
  271. SetTextOutline()
  272. SetTextEntry("STRING")
  273. AddTextComponentString(text)
  274. DrawText(_x, _y)
  275.  
  276. local factor = (string.len(text)) / 320
  277. DrawRect(_x, _y + 0.015, 0.035 + factor, 0.045, 0, 0, 0, 180)
  278. end
Add Comment
Please, Sign In to add comment