diff --git a/README.md b/README.md index 20989c1..392fcb0 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,7 @@ If you're not interested in this method of loading files, you are free to utilis - [x] Server callbacks - [x] Table utilities - [x] OxMySQL wrapper +- [x] Streaming exports #### To do - Think of more features @@ -38,7 +39,6 @@ Setup imports for ESX and QBCore compatibility with certain tables, functions, a
## Usage -Requires the latest optional FXServer build (4478), or anything more recent. Resources are required to utilise Lua 5.4 to ensure compatibility. Any scripts must be loaded _after_ initialising the shared import. ```lua diff --git a/resource/main.lua b/resource/main.lua index ff83a26..631f4d7 100644 --- a/resource/main.lua +++ b/resource/main.lua @@ -1,9 +1,9 @@ --- Creates exports from values assigned to lib. --- Hacky workaround for Lua Language Server support. +-- Creates exports from values assigned to lib +-- Hacky workaround for Lua Language Server support +--- Alias for `exports['pe-lualib']` lib = setmetatable({}, { __newindex = function(self, name, fn) - print('created '..name) exports(name, fn) end }) \ No newline at end of file diff --git a/resource/streaming/client.lua b/resource/streaming/client.lua index 824e4d8..cb3dd58 100644 --- a/resource/streaming/client.lua +++ b/resource/streaming/client.lua @@ -1,51 +1,57 @@ +local function hasLoaded(fn, name) + local timeout = 0 + while not fn(name) do + Wait(0) + timeout += 1 + if timeout > 20 then return false end + end + return true +end + ---@param dict string --- Loads an animation dictionary. function lib.requestAnimDict(dict) - if not HasAnimDictLoaded(dict) then - RequestAnimDict(dict) - while not HasAnimDictLoaded(dict) do Wait(0) end - end - return true + if HasAnimDictLoaded(dict) then return true end + assert(DoesAnimDictExist(dict), ('Attempted to load an invalid animdict (%s)'):format(dict)) + RequestAnimDict(dict) + if hasLoaded(HasAnimDictLoaded, dict) then return true end + print(('Unable to load animdict after 20 ticks (%s)'):format(dict)) end ---@param set string --- Loads an animation clipset. function lib.requestAnimSet(set) - if not HasAnimSetLoaded(set) then - RequestAnimSet(set) - while not HasAnimSetLoaded(set) do Wait(0) end - end - return true + if HasAnimSetLoaded(set) then return true end + RequestAnimSet(set) + if hasLoaded(HasAnimSetLoaded, set) then return true end + print(('Unable to load animset after 20 ticks (%s)'):format(set)) end ---@param model string|number --- Loads a model. function lib.requestModel(model) - model = type(model) == 'number' and model or joaat(model) - if not HasModelLoaded(model) then - assert(IsModelValid(model), ('Attempted to load an invalid model (%s)'):format(model)) - RequestModel(model) - while not HasModelLoaded(model) do Wait(0) end - end - return true + model = type(model) == 'number' and model or joaat(model) + if HasModelLoaded(model) then return true end + assert(IsModelValid(model), ('Attempted to load an invalid model (%s)'):format(model)) + RequestModel(model) + if hasLoaded(HasModelLoaded, model) then return true end + print(('Unable to load model after 20 ticks (%s)'):format(model)) end ---@param dict string --- Loads a texture dictionary. function lib.requestStreamedTextureDict(dict) - if not HasStreamedTextureDictLoaded(dict) then - RequestStreamedTextureDict(dict) - while not HasStreamedTextureDictLoaded(dict) do Wait(0) end - end - return true + if HasStreamedTextureDictLoaded(dict) then return true end + RequestStreamedTextureDict(dict) + if hasLoaded(HasStreamedTextureDictLoaded, dict) then return true end + print(('Unable to load texture dict after 20 ticks (%s)'):format(name)) end ---@param fxName string --- Loads a named particle effect. function lib.requestNamedPtfxAsset(fxName) - if not HasNamedPtfxAssetLoaded(fxName) then - RequestNamedPtfxAsset(fxName) - while not HasNamedPtfxAssetLoaded(fxName) do Wait(0) end - end - return true + if HasNamedPtfxAssetLoaded(fxName) then return true end + RequestNamedPtfxAsset(fxName) + if hasLoaded(RequestNamedPtfxAsset, fxName) then return true end + print(('Unable to load named ptfx after 20 ticks (%s)'):format(name)) end \ No newline at end of file