mirror of
https://github.com/CommunityOx/ox_lib.git
synced 2026-08-19 07:56:02 +01:00
feat(resource/streaming): timeout functions after 20 ticks
This commit is contained in:
@@ -17,6 +17,7 @@ If you're not interested in this method of loading files, you are free to utilis
|
|||||||
- [x] Server callbacks
|
- [x] Server callbacks
|
||||||
- [x] Table utilities
|
- [x] Table utilities
|
||||||
- [x] OxMySQL wrapper
|
- [x] OxMySQL wrapper
|
||||||
|
- [x] Streaming exports
|
||||||
|
|
||||||
#### To do
|
#### To do
|
||||||
- Think of more features
|
- Think of more features
|
||||||
@@ -38,7 +39,6 @@ Setup imports for ESX and QBCore compatibility with certain tables, functions, a
|
|||||||
<br>
|
<br>
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
Requires the latest optional FXServer build (4478), or anything more recent.
|
|
||||||
Resources are required to utilise Lua 5.4 to ensure compatibility.
|
Resources are required to utilise Lua 5.4 to ensure compatibility.
|
||||||
Any scripts must be loaded _after_ initialising the shared import.
|
Any scripts must be loaded _after_ initialising the shared import.
|
||||||
```lua
|
```lua
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
-- Creates exports from values assigned to lib.
|
-- Creates exports from values assigned to lib
|
||||||
-- Hacky workaround for Lua Language Server support.
|
-- Hacky workaround for Lua Language Server support
|
||||||
|
|
||||||
|
--- Alias for `exports['pe-lualib']`
|
||||||
lib = setmetatable({}, {
|
lib = setmetatable({}, {
|
||||||
__newindex = function(self, name, fn)
|
__newindex = function(self, name, fn)
|
||||||
print('created '..name)
|
|
||||||
exports(name, fn)
|
exports(name, fn)
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
@@ -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
|
---@param dict string
|
||||||
--- Loads an animation dictionary.
|
--- Loads an animation dictionary.
|
||||||
function lib.requestAnimDict(dict)
|
function lib.requestAnimDict(dict)
|
||||||
if not HasAnimDictLoaded(dict) then
|
if HasAnimDictLoaded(dict) then return true end
|
||||||
|
assert(DoesAnimDictExist(dict), ('Attempted to load an invalid animdict (%s)'):format(dict))
|
||||||
RequestAnimDict(dict)
|
RequestAnimDict(dict)
|
||||||
while not HasAnimDictLoaded(dict) do Wait(0) end
|
if hasLoaded(HasAnimDictLoaded, dict) then return true end
|
||||||
end
|
print(('Unable to load animdict after 20 ticks (%s)'):format(dict))
|
||||||
return true
|
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param set string
|
---@param set string
|
||||||
--- Loads an animation clipset.
|
--- Loads an animation clipset.
|
||||||
function lib.requestAnimSet(set)
|
function lib.requestAnimSet(set)
|
||||||
if not HasAnimSetLoaded(set) then
|
if HasAnimSetLoaded(set) then return true end
|
||||||
RequestAnimSet(set)
|
RequestAnimSet(set)
|
||||||
while not HasAnimSetLoaded(set) do Wait(0) end
|
if hasLoaded(HasAnimSetLoaded, set) then return true end
|
||||||
end
|
print(('Unable to load animset after 20 ticks (%s)'):format(set))
|
||||||
return true
|
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param model string|number
|
---@param model string|number
|
||||||
--- Loads a model.
|
--- Loads a model.
|
||||||
function lib.requestModel(model)
|
function lib.requestModel(model)
|
||||||
model = type(model) == 'number' and model or joaat(model)
|
model = type(model) == 'number' and model or joaat(model)
|
||||||
if not HasModelLoaded(model) then
|
if HasModelLoaded(model) then return true end
|
||||||
assert(IsModelValid(model), ('Attempted to load an invalid model (%s)'):format(model))
|
assert(IsModelValid(model), ('Attempted to load an invalid model (%s)'):format(model))
|
||||||
RequestModel(model)
|
RequestModel(model)
|
||||||
while not HasModelLoaded(model) do Wait(0) end
|
if hasLoaded(HasModelLoaded, model) then return true end
|
||||||
end
|
print(('Unable to load model after 20 ticks (%s)'):format(model))
|
||||||
return true
|
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param dict string
|
---@param dict string
|
||||||
--- Loads a texture dictionary.
|
--- Loads a texture dictionary.
|
||||||
function lib.requestStreamedTextureDict(dict)
|
function lib.requestStreamedTextureDict(dict)
|
||||||
if not HasStreamedTextureDictLoaded(dict) then
|
if HasStreamedTextureDictLoaded(dict) then return true end
|
||||||
RequestStreamedTextureDict(dict)
|
RequestStreamedTextureDict(dict)
|
||||||
while not HasStreamedTextureDictLoaded(dict) do Wait(0) end
|
if hasLoaded(HasStreamedTextureDictLoaded, dict) then return true end
|
||||||
end
|
print(('Unable to load texture dict after 20 ticks (%s)'):format(name))
|
||||||
return true
|
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param fxName string
|
---@param fxName string
|
||||||
--- Loads a named particle effect.
|
--- Loads a named particle effect.
|
||||||
function lib.requestNamedPtfxAsset(fxName)
|
function lib.requestNamedPtfxAsset(fxName)
|
||||||
if not HasNamedPtfxAssetLoaded(fxName) then
|
if HasNamedPtfxAssetLoaded(fxName) then return true end
|
||||||
RequestNamedPtfxAsset(fxName)
|
RequestNamedPtfxAsset(fxName)
|
||||||
while not HasNamedPtfxAssetLoaded(fxName) do Wait(0) end
|
if hasLoaded(RequestNamedPtfxAsset, fxName) then return true end
|
||||||
end
|
print(('Unable to load named ptfx after 20 ticks (%s)'):format(name))
|
||||||
return true
|
|
||||||
end
|
end
|
||||||
Reference in New Issue
Block a user