mirror of
https://github.com/esx-framework/esx_core.git
synced 2026-08-29 00:01:20 +00:00
feat(esx_lib/streaming): move streaming request helpers to xLib
This commit is contained in:
@@ -37,3 +37,12 @@ end
|
||||
ESX.Game.GetClosestEntity = xLib.entity.closest
|
||||
EnumerateEntitiesWithinDistance = xLib.entity.EnumerateWithinDistance
|
||||
ESX.Game.Teleport = xLib.entity.Teleport
|
||||
|
||||
ESX.Streaming = {
|
||||
RequestModel = xLib.streaming.requestModel,
|
||||
RequestStreamedTextureDict = xLib.streaming.requestStreamedTextureDict,
|
||||
RequestNamedPtfxAsset = xLib.streaming.requestNamedPtfxAsset,
|
||||
RequestAnimSet = xLib.streaming.requestAnimSet,
|
||||
RequestAnimDict = xLib.streaming.requestAnimDict,
|
||||
RequestWeaponAsset = xLib.streaming.requestWeaponAsset,
|
||||
}
|
||||
|
||||
@@ -1,70 +0,0 @@
|
||||
ESX.Streaming = {}
|
||||
|
||||
---@param modelHash number | string
|
||||
---@param cb? function
|
||||
---@return number | nil
|
||||
function ESX.Streaming.RequestModel(modelHash, cb)
|
||||
modelHash = type(modelHash) == "number" and modelHash or joaat(modelHash)
|
||||
|
||||
if not IsModelInCdimage(modelHash) then return end
|
||||
|
||||
RequestModel(modelHash)
|
||||
while not HasModelLoaded(modelHash) do Wait(500) end
|
||||
|
||||
return cb and cb(modelHash) or modelHash
|
||||
end
|
||||
|
||||
---@param textureDict string
|
||||
---@param cb? function
|
||||
---@return string | nil
|
||||
function ESX.Streaming.RequestStreamedTextureDict(textureDict, cb)
|
||||
RequestStreamedTextureDict(textureDict, false)
|
||||
|
||||
while not HasStreamedTextureDictLoaded(textureDict) do Wait(500) end
|
||||
|
||||
return cb and cb(textureDict) or textureDict
|
||||
end
|
||||
|
||||
---@param assetName string
|
||||
---@param cb? function
|
||||
---@return string | nil
|
||||
function ESX.Streaming.RequestNamedPtfxAsset(assetName, cb)
|
||||
RequestNamedPtfxAsset(assetName)
|
||||
|
||||
while not HasNamedPtfxAssetLoaded(assetName) do Wait(500) end
|
||||
|
||||
return cb and cb(assetName) or assetName
|
||||
end
|
||||
|
||||
---@param animSet string
|
||||
---@param cb? function
|
||||
---@return string | nil
|
||||
function ESX.Streaming.RequestAnimSet(animSet, cb)
|
||||
RequestAnimSet(animSet)
|
||||
|
||||
while not HasAnimSetLoaded(animSet) do Wait(500) end
|
||||
|
||||
return cb and cb(animSet) or animSet
|
||||
end
|
||||
|
||||
---@param animDict string
|
||||
---@param cb? function
|
||||
---@return string | nil
|
||||
function ESX.Streaming.RequestAnimDict(animDict, cb)
|
||||
RequestAnimDict(animDict)
|
||||
|
||||
while not HasAnimDictLoaded(animDict) do Wait(500) end
|
||||
|
||||
return cb and cb(animDict) or animDict
|
||||
end
|
||||
|
||||
---@param weaponHash number | string
|
||||
---@param cb? function
|
||||
---@return string | number | nil
|
||||
function ESX.Streaming.RequestWeaponAsset(weaponHash, cb)
|
||||
RequestWeaponAsset(weaponHash, 31, 0)
|
||||
|
||||
while not HasWeaponAssetLoaded(weaponHash) do Wait(500) end
|
||||
|
||||
return cb and cb(weaponHash) or weaponHash
|
||||
end
|
||||
@@ -58,7 +58,6 @@ client_scripts {
|
||||
'client/modules/npwd.lua',
|
||||
'client/modules/interactions.lua',
|
||||
'client/modules/scaleform.lua',
|
||||
'client/modules/streaming.lua',
|
||||
}
|
||||
|
||||
ui_page {
|
||||
|
||||
@@ -0,0 +1,86 @@
|
||||
---@class streaminglib
|
||||
xLib.streaming = {}
|
||||
|
||||
---@param modelHash number | string
|
||||
---@param cb? function
|
||||
---@return number | nil
|
||||
function xLib.streaming.requestModel(modelHash, cb)
|
||||
modelHash = type(modelHash) == "number" and modelHash or joaat(modelHash)
|
||||
|
||||
if not IsModelInCdimage(modelHash) then return end
|
||||
|
||||
RequestModel(modelHash)
|
||||
|
||||
while not HasModelLoaded(modelHash) do
|
||||
Wait(500)
|
||||
end
|
||||
|
||||
return cb and cb(modelHash) or modelHash
|
||||
end
|
||||
|
||||
---@param textureDict string
|
||||
---@param cb? function
|
||||
---@return string | nil
|
||||
function xLib.streaming.requestStreamedTextureDict(textureDict, cb)
|
||||
RequestStreamedTextureDict(textureDict, false)
|
||||
|
||||
while not HasStreamedTextureDictLoaded(textureDict) do
|
||||
Wait(500)
|
||||
end
|
||||
|
||||
return cb and cb(textureDict) or textureDict
|
||||
end
|
||||
|
||||
---@param assetName string
|
||||
---@param cb? function
|
||||
---@return string | nil
|
||||
function xLib.streaming.requestNamedPtfxAsset(assetName, cb)
|
||||
RequestNamedPtfxAsset(assetName)
|
||||
|
||||
while not HasNamedPtfxAssetLoaded(assetName) do
|
||||
Wait(500)
|
||||
end
|
||||
|
||||
return cb and cb(assetName) or assetName
|
||||
end
|
||||
|
||||
---@param animSet string
|
||||
---@param cb? function
|
||||
---@return string | nil
|
||||
function xLib.streaming.requestAnimSet(animSet, cb)
|
||||
RequestAnimSet(animSet)
|
||||
|
||||
while not HasAnimSetLoaded(animSet) do
|
||||
Wait(500)
|
||||
end
|
||||
|
||||
return cb and cb(animSet) or animSet
|
||||
end
|
||||
|
||||
---@param animDict string
|
||||
---@param cb? function
|
||||
---@return string | nil
|
||||
function xLib.streaming.requestAnimDict(animDict, cb)
|
||||
RequestAnimDict(animDict)
|
||||
|
||||
while not HasAnimDictLoaded(animDict) do
|
||||
Wait(500)
|
||||
end
|
||||
|
||||
return cb and cb(animDict) or animDict
|
||||
end
|
||||
|
||||
---@param weaponHash number | string
|
||||
---@param cb? function
|
||||
---@return string | number | nil
|
||||
function xLib.streaming.requestWeaponAsset(weaponHash, cb)
|
||||
RequestWeaponAsset(weaponHash, 31, 0)
|
||||
|
||||
while not HasWeaponAssetLoaded(weaponHash) do
|
||||
Wait(500)
|
||||
end
|
||||
|
||||
return cb and cb(weaponHash) or weaponHash
|
||||
end
|
||||
|
||||
return xLib.streaming
|
||||
Reference in New Issue
Block a user