diff --git a/README.md b/README.md index 49f28d7..a2cd25d 100644 --- a/README.md +++ b/README.md @@ -26,28 +26,6 @@ qb-inventory > html > images -# Add to qb-core > client > functions.lua -``` -QBCore.Functions.SpawnLocalObject = function(model, coords, cb) - - local model = (type(model) == 'number' and model or GetHashKey(model)) - - Citizen.CreateThread(function() - RequestModel(model) - local obj = CreateObject(model, coords.x, coords.y, coords.z, false, false, true) - SetModelAsNoLongerNeeded(model) - - if cb then - cb(obj) - end - end) -end - -QBCore.Functions.DeleteObject = function(object) - SetEntityAsMissionEntity(object, false, true) - DeleteObject(object) -end -``` # Add to qb-target ``` diff --git a/client/chemicals.lua b/client/chemicals.lua index 13ad9ed..5e3981f 100644 --- a/client/chemicals.lua +++ b/client/chemicals.lua @@ -19,7 +19,8 @@ end) AddEventHandler('onResourceStop', function(resource) if resource == GetCurrentResourceName() then for k, v in pairs(Chemicals) do - QBCore.Functions.DeleteObject(v) + SetEntityAsMissionEntity(v, false, true) + DeleteObject(v) end end end) @@ -309,7 +310,8 @@ AddEventHandler("qb-drugtrafficking:chemicals", function() disableCombat = true, }, {}, {}, {}, function() -- Done ClearPedTasks(PlayerPedId()) - QBCore.Functions.DeleteObject(nearbyObject) + SetEntityAsMissionEntity(nearbyObject, false, true) + DeleteObject(nearbyObject) table.remove(Chemicals, nearbyID) SpawnedChemicals = SpawnedChemicals - 1 @@ -330,14 +332,15 @@ function SpawnChemicals() while SpawnedChemicals < 10 do Citizen.Wait(0) local chemicalsCoords = GeneratechemicalsCoords() - - QBCore.Functions.SpawnLocalObject('mw_chemical_barrel', chemicalsCoords, function(obj) - PlaceObjectOnGroundProperly(obj) - FreezeEntityPosition(obj, true) - - table.insert(Chemicals, obj) - SpawnedChemicals = SpawnedChemicals + 1 - end) + RequestModel(`mw_chemical_barrel`) + while not HasModelLoaded(`mw_chemical_barrel`) do + Wait(100) + end + local obj = CreateObject(`mw_chemical_barrel`, chemicalsCoords.x, chemicalsCoords.y, chemicalsCoords.z, true, true, false) + PlaceObjectOnGroundProperly(obj) + FreezeEntityPosition(obj, true) + table.insert(Chemicals, obj) + SpawnedChemicals = SpawnedChemicals + 1 end end diff --git a/client/coke.lua b/client/coke.lua index b26b2f5..d1a53cb 100644 --- a/client/coke.lua +++ b/client/coke.lua @@ -109,7 +109,8 @@ Citizen.CreateThread(function() disableCombat = true, }, {}, {}, {}, function() -- Done ClearPedTasks(PlayerPedId()) - QBCore.Functions.DeleteObject(nearbyObject) + SetEntityAsMissionEntity(nearbyObject, false, true) + DeleteObject(nearbyObject) table.remove(CocaPlants, nearbyID) spawnedCocaLeaf = spawnedCocaLeaf - 1 @@ -131,7 +132,8 @@ end) AddEventHandler('onResourceStop', function(resource) if resource == GetCurrentResourceName() then for k, v in pairs(CocaPlants) do - QBCore.Functions.DeleteObject(v) + SetEntityAsMissionEntity(v, false, true) + DeleteObject(v) end end end) @@ -140,14 +142,15 @@ function SpawnCocaPlants() while spawnedCocaLeaf < 15 do Citizen.Wait(0) local weedCoords = GenerateCocaLeafCoords() - - QBCore.Functions.SpawnLocalObject('mw_coke_plant', weedCoords, function(obj) - PlaceObjectOnGroundProperly(obj) - FreezeEntityPosition(obj, true) - - table.insert(CocaPlants, obj) - spawnedCocaLeaf = spawnedCocaLeaf + 1 - end) + RequestModel(`mw_coke_plant`) + while not HasModelLoaded(`mw_coke_plant`) do + Wait(100) + end + local obj = CreateObject(`mw_coke_plant`, weedCoords.x, weedCoords.y, weedCoords.z, true, true, false) + PlaceObjectOnGroundProperly(obj) + FreezeEntityPosition(obj, true) + table.insert(CocaPlants, obj) + spawnedCocaLeaf = spawnedCocaLeaf + 1 end end diff --git a/client/heroin.lua b/client/heroin.lua index 4706c97..bf5e540 100644 --- a/client/heroin.lua +++ b/client/heroin.lua @@ -110,7 +110,8 @@ Citizen.CreateThread(function() disableCombat = true, }, {}, {}, {}, function() -- Done ClearPedTasks(PlayerPedId()) - QBCore.Functions.DeleteObject(nearbyObject) + SetEntityAsMissionEntity(nearbyObject, false, true) + DeleteObject(nearbyObject) table.remove(PoppyPlants, nearbyID) spawnedPoppys = spawnedPoppys - 1 @@ -132,7 +133,8 @@ end) AddEventHandler('onResourceStop', function(resource) if resource == GetCurrentResourceName() then for k, v in pairs(PoppyPlants) do - QBCore.Functions.DeleteObject(v) + SetEntityAsMissionEntity(v, false, true) + DeleteObject(v) end end end) @@ -141,14 +143,15 @@ function SpawnPoppyPlants() while spawnedPoppys < 15 do Citizen.Wait(0) local heroinCoords = GenerateHeroinCoords() - - QBCore.Functions.SpawnLocalObject('mw_heroin_plant', heroinCoords, function(obj) - PlaceObjectOnGroundProperly(obj) - FreezeEntityPosition(obj, true) - - table.insert(PoppyPlants, obj) - spawnedPoppys = spawnedPoppys + 1 - end) + RequestModel(`mw_heroin_plant`) + while not HasModelLoaded(`mw_heroin_plant`) do + Wait(100) + end + local obj = CreateObject(`mw_heroin_plant`, heroinCoords.x, heroinCoords.y, heroinCoords.z, true, true, false) + PlaceObjectOnGroundProperly(obj) + FreezeEntityPosition(obj, true) + table.insert(PoppyPlants, obj) + spawnedPoppys = spawnedPoppys + 1 end end diff --git a/client/hydrochloricacid.lua b/client/hydrochloricacid.lua index 2b6e039..597a003 100644 --- a/client/hydrochloricacid.lua +++ b/client/hydrochloricacid.lua @@ -42,7 +42,8 @@ AddEventHandler("qb-drugtrafficking:client:hydrochloricacid", function() disableCombat = true, }, {}, {}, {}, function() ClearPedTasks(PlayerPedId()) - QBCore.Functions.DeleteObject(nearbyObject) + SetEntityAsMissionEntity(nearbyObject, false, true) + DeleteObject(nearbyObject) table.remove(HydrochloricAcidBarrels, nearbyID) spawnedHydrochloricAcidBarrels = spawnedHydrochloricAcidBarrels - 1 @@ -62,7 +63,8 @@ end) AddEventHandler('onResourceStop', function(resource) if resource == GetCurrentResourceName() then for k, v in pairs(HydrochloricAcidBarrels) do - QBCore.Functions.DeleteObject(v) + SetEntityAsMissionEntity(v, false, true) + DeleteObject(v) end end end) @@ -71,14 +73,15 @@ function SpawnHydrochloricAcidBarrels() while spawnedHydrochloricAcidBarrels < 5 do Citizen.Wait(0) local weedCoords = GenerateHydrochloricAcidCoords() - - QBCore.Functions.SpawnLocalObject('mw_hydro_barrel', weedCoords, function(obj) - PlaceObjectOnGroundProperly(obj) - FreezeEntityPosition(obj, true) - - table.insert(HydrochloricAcidBarrels, obj) - spawnedHydrochloricAcidBarrels = spawnedHydrochloricAcidBarrels + 1 - end) + RequestModel(`mw_hydro_barrel`) + while not HasModelLoaded(`mw_hydro_barrel`) do + Wait(100) + end + local obj = CreateObject(`mw_hydro_barrel`, weedCoords.x, weedCoords.y, weedCoords.z, true, true, false) + PlaceObjectOnGroundProperly(obj) + FreezeEntityPosition(obj, true) + table.insert(HydrochloricAcidBarrels, obj) + spawnedHydrochloricAcidBarrels = spawnedHydrochloricAcidBarrels + 1 end end diff --git a/client/sodiumhydroxide.lua b/client/sodiumhydroxide.lua index 97aebc9..a85fe4c 100644 --- a/client/sodiumhydroxide.lua +++ b/client/sodiumhydroxide.lua @@ -42,7 +42,8 @@ AddEventHandler("qb-drugtrafficking:client:sodium", function() disableCombat = true, }, {}, {}, {}, function() ClearPedTasks(PlayerPedId()) - QBCore.Functions.DeleteObject(nearbyObject3) + SetEntityAsMissionEntity(nearbyObject3, false, true) + DeleteObject(nearbyObject3) table.remove(SodiumHydroxideBarrels, nearbyID3) spawnedSodiumHydroxideBarrels = spawnedSodiumHydroxideBarrels - 1 @@ -63,7 +64,8 @@ end) AddEventHandler('onResourceStop', function(resource) if resource == GetCurrentResourceName() then for k, v in pairs(SodiumHydroxideBarrels) do - QBCore.Functions.DeleteObject(v) + SetEntityAsMissionEntity(v, false, true) + DeleteObject(v) end end end) @@ -72,14 +74,15 @@ function SpawnSodiumHydroxideBarrels() while spawnedSodiumHydroxideBarrels < 10 do Citizen.Wait(0) local weedCoords2 = GenerateSodiumHydroxideCoords() - - QBCore.Functions.SpawnLocalObject('mw_sodium_barrel', weedCoords2, function(obj) - PlaceObjectOnGroundProperly(obj) - FreezeEntityPosition(obj, true) - - table.insert(SodiumHydroxideBarrels, obj) - spawnedSodiumHydroxideBarrels = spawnedSodiumHydroxideBarrels + 1 - end) + RequestModel(`mw_sodium_barrel`) + while not HasModelLoaded(`mw_sodium_barrel`) do + Wait(100) + end + local obj = CreateObject(`mw_sodium_barrel`, weedCoords2.x, weedCoords2.y, weedCoords2.z, true, true, false) + PlaceObjectOnGroundProperly(obj) + FreezeEntityPosition(obj, true) + table.insert(SodiumHydroxideBarrels, obj) + spawnedSodiumHydroxideBarrels = spawnedSodiumHydroxideBarrels + 1 end end diff --git a/client/sulfuricacid.lua b/client/sulfuricacid.lua index 8b5732f..6b93e5f 100644 --- a/client/sulfuricacid.lua +++ b/client/sulfuricacid.lua @@ -42,7 +42,8 @@ AddEventHandler("qb-drugtrafficking:client:sulfuric", function() disableCombat = true, }, {}, {}, {}, function() -- Done ClearPedTasks(PlayerPedId()) - QBCore.Functions.DeleteObject(nearbyObject) + SetEntityAsMissionEntity(nearbyObject, false, true) + DeleteObject(nearbyObject) table.remove(SulfuricAcidBarrels, nearbyID) spawnedSulfuricAcidBarrels = spawnedSulfuricAcidBarrels - 1 @@ -63,7 +64,8 @@ end) AddEventHandler('onResourceStop', function(resource) if resource == GetCurrentResourceName() then for k, v in pairs(SulfuricAcidBarrels) do - QBCore.Functions.DeleteObject(v) + SetEntityAsMissionEntity(v, false, true) + DeleteObject(v) end end end) @@ -72,14 +74,15 @@ function SpawnSulfuricAcidBarrels() while spawnedSulfuricAcidBarrels < 10 do Citizen.Wait(0) local weedCoords = GenerateSulfuricAcidCoords() - - QBCore.Functions.SpawnLocalObject('mw_sulfuric_barrel', weedCoords, function(obj) - PlaceObjectOnGroundProperly(obj) - FreezeEntityPosition(obj, true) - - table.insert(SulfuricAcidBarrels, obj) - spawnedSulfuricAcidBarrels = spawnedSulfuricAcidBarrels + 1 - end) + RequestModel(`mw_sulfuric_barrel`) + while not HasModelLoaded(`mw_sulfuric_barrel`) do + Wait(100) + end + local obj = CreateObject(`mw_sulfuric_barrel`, weedCoords.x, weedCoords.y, weedCoords.z, true, true, false) + PlaceObjectOnGroundProperly(obj) + FreezeEntityPosition(obj, true) + table.insert(SulfuricAcidBarrels, obj) + spawnedSulfuricAcidBarrels = spawnedSulfuricAcidBarrels + 1 end end diff --git a/client/weed.lua b/client/weed.lua index 38f4b19..fa0ed3e 100644 --- a/client/weed.lua +++ b/client/weed.lua @@ -109,7 +109,8 @@ Citizen.CreateThread(function() disableCombat = true, }, {}, {}, {}, function() -- Done ClearPedTasks(PlayerPedId()) - QBCore.Functions.DeleteObject(nearbyObject) + SetEntityAsMissionEntity(nearbyObject, false, true) + DeleteObject(nearbyObject) table.remove(weedPlants, nearbyID) spawnedWeeds = spawnedWeeds - 1 @@ -131,7 +132,8 @@ end) AddEventHandler('onResourceStop', function(resource) if resource == GetCurrentResourceName() then for k, v in pairs(weedPlants) do - QBCore.Functions.DeleteObject(v) + SetEntityAsMissionEntity(v, false, true) + DeleteObject(v) end end end) @@ -140,14 +142,15 @@ function SpawnWeedPlants() while spawnedWeeds < 15 do Citizen.Wait(0) local weedCoords = GenerateWeedCoords() - - QBCore.Functions.SpawnLocalObject('mw_weed_plant', weedCoords, function(obj) - PlaceObjectOnGroundProperly(obj) - FreezeEntityPosition(obj, true) - - table.insert(weedPlants, obj) - spawnedWeeds = spawnedWeeds + 1 - end) + RequestModel(`mw_weed_plant`) + while not HasModelLoaded(`mw_weed_plant`) do + Wait(100) + end + local obj = CreateObject(`mw_weed_plant`, weedCoords.x, weedCoords.y, weedCoords.z, true, true, false) + PlaceObjectOnGroundProperly(obj) + FreezeEntityPosition(obj, true) + table.insert(weedPlants, obj) + spawnedWeeds = spawnedWeeds + 1 end end