Project Zomboid

Project Zomboid

Mod Checker
Hilvon 30 Aug, 2024 @ 2:19pm
Tsar Common Library, Tuning2, Interactive trunk.fillingOnlyOne bug at full capacity
I am working on a mod that utilizes interactive trunk to add dummy tarp-covered cargo on top of SVU roof racks. And I found a bug in the code.
Relevant code is in lua\server\Tuning2\ATATuning2.lua line 384 and reads like this:

elseif modelInfo.interactiveTrunk.fillingOnlyOne then local tableSize = #modelInfo.interactiveTrunk.fillingOnlyOne for num, itemTrunkModel in ipairs(modelInfo.interactiveTrunk.fillingOnlyOne) do if num == math.floor(fillingRate * tableSize + 1) then part:setModelVisible(itemTrunkModel, true) end end end

The problem arises if the container in question is 100% full. In that case "fillrate * tableSize + 1" computes to tableSize + 1 and so none of the items iterated from the table get correct "num" value to become visible.

Also another minot issue is that value to compare num to gets recalculated on every iteration, while it is actually does not change between them.

A fixed code might look something like:
elseif modelInfo.interactiveTrunk.fillingOnlyOne then local tableSize = #modelInfo.interactiveTrunk.fillingOnlyOne local targetModelIndex = math.floor(fillingRate * tableSize + 1) if targetModelIndex > tableSize then targetModelIndex = tableSize end for num, itemTrunkModel in ipairs(modelInfo.interactiveTrunk.fillingOnlyOne) do if num == targetModelIndex then part:setModelVisible(itemTrunkModel, true) end end end

Thank you in advance.