FiveM Docs
es_extendedClientModules

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

Resourcees_extended (implemented in esx_lib as xLib.streaming)
SideClient
TimeoutxLib: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)
NameTypeDescription
modelHashnumber | stringModel hash or name. Names are hashed with joaat.
cbfunction?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)
end

ESX.Streaming.RequestAnimDict

ESX.Streaming.RequestAnimDict(animDict, cb)
NameTypeDescription
animDictstringAnimation dictionary.
cbfunction?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).

NameTypeDescription
animSetstringClipset name, for example move_m@drunk@verydrunk.
cbfunction?function(animSet).

Returns: string|nil

local walk = ESX.Streaming.RequestAnimSet('move_m@drunk@verydrunk')

if walk then
    SetPedMovementClipset(ESX.PlayerData.ped, walk, 1.0)
end

ESX.Streaming.RequestStreamedTextureDict

ESX.Streaming.RequestStreamedTextureDict(textureDict, cb)
NameTypeDescription
textureDictstringTexture dictionary.
cbfunction?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)
NameTypeDescription
assetNamestringParticle asset, for example core.
cbfunction?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)
NameTypeDescription
weaponHashnumberWeapon hash, for example `WEAPON_PISTOL`.
cbfunction?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 nil for a custom vehicle or ped. The addon resource is not started or the model name is wrong. Check IsModelInCdimage.
  • Memory grows over time. Release assets with the matching SetModelAsNoLongerNeeded / Remove* native.

Frequently asked questions

Independent documentation

esx-fivem.com is a community project and is not affiliated with the ESX Framework team. Facts on this page were checked against the upstream source. Official resources: docs.esx-framework.org and github.com/esx-framework.
Edit on GitHub

Last updated on

On this page