I had to update it a bit to not do anything if it returned nil as opening clams, etc returned errors.
Code:
local QuickSort;
do
local func = function(v1, v2)
if (v1 or v2 ~= nil) then
if v1[1] == 0 or v2[1] == 0 then -- Empty bag slot
return v1[1] > v2[1]; -- Put empty slots last
elseif v1[2] ~= v2[2] then
return v1[2] > v2[2]; -- Higher quality first
elseif v1[1] ~= v2[1] then
return v1[1] < v2[1];
else -- Compare stack counts
local _, c1 = GetContainerItemInfo(v1[3].bagID, v1[3].slotID);
local _, c2 = GetContainerItemInfo(v2[3].bagID, v2[3].slotID);
return c1 < c2;
end
end
end;
QuickSort = function(tbl) table.sort(tbl, func); end
end