diff --git a/core_c.lua b/core_c.lua index 90118ce..2d11ba3 100644 --- a/core_c.lua +++ b/core_c.lua @@ -73,6 +73,7 @@ addEvent(resourceName..':ReplaceModel', true) addEventHandler(resourceName..':ReplaceModel', localPlayer, function(model, id) if type(model) == 'table' then for _,entry in ipairs(model) do + -- replace provided model with certain id ML.Funcs.ReplaceModel(entry, id) end end diff --git a/sync_c.lua b/sync_c.lua index 5327df4..ceb366e 100644 --- a/sync_c.lua +++ b/sync_c.lua @@ -21,8 +21,8 @@ local function RequestIDs() end -- Sync incoming models -addEvent(resourceName..':SetSyncedModels', true) -addEventHandler(resourceName..':SetSyncedModels', localPlayer, function(models) +addEvent(resourceName..':SendSyncedModels', true) +addEventHandler(resourceName..':SendSyncedModels', localPlayer, function(models) assert(type(models) == 'table', 'Expected table in "modelloader:getModels", got '..type(models)) syncedModels = models @@ -32,9 +32,12 @@ end) -- When resource starts, request synced models -- and request ids for them addEventHandler('onClientResourceStart', resourceRoot, function() + -- if syncedModels table is empty if not next(syncedModels) then + -- request synced models from the server triggerServerEvent(resourceName..':RequestSyncedModels', resourceRoot) end + -- request ids for models RequestIDs() end) diff --git a/sync_s.lua b/sync_s.lua index 7e628d8..35f9c2b 100644 --- a/sync_s.lua +++ b/sync_s.lua @@ -2,7 +2,7 @@ local syncedIds = {} -- Send synced models to player local function SendSyncedModels(player) - triggerClientEvent(player, resourceName..':SetSyncedModels', player, GetModels()) + triggerClientEvent(player, resourceName..':SendSyncedModels', player, GetModels()) end -- Send synced models to a player @@ -20,7 +20,8 @@ addEventHandler(resourceName..':SendSyncedIDs', resourceRoot, function(ids) end) -- When player joins, send synced models -addEventHandler('onPlayerJoin', root, function() +addEventHandler('onPlayerResourceStart', root, function(res) + if res ~= resource then return end SendSyncedModels(source) end)