Skip to content

Commit 781f61f

Browse files
Important fix v1.6.9
1 parent f630ee5 commit 781f61f

File tree

3 files changed

+25
-32
lines changed

3 files changed

+25
-32
lines changed

newmodels/client.lua

Lines changed: 23 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -257,33 +257,31 @@ function setElementCustomModel(element, elementType, id)
257257
return true
258258
end
259259

260-
function freeElementCustomMod(id)
260+
function freeElementCustomMod(id2)
261261

262-
local isCustom, mod, et2 = isCustomModID(id)
263-
if isTimer(atimers[id]) then killTimer(atimers[id]) end
264-
atimers[id] = setTimer(function()
262+
local isCustom, _, et2 = isCustomModID(id2)
263+
if isTimer(atimers[id2]) then killTimer(atimers[id2]) end
264+
265+
atimers[id2] = setTimer(function(id, et, en)
265266

267+
local dataName = dataNames[et]
266268
local allocated_id = allocated_ids[id]
267269
if not allocated_id then return end
268270

269-
local test1, test2
270-
local foundElement -- try to find an element to track
271+
local oneStreamedIn = false
271272

272-
for k, element in ipairs(getElementsByType(et2)) do
273-
local id2 = tonumber(getElementData(element, dataNames[et2]))
273+
-- check if no elements streamed in have that id
274+
for k, element in ipairs(getElementsByType(et)) do
275+
local id2 = tonumber(getElementData(element, dataName))
274276
if id2 and id2 == id then
275-
foundElement = element
276-
break
277+
if isElementStreamedIn(element) then
278+
oneStreamedIn = element
279+
break
280+
end
277281
end
278282
end
279283

280-
if isElement(foundElement) then
281-
test1 = ( not isElementStreamedIn(foundElement) )
282-
test2 = ( isElementStreamedIn(foundElement) and ((not getElementData(foundElement, dataName)) or getElementData(foundElement, dataName) ~= id) )
283-
end
284-
285-
286-
if (not isElement(foundElement)) or test1 or test2 then
284+
if not oneStreamedIn then
287285

288286
local worked = engineFreeModel(allocated_id)
289287

@@ -292,32 +290,26 @@ function freeElementCustomMod(id)
292290
r,g,b = 252, 44, 3
293291
end
294292

295-
if test1 then
296-
outputDebugString("["..(eventname or "?").."] Freed allocated ID "..allocated_id.." for mod ID "..id..": element not streamed in", 0, r,g,b)
297-
elseif test2 then
298-
outputDebugString("["..(eventname or "?").."] Freed allocated ID "..allocated_id.." for mod ID "..id..": element streamed in with different custom model or default model", r,g,b)
299-
else
300-
outputDebugString("["..(eventname or "?").."] Freed allocated ID "..allocated_id.." for mod ID "..id..": no element found", 0,r,g,b)
301-
end
293+
outputDebugString("["..(en or "?").."] Freed allocated ID "..allocated_id.." for mod ID "..id..": none streamed in", 0,r,g,b)
302294

303295
-- local count = 0
304296
for k, element in pairs(model_elements[allocated_id] or {}) do
305297
if isElement(element) then
306-
if destroyElement(element) then
298+
destroyElement(element)
299+
-- if destroyElement(element) then
307300
-- count = count + 1
308-
end
301+
-- end
309302
end
310303
end
311304
model_elements[allocated_id] = nil
312-
-- outputDebugString("["..(eventname or "?").."] Destroyed "..count.." dff/txd/col elements of allocated ID "..allocated_id, 0,227, 255, 117)
313-
314305
allocated_ids[id] = nil
315306
else
316-
-- outputDebugString("["..(eventname or "?").."] Not freeing allocated ID "..allocated_id.." for mod ID "..id, 0,227, 255, 117)
307+
-- outputDebugString("["..(en or "?").."] Not freeing allocated ID "..allocated_id.." for mod ID "..id, 0,227, 255, 117)
317308
end
318309

319310
atimers[id] = nil
320-
end, adelay, 1)
311+
312+
end, adelay, 1, id2, et2, eventName)
321313
end
322314

323315
function hasOtherElementsWithModel(element, id)
@@ -602,7 +594,7 @@ end
602594
function receiveModList(modList)
603595
received_modlist = modList
604596

605-
outputDebugString("Client received mod list", 0, 115, 236, 255)
597+
outputDebugString("Received mod list on client", 0, 115, 236, 255)
606598
triggerEvent(resName..":onMapListReceived", localPlayer) -- for other resources to handle
607599
-- iprint(modList)
608600

newmodels/meta.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<!-- DOCUMENTATION:
33
https://github.com/Fernando-A-Rocha/mta-add-models
44
-->
5-
<info author="Fernando" name="mta-add-models" description="minimalistic library for adding new models to your server" version="1.6.8" type="script"/>
5+
<info author="Fernando" name="mta-add-models" description="minimalistic library for adding new models to your server" version="1.6.9" type="script"/>
66

77
<!-- https://nightly.mtasa.com IMPORTANT TO HAVE THE VERSION SPECIFIED SO THAT ADDED MODELS WORK AS EXPECTED -->
88
<min_mta_version client="1.5.9-9.21125.0" server="1.5.9-9.21125.0"></min_mta_version>

newmodels/testing_client.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,7 @@ local dfont = "default-bold"
236236

237237
function drawAllocatedTable()
238238
local text = inspect(allocated_ids)
239+
text="Total: "..table.size(allocated_ids).."\n"..text
239240
local width = dxGetTextWidth(text, dfontsize, dfont)
240241
local x,y = sx/2 - width/2, 20
241242
dxDrawText(text, x,y,x,y, "0xffffffff", dfontsize, dfont)

0 commit comments

Comments
 (0)