Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace QBCore.Functions with natives #5

Merged
merged 1 commit into from
Feb 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 0 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

```
Expand Down
23 changes: 13 additions & 10 deletions client/chemicals.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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

Expand Down
23 changes: 13 additions & 10 deletions client/coke.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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

Expand Down
23 changes: 13 additions & 10 deletions client/heroin.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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

Expand Down
23 changes: 13 additions & 10 deletions client/hydrochloricacid.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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

Expand Down
23 changes: 13 additions & 10 deletions client/sodiumhydroxide.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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

Expand Down
23 changes: 13 additions & 10 deletions client/sulfuricacid.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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

Expand Down
23 changes: 13 additions & 10 deletions client/weed.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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

Expand Down