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
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)