Skip to content

Commit

Permalink
Support charges and bulk item creation by talkaction (otland#4350)
Browse files Browse the repository at this point in the history
Co-authored-by: Marcin Michalski <57528542+marmichalski@users.noreply.github.com>
  • Loading branch information
2 people authored and EPuncker committed May 23, 2023
1 parent c42ade8 commit fd8162f
Showing 1 changed file with 23 additions and 7 deletions.
30 changes: 23 additions & 7 deletions data/talkactions/scripts/create_item.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,31 +26,47 @@ function onSay(player, words, param)
return false
end

local keyNumber = 0
local count = tonumber(split[2])
local subType = 1
if not itemType:isStackable() and split[3] then
subType = math.max(1, tonumber(split[3]) or 1)
end

if count then
if itemType:isStackable() then
count = math.min(10000, math.max(1, count))
elseif not itemType:isFluidContainer() then
count = math.min(100, math.max(1, count))
if itemType:isFluidContainer() then
count = math.max(0, math.min(count, 99))
elseif itemType:isKey() then
keyNumber = count
count = 1
else
count = math.max(0, count)
count = math.min(10000, math.max(1, count))
end
else
if not itemType:isFluidContainer() then
count = 1
count = math.max(1, itemType:getCharges())
else
count = 0
end
end

local result = player:addItem(itemType:getId(), count)
local result = nil
if itemType:isStackable() then
result = player:addItem(itemType:getId(), count, true, subType)
else
result = player:addItem(itemType:getId(), subType, true, count)
end

if result then
if not itemType:isStackable() then
if type(result) == "table" then
for _, item in ipairs(result) do
item:decay()
end
else
if itemType:isKey() then
result:setAttribute(ITEM_ATTRIBUTE_ACTIONID, keyNumber)
end
result:decay()
end
end
Expand Down

0 comments on commit fd8162f

Please sign in to comment.