8282local function ValidateCocaLeafCoord (plantCoord )
8383 local validate = true
8484 if spawnedCocaLeaf > 0 then
85- for k , v in pairs (CocaPlants ) do
85+ for _ , v in pairs (CocaPlants ) do
8686 if # (plantCoord - GetEntityCoords (v )) < 5 then
8787 validate = false
8888 end
@@ -135,19 +135,21 @@ local function GenerateCocaLeafCoords()
135135end
136136
137137local function SpawnCocaPlants ()
138+ local model = ` h4_prop_bush_cocaplant_01`
138139 while spawnedCocaLeaf < 15 do
139140 Wait (0 )
140141 local weedCoords = GenerateCocaLeafCoords ()
141- RequestModel (` h4_prop_bush_cocaplant_01 ` )
142- while not HasModelLoaded (` h4_prop_bush_cocaplant_01 ` ) do
142+ RequestModel (model )
143+ while not HasModelLoaded (model ) do
143144 Wait (100 )
144145 end
145- local obj = CreateObject (` h4_prop_bush_cocaplant_01 ` , weedCoords .x , weedCoords .y , weedCoords .z , false , true , false )
146+ local obj = CreateObject (model , weedCoords .x , weedCoords .y , weedCoords .z , false , true , false )
146147 PlaceObjectOnGroundProperly (obj )
147148 FreezeEntityPosition (obj , true )
148- table.insert ( CocaPlants , obj )
149+ CocaPlants [ # CocaPlants + 1 ] = obj
149150 spawnedCocaLeaf += 1
150151 end
152+ SetModelAsNoLongerNeeded (model )
151153end
152154
153155
@@ -303,7 +305,7 @@ RegisterNetEvent('ps-drugprocessing:pickCocaLeaves', function()
303305 local nearbyObject , nearbyID
304306
305307 for i = 1 , # CocaPlants , 1 do
306- if GetDistanceBetweenCoords (coords , GetEntityCoords (CocaPlants [i ]), false ) < 2 then
308+ if # (coords - GetEntityCoords (CocaPlants [i ])) < 2 then
307309 nearbyObject , nearbyID = CocaPlants [i ], i
308310 end
309311 end
@@ -312,7 +314,6 @@ RegisterNetEvent('ps-drugprocessing:pickCocaLeaves', function()
312314 if not isPickingUp then
313315 isPickingUp = true
314316 TaskStartScenarioInPlace (playerPed , ' world_human_gardener_plant' , 0 , false )
315-
316317 QBCore .Functions .Progressbar (" search_register" , Lang :t (" progressbar.collecting" ), 10000 , false , true , {
317318 disableMovement = true ,
318319 disableCarMovement = true ,
@@ -323,7 +324,7 @@ RegisterNetEvent('ps-drugprocessing:pickCocaLeaves', function()
323324 SetEntityAsMissionEntity (nearbyObject , false , true )
324325 DeleteObject (nearbyObject )
325326
326- table.remove ( CocaPlants , nearbyID )
327+ CocaPlants [ nearbyID ] = nil
327328 spawnedCocaLeaf = spawnedCocaLeaf - 1
328329
329330 TriggerServerEvent (' ps-drugprocessing:pickedUpCocaLeaf' )
@@ -339,15 +340,15 @@ end)
339340
340341AddEventHandler (' onResourceStop' , function (resource )
341342 if resource == GetCurrentResourceName () then
342- for k , v in pairs (CocaPlants ) do
343+ for _ , v in pairs (CocaPlants ) do
343344 SetEntityAsMissionEntity (v , false , true )
344345 DeleteObject (v )
345346 end
346347 end
347348end )
348349
349350RegisterCommand (' propfix' , function ()
350- for k , v in pairs (GetGamePool (' CObject' )) do
351+ for _ , v in pairs (GetGamePool (' CObject' )) do
351352 if IsEntityAttachedToEntity (PlayerPedId (), v ) then
352353 SetEntityAsMissionEntity (v , true , true )
353354 DeleteObject (v )
0 commit comments