mirror of
https://github.com/CommunityOx/ox_lib.git
synced 2026-08-17 06:56:03 +01:00
refactor(streaming): convert to modules
Import methods rather than call via exports.
This commit is contained in:
@@ -26,7 +26,10 @@ local function createProp(prop)
|
||||
lib.requestModel(prop.model)
|
||||
local coords = GetEntityCoords(cache.ped)
|
||||
local object = CreateObject(prop.model, coords.x, coords.y, coords.z, true, true, true)
|
||||
|
||||
AttachEntityToEntity(object, cache.ped, GetPedBoneIndex(cache.ped, prop.bone or 60309), prop.pos.x, prop.pos.y, prop.pos.z, prop.rot.x, prop.rot.y, prop.rot.z, true, true, false, true, 0, true)
|
||||
SetModelAsNoLongerNeeded(prop.model)
|
||||
|
||||
return object
|
||||
end
|
||||
|
||||
@@ -44,10 +47,14 @@ local function startProgress(data)
|
||||
if data.anim then
|
||||
if data.anim.dict then
|
||||
lib.requestAnimDict(data.anim.dict)
|
||||
|
||||
TaskPlayAnim(cache.ped, data.anim.dict, data.anim.clip, data.anim.blendIn or 3.0, data.anim.blendOut or 1.0, data.anim.duration or -1, data.anim.flag or 49, data.anim.playbackRate or 0, data.anim.lockX, data.anim.lockY, data.anim.lockZ)
|
||||
RemoveAnimDict(data.anim.dict)
|
||||
|
||||
data.anim = true
|
||||
elseif data.anim.scenario then
|
||||
TaskStartScenarioInPlace(cache.ped, data.anim.scenario, 0, data.anim.playEnter ~= nil and data.anim.playEnter or true)
|
||||
|
||||
data.anim = true
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,76 +0,0 @@
|
||||
local function request(native, hasLoaded, requestType, name, timeout)
|
||||
native(name)
|
||||
|
||||
if coroutine.running() then
|
||||
if not timeout then
|
||||
timeout = 500
|
||||
end
|
||||
|
||||
for i = 1, timeout do
|
||||
Wait(0)
|
||||
if hasLoaded(name) then
|
||||
return name
|
||||
end
|
||||
end
|
||||
|
||||
print(("Failed to load %s '%s' after %s ticks"):format(requestType, name, timeout))
|
||||
end
|
||||
|
||||
return name
|
||||
end
|
||||
|
||||
---Load an animation dictionary. When called from a thread, it will yield until it has loaded.
|
||||
---@param animDict string
|
||||
---@param timeout number? Number of ticks to wait for the dictionary to load. Default is 500.
|
||||
---@return string? animDict
|
||||
function lib.requestAnimDict(animDict, timeout)
|
||||
if HasAnimDictLoaded(animDict) then return animDict end
|
||||
|
||||
if not DoesAnimDictExist(animDict) then
|
||||
return error(("Attempted to load invalid animDict (%s)"):format(animDict))
|
||||
end
|
||||
|
||||
return request(RequestAnimDict, HasAnimDictLoaded, 'animDict', animDict, timeout)
|
||||
end
|
||||
|
||||
---Load an animation clipset. When called from a thread, it will yield until it has loaded.
|
||||
---@param animSet string
|
||||
---@param timeout number? Number of ticks to wait for the clipset to load. Default is 500.
|
||||
---@return string? animSet
|
||||
function lib.requestAnimSet(animSet, timeout)
|
||||
if HasAnimSetLoaded(animSet) then return animSet end
|
||||
return request(RequestAnimSet, HasAnimSetLoaded, 'animSet', animSet, timeout)
|
||||
end
|
||||
|
||||
---Load a model. When called from a thread, it will yield until it has loaded.
|
||||
---@param model number
|
||||
---@param timeout number? Number of ticks to wait for the model to load. Default is 500.
|
||||
---@return number? model
|
||||
function lib.requestModel(model, timeout)
|
||||
if not tonumber(model) then model = joaat(model) end
|
||||
if HasModelLoaded(model) then return model end
|
||||
|
||||
if not IsModelValid(model) then
|
||||
return error(("Attempted to load invalid model (%s)"):format(model))
|
||||
end
|
||||
|
||||
return request(RequestModel, HasModelLoaded, 'model', model, timeout)
|
||||
end
|
||||
|
||||
---Load a texture dictionary. When called from a thread, it will yield until it has loaded.
|
||||
---@param textureDict string
|
||||
---@param timeout number? Number of ticks to wait for the dictionary to load. Default is 500.
|
||||
---@return string? textureDict
|
||||
function lib.requestStreamedTextureDict(textureDict, timeout)
|
||||
if HasStreamedTextureDictLoaded(textureDict) then return textureDict end
|
||||
return request(RequestStreamedTextureDict, HasStreamedTextureDictLoaded, 'textureDict', textureDict, timeout)
|
||||
end
|
||||
|
||||
---Load a named particle effect. When called from a thread, it will yield until it has loaded.
|
||||
---@param fxName string
|
||||
---@param timeout number? Number of ticks to wait for the particle effect to load. Default is 500.
|
||||
---@return string? fxName
|
||||
function lib.requestNamedPtfxAsset(fxName, timeout)
|
||||
if HasNamedPtfxAssetLoaded(fxName) then return fxName end
|
||||
return request(RequestNamedPtfxAsset, HasNamedPtfxAssetLoaded, 'fxName', fxName, timeout)
|
||||
end
|
||||
Reference in New Issue
Block a user