Issue
when using LuaInventory::sort_and_merge on an ammo inventory, ammunition gets possibly sorted away from their intended weapons. the gui does not allow that.here an example with the player character and a tank.
this: becomes this:
How to reproduce
- load the supplied example save with a prepared tank and some weapons and ammo.
- execute the following command.
Code: Select all
/c local function sort_inventories(ntt) local get = ntt.get_inventory for n = 1,ntt.get_max_inventory_index(),1 do local i = get(n) if i and #i>0 then i.sort_and_merge() end end end sort_inventories(game.player.character) sort_inventories(game.player.vehicle)
- almost all weapons are unusable now since their ammo is in the wrong slot.
Bonus
After fixing the issue, this command intentionally breaks player ammo on first run by sorting weapons after ammo is sorted.A second run should then fix ammo again.
Code: Select all
/c local function sort_inventories(ntt)
local get = ntt.get_inventory
for n = ntt.get_max_inventory_index(),1,-1 do
local i = get(n)
if i and #i>0 then
i.sort_and_merge()
end
end
end
sort_inventories(game.player.character)
sort_inventories(game.player.vehicle)
if you can find a simple solution to link ammo slots to their weapons, i think nobody would complain.