diff --git a/data/scripts/talkactions/god/create_item.lua b/data/scripts/talkactions/god/create_item.lua index 7a6285ef101..723a7f047dd 100644 --- a/data/scripts/talkactions/god/create_item.lua +++ b/data/scripts/talkactions/god/create_item.lua @@ -23,16 +23,22 @@ function createItem.onSay(player, words, param) local count = tonumber(split[2]) if count then if itemType:isStackable() then - local item = Game.createItem(itemType:getId(), count) - if not item then - player:sendCancelMessage("Cannot create item") - return true - end + local stackSize = itemType:getStackSize() + local container = Game.createItem(2854) + local remainingCount = count - local ret = player:addItemEx(item, INDEX_WHEREEVER, FLAG_NOLIMIT) - if ret ~= RETURNVALUE_NOERROR then - player:sendCancelMessage(ret) + while remainingCount > 0 do + local countToAdd = math.min(remainingCount, stackSize) + local tmpItem = container:addItem(itemType:getId(), countToAdd, INDEX_WHEREEVER, FLAG_NOLIMIT) + if tmpItem then + remainingCount = remainingCount - countToAdd + else + logger.warn("Failed to add item: {}, to container", itemType:getName()) + end end + + player:addItemEx(container) + player:getPosition():sendMagicEffect(CONST_ME_MAGIC_GREEN) return true elseif not itemType:isFluidContainer() then local min = 100