Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: create item talkaction for stackable items #1898

Merged
merged 2 commits into from
Nov 24, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions data/scripts/talkactions/god/create_item.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down