Spoiler function cleanitems()
for k,v in pairs (GROUNDITEMS) do
local x,y,height
for a,b in pairs (v) do
for c,d in pairs (b) do
d[4] = d[4] -1
y=k
x=a
height=c
if d[4] <= 0 and not TILEZONE[y][x].HOUSE then
local item = d
if item[1] == 1337 then
if item[2] then freeimage(item[2]) end
GROUNDITEMS[y][x][height] = nil
else
local tile = gettile(x*32, y*32)
if tile.HEAL and ITEMS[item[1]].heal then
tile.HEAL = tile.HEAL - ITEMS[item[1]].heal
if tile.HEAL == 0 then
tile.HEAL = nil
end
end
if item[2] then freeimage(item[2]) end
GROUNDITEMS[y][x][height] = nil
end
end
end
end
end
end