[Tutorial + Snippet] Simple Way to use Network Synchronized Scenes

Hello! I’ve seen quite a few posts that talk about how to use Networked Synchronized Scenes but none seem as simple as the way I have been doing it. So, I thought id share this with the community :slight_smile:

Here’s the function (i’d suggest chucking this in a base resource then exposing it using exports)
Edit: E.G GitHub - Benjamoon/bl_networkedScenes: Simple FiveM script that exposes an export to use synced scenes

function NetworkedScene(coords, rotation, peds, objects, duration)
    local scene = NetworkCreateSynchronisedScene(coords.x, coords.y, coords.z, rotation, 2, false, false,
        -1,
        0,
        1.0)

    for k, v in pairs(peds) do
        if v.model and not v.ped then
            while not HasModelLoaded(v.model) do
                RequestModel(v.model)
                Wait(1)
            end

            v.ped = CreatePed(23, v.model, coords.x, coords.y, coords.z, 0.0, true, true)
            v.createdByUs = true
        end
        while not HasAnimDictLoaded(v.anim.dict) do
            RequestAnimDict(v.anim.dict)
            Wait(1)
        end
        NetworkAddPedToSynchronisedScene(v.ped, scene, v.anim.dict, v.anim.anim, 1.5,
            -4.0, 1,
            16,
            1148846080, 0)
    end

    for k, v in pairs(objects) do
        if v.model and not v.object then
            while not HasModelLoaded(v.model) do
                RequestModel(v.model)
                Wait(1)
            end
            v.object = CreateObject(v.model, coords, true, true, true)
            v.createdByUs = true
        end
        while not HasAnimDictLoaded(v.anim.dict) do
            RequestAnimDict(v.anim.dict)
            Wait(1)
        end
        NetworkAddEntityToSynchronisedScene(v.object, scene, v.anim.dict, v.anim.anim,
            1.0,
            1.0, 1)
    end

    NetworkStartSynchronisedScene(scene)
    Wait(duration)
    NetworkStopSynchronisedScene(scene)

    for k, v in pairs(peds) do
        if v.createdByUs then
            DeletePed(v.ped)
        end
    end

    for k, v in pairs(objects) do
        if v.createdByUs then
            DeleteEntity(v.object)
        end
    end
end

I’m not very good at documenting the way my code works, but here goes…

coords - The coordinates of where to create the scene
rotation - The rotation of the scene
peds - An array of objects representing the peds involved. 
      {
            anim = {dict, anim},
            ped = The physical ped, optional, will override the below option,
            model = the ped model, passing this (and not the above) will spawn the ped
      }
objects - An array of objects representing the objects involved
     {
            anim = {dict, anim},
            object = The physical object, optional, will override the below option,
            model = the object model, passing this (and not the above) will spawn the object
      }
duration - The duration of the scene, it will be destroyed after this time

And here’s an example on how to use it (vault close anim)

local ped = PlayerPedId()
    local pedCoords = GetEntityCoords(ped)
    local pedRotation = GetEntityRotation(ped)
    NetworkedScene(pedCoords, pedRotation, {
        {
            ped = ped,
            anim = {
                dict = "missbigscore2aig_6",
                anim = "close_vaultdoor"
            }
        }
    }, {
        {
            model = `p_fin_vaultdoor_s`,
            anim = {
                dict = "missbigscore2aig_6",
                anim = "close_vaultdoor_door"
            }
        }
    }, 29000)

And here’s another example that also includes spawning a ped (arresting scene)

local ped = PlayerPedId()
    local pedCoords = GetEntityCoords(ped)
    local pedRotation = GetEntityRotation(ped)
    NetworkedScene(pedCoords, pedRotation, {
        {
            model = `a_f_m_fatwhite_01`,
            anim = {
                dict = "mp_arresting",
                anim = "arrest_on_floor_back_left_b"
            }
        },
        {
            ped = ped,
            anim = {
                dict = "mp_arresting",
                anim = "arrest_on_floor_back_left_a"
            }
        }
    }, {}, 7366)
3 Likes

bro, thanks for sharing, i’ve been looking so long for a post on this because I’ve been wanting to use synchronized scenes for like 2 months but just let it go because I couldn’t figure it out. Now your post is online and it should help a ton of people.

THANKS!

Question? I have a prop right now but that doesn’t move with the animation, is that caused because the animation isn’t correct?

Yeah, probably

Can I add you on discord? Have a really important question…

How can i find the animations to use this ?

this is awesome! trying to find something like this for years!