It works if those items got inserted when the player was outside of logistics range at the time of insertion or if he walks out of range after insertion and then walks back in.
Code: Select all
function on_tick(event)
if event.tick % 120 == 0 then
for pi, player in pairs(game.players) do
if not player.valid or not player.connected or not global.config[player.name] then
break
end
for i, item in pairs(global.config[player.name]) do
if item.name == "" then
break
end
local stack = {name=item.name, count=1}
local count = player.get_item_count(item.name)
local desired = item.count
local diff = count - desired
if diff > 0 then
player.print(item.name.. ": " .. diff)
local trash = player.get_inventory(defines.inventory.player_trash)
for j=1,diff do
if trash.can_insert(stack) then
player.remove_item(stack)
trash.insert(stack)
end
end
end
end
end
end
end