Okay, this time I think I found an actual bug. I can right click on the stocking as much as I want after it's filled and I keep adding the items to my inventory. Also if my active item in the hotbar is the same as what is in the stocking it won't add anything, or if the hotbar slot is empty, it will not get filled. Looking at the code it doesn't look like the inventory of the stocking is ever cleared.
This code snippet seems to fix the problem. I don't know what the leftover locals were for, and removing them and calling playerinv:add_item seemed to work just fine.
Code: Select all
elseif not inv:is_empty("main") then --stocking has something in it.
local item1 = inv:get_stack("main", 1)
local item2 = inv:get_stack("main", 2)
local item3 = inv:get_stack("main", 3)
playerinv:add_item("main", item1)
playerinv:add_item("main", item2)
playerinv:add_item("main", item3)
inv:set_stack("main", 1 ,'')
inv:set_stack("main", 2 ,'')
inv:set_stack("main", 3 ,'')
timer:start(5400)
This code doesn't check if the player inventory is full, but neither did the original. If the player inventory is full the items are lost and the clock is still restarted. There is a way to check if the items will fit in inventory, and if they don't they could either be dropped in world, or you could opt to not set the inventory empty. However if a player had two empty slots they could keep right clicking on the stocking and fill those two slots to 99 items because the stocking keeps giving items.