mirror of
https://github.com/esx-framework/esx_core.git
synced 2026-08-29 01:08:54 +00:00
Merge remote-tracking branch 'N/main' into dev
This commit is contained in:
@@ -1,4 +1,31 @@
|
|||||||
ESX.Streaming = {}
|
ESX.Streaming = {}
|
||||||
|
local StreamTimeoutMS = 5000
|
||||||
|
local StreamWaitStepMs = 50
|
||||||
|
|
||||||
|
---@param cond fun():boolean
|
||||||
|
---@param timeout number|nil
|
||||||
|
---@param step number|nil
|
||||||
|
---@return boolean loaded -- false on timeout
|
||||||
|
local function waitForLoaded(cond, timeout, step)
|
||||||
|
local start = GetGameTimer()
|
||||||
|
local to = timeout or StreamTimeoutMS
|
||||||
|
local st = step or StreamWaitStepMs
|
||||||
|
while not cond() do
|
||||||
|
if GetGameTimer() - start >= to then
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
Wait(st)
|
||||||
|
end
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
---@generic T
|
||||||
|
---@param cb fun(val:T):any|nil
|
||||||
|
---@param val T
|
||||||
|
---@return T|any
|
||||||
|
local function ret(cb, val)
|
||||||
|
return cb and cb(val) or val
|
||||||
|
end
|
||||||
|
|
||||||
---@param modelHash number | string
|
---@param modelHash number | string
|
||||||
---@param cb? function
|
---@param cb? function
|
||||||
@@ -8,63 +35,94 @@ function ESX.Streaming.RequestModel(modelHash, cb)
|
|||||||
|
|
||||||
if not IsModelInCdimage(modelHash) then return end
|
if not IsModelInCdimage(modelHash) then return end
|
||||||
|
|
||||||
RequestModel(modelHash)
|
if HasModelLoaded(modelHash) then
|
||||||
while not HasModelLoaded(modelHash) do Wait(500) end
|
return ret(cb, modelHash)
|
||||||
|
end
|
||||||
|
|
||||||
return cb and cb(modelHash) or modelHash
|
RequestModel(modelHash)
|
||||||
|
if not waitForLoaded(function() return HasModelLoaded(modelHash) end) then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
return ret(cb, modelHash)
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param textureDict string
|
---@param textureDict string
|
||||||
---@param cb? function
|
---@param cb? function
|
||||||
---@return string | nil
|
---@return string | nil
|
||||||
function ESX.Streaming.RequestStreamedTextureDict(textureDict, cb)
|
function ESX.Streaming.RequestStreamedTextureDict(textureDict, cb)
|
||||||
|
if HasStreamedTextureDictLoaded(textureDict) then
|
||||||
|
return ret(cb, textureDict)
|
||||||
|
end
|
||||||
|
|
||||||
RequestStreamedTextureDict(textureDict, false)
|
RequestStreamedTextureDict(textureDict, false)
|
||||||
|
if not waitForLoaded(function() return HasStreamedTextureDictLoaded(textureDict) end) then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
while not HasStreamedTextureDictLoaded(textureDict) do Wait(500) end
|
return ret(cb, textureDict)
|
||||||
|
|
||||||
return cb and cb(textureDict) or textureDict
|
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param assetName string
|
---@param assetName string
|
||||||
---@param cb? function
|
---@param cb? function
|
||||||
---@return string | nil
|
---@return string | nil
|
||||||
function ESX.Streaming.RequestNamedPtfxAsset(assetName, cb)
|
function ESX.Streaming.RequestNamedPtfxAsset(assetName, cb)
|
||||||
|
if HasNamedPtfxAssetLoaded(assetName) then
|
||||||
|
return ret(cb, assetName)
|
||||||
|
end
|
||||||
|
|
||||||
RequestNamedPtfxAsset(assetName)
|
RequestNamedPtfxAsset(assetName)
|
||||||
|
if not waitForLoaded(function() return HasNamedPtfxAssetLoaded(assetName) end) then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
while not HasNamedPtfxAssetLoaded(assetName) do Wait(500) end
|
return ret(cb, assetName)
|
||||||
|
|
||||||
return cb and cb(assetName) or assetName
|
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param animSet string
|
---@param animSet string
|
||||||
---@param cb? function
|
---@param cb? function
|
||||||
---@return string | nil
|
---@return string | nil
|
||||||
function ESX.Streaming.RequestAnimSet(animSet, cb)
|
function ESX.Streaming.RequestAnimSet(animSet, cb)
|
||||||
|
if HasAnimSetLoaded(animSet) then
|
||||||
|
return ret(cb, animSet)
|
||||||
|
end
|
||||||
|
|
||||||
RequestAnimSet(animSet)
|
RequestAnimSet(animSet)
|
||||||
|
if not waitForLoaded(function() return HasAnimSetLoaded(animSet) end) then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
while not HasAnimSetLoaded(animSet) do Wait(500) end
|
return ret(cb, animSet)
|
||||||
|
|
||||||
return cb and cb(animSet) or animSet
|
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param animDict string
|
---@param animDict string
|
||||||
---@param cb? function
|
---@param cb? function
|
||||||
---@return string | nil
|
---@return string | nil
|
||||||
function ESX.Streaming.RequestAnimDict(animDict, cb)
|
function ESX.Streaming.RequestAnimDict(animDict, cb)
|
||||||
|
if HasAnimDictLoaded(animDict) then
|
||||||
|
return ret(cb, animDict)
|
||||||
|
end
|
||||||
|
|
||||||
RequestAnimDict(animDict)
|
RequestAnimDict(animDict)
|
||||||
|
if not waitForLoaded(function() return HasAnimDictLoaded(animDict) end) then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
while not HasAnimDictLoaded(animDict) do Wait(500) end
|
return ret(cb, animDict)
|
||||||
|
|
||||||
return cb and cb(animDict) or animDict
|
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param weaponHash number | string
|
---@param weaponHash number | string
|
||||||
---@param cb? function
|
---@param cb? function
|
||||||
---@return string | number | nil
|
---@return string | number | nil
|
||||||
function ESX.Streaming.RequestWeaponAsset(weaponHash, cb)
|
function ESX.Streaming.RequestWeaponAsset(weaponHash, cb)
|
||||||
|
if HasWeaponAssetLoaded(weaponHash) then
|
||||||
|
return ret(cb, weaponHash)
|
||||||
|
end
|
||||||
|
|
||||||
RequestWeaponAsset(weaponHash, 31, 0)
|
RequestWeaponAsset(weaponHash, 31, 0)
|
||||||
|
if not waitForLoaded(function() return HasWeaponAssetLoaded(weaponHash) end) then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
while not HasWeaponAssetLoaded(weaponHash) do Wait(500) end
|
return ret(cb, weaponHash)
|
||||||
|
end
|
||||||
return cb and cb(weaponHash) or weaponHash
|
|
||||||
end
|
|
||||||
Reference in New Issue
Block a user