Skip to content

Commit

Permalink
Refactored scripts
Browse files Browse the repository at this point in the history
Renamed events;
Improved stability;
Added comments for some functions
  • Loading branch information
TracerDS committed Jun 6, 2024
1 parent 94d2084 commit 16dee86
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
1 change: 1 addition & 0 deletions core_c.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 5 additions & 2 deletions sync_c.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)

Expand Down
5 changes: 3 additions & 2 deletions sync_s.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)

Expand Down

0 comments on commit 16dee86

Please sign in to comment.