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

Support charges and bulk item creation by talkaction #4350

Merged
merged 1 commit into from
Mar 17, 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
23 changes: 16 additions & 7 deletions data/talkactions/scripts/create_item.lua
Original file line number Diff line number Diff line change
Expand Up @@ -28,26 +28,35 @@ function onSay(player, words, param)

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))
if itemType:isFluidContainer() then
count = math.max(0, math.min(count, 99))
elseif itemType:isKey() then
keyNumber = count
count = 1
elseif not itemType:isFluidContainer() then
count = math.min(100, math.max(1, count))
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
Expand Down