diff --git a/newmodels/_config.lua b/newmodels/_config.lua index c607b5e..ef7139f 100644 --- a/newmodels/_config.lua +++ b/newmodels/_config.lua @@ -19,6 +19,18 @@ dataNames = { -- useful for getting a vehicle's base model to fetch its original handling, etc baseDataName = "baseID" +-- If you are 100% sure that the mods in mod_list.lua are valid, you can disable initial checks +-- for faster startup time +STARTUP_VERIFICATIONS = true + +-- Newmodels will try to start these resources (identified by their names) after newmodels has started, +-- as well as stop them when newmodels is stopped +-- Usually these are resources that use newmodels and you want them to start only after newmodels, +-- and they can be stopped when newmodels stops +OTHER_RESOURCES = { + -- { name = "sampobj_reloaded", start = true, stop = true} +} + -- Mod file download feature SHOW_DOWNLOADING = true -- display the downloading progress dxDraw KICK_ON_DOWNLOAD_FAILS = true -- kick player if failed to download a file more than X times diff --git a/newmodels/client.lua b/newmodels/client.lua index abf717f..d0cce11 100644 --- a/newmodels/client.lua +++ b/newmodels/client.lua @@ -631,7 +631,6 @@ function updateStreamedOutElement(source) end end addEventHandler( "onClientElementStreamOut", root, function () updateStreamedOutElement(source) end) -addEventHandler( "onClientElementDestroy", root, function () updateStreamedOutElement(source) end) -- same behavior for stream out -- (4) updateModelChangedElement function updateModelChangedElement(source, oldModel, newModel) @@ -686,6 +685,30 @@ function updateModelChangedElement(source, oldModel, newModel) end addEventHandler( "onClientElementModelChange", root, function (oldModel, newModel) updateModelChangedElement(source, oldModel, newModel) end) +function handleDestroyedElement() + if not received_modlist then return end + local et = getElementType(source) + if not isElementTypeSupported(et) then + return + end + + local id = tonumber(getElementData(source, dataNames[et])) + if not (id) then return end -- doesn't have a custom model + + if isCustomModID(id) then + + local allocated_id = allocated_ids[id] + if not allocated_id then return end -- was not allocated + + if not hasOtherElementsWithModel(source, id) then + freeElementCustomMod(id) + return + end + end +end +addEventHandler( "onClientElementDestroy", root, handleDestroyedElement) + + -- Free waiting_queue memory when player leaves addEventHandler( "onClientPlayerQuit", root, function (reason) diff --git a/newmodels/meta.xml b/newmodels/meta.xml index aecfe3a..b5fb1e5 100644 --- a/newmodels/meta.xml +++ b/newmodels/meta.xml @@ -1,10 +1,6 @@ - + description="minimalistic library for adding new models to your server" version="2.0.1" type="script"/> + +