Skip to content

Commit e347865

Browse files
Separated onClientElementDestroy in client.lua
1 parent 5fa524e commit e347865

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

newmodels/client.lua

+24-1
Original file line numberDiff line numberDiff line change
@@ -631,7 +631,6 @@ function updateStreamedOutElement(source)
631631
end
632632
end
633633
addEventHandler( "onClientElementStreamOut", root, function () updateStreamedOutElement(source) end)
634-
addEventHandler( "onClientElementDestroy", root, function () updateStreamedOutElement(source) end) -- same behavior for stream out
635634

636635
-- (4) updateModelChangedElement
637636
function updateModelChangedElement(source, oldModel, newModel)
@@ -686,6 +685,30 @@ function updateModelChangedElement(source, oldModel, newModel)
686685
end
687686
addEventHandler( "onClientElementModelChange", root, function (oldModel, newModel) updateModelChangedElement(source, oldModel, newModel) end)
688687

688+
function handleDestroyedElement()
689+
if not received_modlist then return end
690+
local et = getElementType(source)
691+
if not isElementTypeSupported(et) then
692+
return
693+
end
694+
695+
local id = tonumber(getElementData(source, dataNames[et]))
696+
if not (id) then return end -- doesn't have a custom model
697+
698+
if isCustomModID(id) then
699+
700+
local allocated_id = allocated_ids[id]
701+
if not allocated_id then return end -- was not allocated
702+
703+
if not hasOtherElementsWithModel(source, id) then
704+
freeElementCustomMod(id)
705+
return
706+
end
707+
end
708+
end
709+
addEventHandler( "onClientElementDestroy", root, handleDestroyedElement)
710+
711+
689712
-- Free waiting_queue memory when player leaves
690713
addEventHandler( "onClientPlayerQuit", root,
691714
function (reason)

0 commit comments

Comments
 (0)