mirror of
https://github.com/qbcore-fivem/qb-core.git
synced 2026-08-28 17:01:16 +00:00
Merge pull request #1219 from MrNewb/main
Add timeouts and validation to asset loaders
This commit is contained in:
+43
-14
@@ -356,12 +356,23 @@ end
|
|||||||
|
|
||||||
-- Vehicle
|
-- Vehicle
|
||||||
|
|
||||||
function QBCore.Functions.LoadModel(model)
|
function QBCore.Functions.LoadModel(model, timeout)
|
||||||
if HasModelLoaded(model) then return end
|
timeout = timeout or 5000
|
||||||
RequestModel(model)
|
local modelName = model
|
||||||
while not HasModelLoaded(model) do
|
if type(modelName) ~= 'number' then modelName = joaat(model) end
|
||||||
|
if HasModelLoaded(modelName) then return true, model end
|
||||||
|
|
||||||
|
if not IsModelValid(modelName) and not IsModelInCdimage(modelName) then
|
||||||
|
print(('[QBCore] Model does not exist: %s'):format(modelName or model))
|
||||||
|
return false, modelName
|
||||||
|
end
|
||||||
|
|
||||||
|
RequestModel(modelName)
|
||||||
|
local count = GetGameTimer() + timeout
|
||||||
|
while not HasModelLoaded(modelName) and GetGameTimer() < count do
|
||||||
Wait(0)
|
Wait(0)
|
||||||
end
|
end
|
||||||
|
return HasModelLoaded(modelName), modelName
|
||||||
end
|
end
|
||||||
|
|
||||||
function QBCore.Functions.SpawnVehicle(model, cb, coords, isnetworked, teleportInto)
|
function QBCore.Functions.SpawnVehicle(model, cb, coords, isnetworked, teleportInto)
|
||||||
@@ -880,12 +891,20 @@ function QBCore.Functions.DrawText3D(x, y, z, text)
|
|||||||
ClearDrawOrigin()
|
ClearDrawOrigin()
|
||||||
end
|
end
|
||||||
|
|
||||||
function QBCore.Functions.RequestAnimDict(animDict)
|
function QBCore.Functions.RequestAnimDict(animDict, timeout)
|
||||||
if HasAnimDictLoaded(animDict) then return end
|
timeout = timeout or 5000
|
||||||
|
if HasAnimDictLoaded(animDict) then return true, animDict end
|
||||||
|
if not DoesAnimDictExist(animDict) then
|
||||||
|
print(('[QBCore] Animation dictionary does not exist: %s'):format(animDict))
|
||||||
|
return false, animDict
|
||||||
|
end
|
||||||
|
|
||||||
RequestAnimDict(animDict)
|
RequestAnimDict(animDict)
|
||||||
while not HasAnimDictLoaded(animDict) do
|
local count = GetGameTimer() + timeout
|
||||||
|
while not HasAnimDictLoaded(animDict) and GetGameTimer() < count do
|
||||||
Wait(0)
|
Wait(0)
|
||||||
end
|
end
|
||||||
|
return HasAnimDictLoaded(animDict), animDict
|
||||||
end
|
end
|
||||||
|
|
||||||
function QBCore.Functions.GetClosestBone(entity, list)
|
function QBCore.Functions.GetClosestBone(entity, list)
|
||||||
@@ -948,20 +967,30 @@ function QBCore.Functions.SpawnClear(coords, radius)
|
|||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
function QBCore.Functions.LoadAnimSet(animSet)
|
function QBCore.Functions.LoadAnimSet(animSet, timeout)
|
||||||
if HasAnimSetLoaded(animSet) then return end
|
timeout = timeout or 5000
|
||||||
|
if HasAnimSetLoaded(animSet) then return true, animSet end
|
||||||
RequestAnimSet(animSet)
|
RequestAnimSet(animSet)
|
||||||
while not HasAnimSetLoaded(animSet) do
|
|
||||||
|
local count = GetGameTimer() + timeout
|
||||||
|
while not HasAnimSetLoaded(animSet) and GetGameTimer() < count do
|
||||||
Wait(0)
|
Wait(0)
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
function QBCore.Functions.LoadParticleDictionary(dictionary)
|
return HasAnimSetLoaded(animSet), animSet
|
||||||
if HasNamedPtfxAssetLoaded(dictionary) then return end
|
end
|
||||||
|
|
||||||
|
function QBCore.Functions.LoadParticleDictionary(dictionary, timeout)
|
||||||
|
timeout = timeout or 5000
|
||||||
|
if HasNamedPtfxAssetLoaded(dictionary) then return true, dictionary end
|
||||||
RequestNamedPtfxAsset(dictionary)
|
RequestNamedPtfxAsset(dictionary)
|
||||||
while not HasNamedPtfxAssetLoaded(dictionary) do
|
|
||||||
|
local count = GetGameTimer() + timeout
|
||||||
|
while not HasNamedPtfxAssetLoaded(dictionary) and GetGameTimer() < count do
|
||||||
Wait(0)
|
Wait(0)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
return HasNamedPtfxAssetLoaded(dictionary), dictionary
|
||||||
end
|
end
|
||||||
|
|
||||||
function QBCore.Functions.StartParticleAtCoord(dict, ptName, looped, coords, rot, scale, alpha, color, duration)
|
function QBCore.Functions.StartParticleAtCoord(dict, ptName, looped, coords, rot, scale, alpha, color, duration)
|
||||||
|
|||||||
Reference in New Issue
Block a user