Streaming
ESX.Streaming loads models, animation dictionaries, anim sets, texture dictionaries, particle assets and weapon assets safely with a timeout in ESX Legacy.
ESX.Streaming wraps the GTA "request and wait until loaded" pattern. Each function requests an asset, waits until it is loaded and returns it, or returns nil if loading fails. Use it before you spawn a model, play an animation or draw a texture.
Overview
| Resource | es_extended (implemented in esx_lib as xLib.streaming) |
| Side | Client |
| Timeout | xLib:streamingTimeout convar, default 10000 ms, 0 waits forever |
Every function has the same shape: (asset, cb?). With cb, the function calls cb(asset) and returns its result. Without cb, it returns the asset. On timeout it returns nil and cb is not called. The functions block, so call them from a thread.
Functions
ESX.Streaming.RequestModel
ESX.Streaming.RequestModel(modelHash, cb)| Name | Type | Description |
|---|---|---|
modelHash | number | string | Model hash or name. Names are hashed with joaat. |
cb | function? | function(modelHash). |
Returns: number|nil model hash. nil if the model does not exist or timed out.
local model = ESX.Streaming.RequestModel('a_m_y_business_01')
if model then
local ped = CreatePed(4, model, 240.0, -862.0, 29.7, 340.0, false, true)
SetModelAsNoLongerNeeded(model)
endESX.Streaming.RequestAnimDict
ESX.Streaming.RequestAnimDict(animDict, cb)| Name | Type | Description |
|---|---|---|
animDict | string | Animation dictionary. |
cb | function? | function(animDict). |
Returns: string|nil
ESX.Streaming.RequestAnimDict('mp_arresting', function(dict)
TaskPlayAnim(ESX.PlayerData.ped, dict, 'idle', 8.0, -8.0, -1, 49, 0.0, false, false, false)
RemoveAnimDict(dict)
end)ESX.Streaming.RequestAnimSet
ESX.Streaming.RequestAnimSet(animSet, cb)Loads a movement clipset (walk style).
| Name | Type | Description |
|---|---|---|
animSet | string | Clipset name, for example move_m@drunk@verydrunk. |
cb | function? | function(animSet). |
Returns: string|nil
local walk = ESX.Streaming.RequestAnimSet('move_m@drunk@verydrunk')
if walk then
SetPedMovementClipset(ESX.PlayerData.ped, walk, 1.0)
endESX.Streaming.RequestStreamedTextureDict
ESX.Streaming.RequestStreamedTextureDict(textureDict, cb)| Name | Type | Description |
|---|---|---|
textureDict | string | Texture dictionary. |
cb | function? | function(textureDict). |
Returns: string|nil
CreateThread(function()
local dict = ESX.Streaming.RequestStreamedTextureDict('commonmenu')
if not dict then return end
while showLogo do
DrawSprite(dict, 'shop_box_tick', 0.9, 0.1, 0.03, 0.05, 0.0, 255, 255, 255, 255)
Wait(0)
end
SetStreamedTextureDictAsNoLongerNeeded(dict)
end)ESX.Streaming.RequestNamedPtfxAsset
ESX.Streaming.RequestNamedPtfxAsset(assetName, cb)| Name | Type | Description |
|---|---|---|
assetName | string | Particle asset, for example core. |
cb | function? | function(assetName). |
Returns: string|nil
ESX.Streaming.RequestNamedPtfxAsset('core', function(asset)
UseParticleFxAsset(asset)
local coords = GetEntityCoords(ESX.PlayerData.ped)
StartParticleFxNonLoopedAtCoord('exp_grd_bzgas_smoke', coords.x, coords.y, coords.z, 0.0, 0.0, 0.0, 1.0, false, false, false)
end)ESX.Streaming.RequestWeaponAsset
ESX.Streaming.RequestWeaponAsset(weaponHash, cb)| Name | Type | Description |
|---|---|---|
weaponHash | number | Weapon hash, for example `WEAPON_PISTOL`. |
cb | function? | function(weaponHash). |
Returns: number|nil
local weapon = ESX.Streaming.RequestWeaponAsset(`WEAPON_PISTOL`)More in esx_lib
xLib.streaming also has requestModelWithSpinner(model, message, cb) and requestAudioBank(bankName, cb). They are not mapped to ESX.Streaming. Load @esx_lib/imports.lua in your manifest to use them through xLib.
Common issues
- Function returns
nilfor a custom vehicle or ped. The addon resource is not started or the model name is wrong. CheckIsModelInCdimage. - Memory grows over time. Release assets with the matching
SetModelAsNoLongerNeeded/Remove*native.
Related
Frequently asked questions
Independent documentation
Last updated on
Scaleform
ESX.Scaleform functions show GTA scaleforms like the wasted shard, breaking news and popup warnings, plus helpers to load movies and call scaleform methods.
Points
ESX.Point creates proximity points with enter, leave and inside callbacks in ESX Legacy, replacing distance loops. Learn the options, methods and pitfalls.