@@ -631,7 +631,6 @@ function updateStreamedOutElement(source)
631
631
end
632
632
end
633
633
addEventHandler ( " onClientElementStreamOut" , root , function () updateStreamedOutElement (source ) end )
634
- addEventHandler ( " onClientElementDestroy" , root , function () updateStreamedOutElement (source ) end ) -- same behavior for stream out
635
634
636
635
-- (4) updateModelChangedElement
637
636
function updateModelChangedElement (source , oldModel , newModel )
@@ -686,6 +685,30 @@ function updateModelChangedElement(source, oldModel, newModel)
686
685
end
687
686
addEventHandler ( " onClientElementModelChange" , root , function (oldModel , newModel ) updateModelChangedElement (source , oldModel , newModel ) end )
688
687
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
+
689
712
-- Free waiting_queue memory when player leaves
690
713
addEventHandler ( " onClientPlayerQuit" , root ,
691
714
function (reason )
0 commit comments