-- Including the Advanced NPC System
dofile('data/npc/lib/npcsystem/npcsystem.lua')
function msgcontains(message, keyword)
local message, keyword = message:lower(), keyword:lower()
if message == keyword then
return true
end
return message:find(keyword) and not message:find('(%w+)' .. keyword)
end
function doNpcSellItem(cid, itemid, amount, subType, ignoreCap, inBackpacks, backpack)
local amount = amount or 1
local subType = subType or 0
local item = 0
if ItemType(itemid):isStackable() then
if inBackpacks then
stuff = Game.createItem(backpack, 1)
item = stuff:addItem(itemid, math.min(100, amount))
else
stuff = Game.createItem(itemid, math.min(100, amount))
end
return Player(cid):addItemEx(stuff, ignoreCap) ~= RETURNVALUE_NOERROR and 0 or amount, 0
if itemId = 26384 then
item:setActionId(50501)
end
end
local a = 0
if inBackpacks then
local container, b = Game.createItem(backpack, 1), 1
for i = 1, amount do
local item = container:addItem(itemid, subType)
if table.contains({(ItemType(backpack):getCapacity() * b), amount}, i) then
if Player(cid):addItemEx(container, ignoreCap) ~= RETURNVALUE_NOERROR then
b = b - 1
break
end
a = i
if amount > i then
container = Game.createItem(backpack, 1)
b = b + 1
end
end
end
return a, b
end
for i = 1, amount do -- normal method for non-stackable items
local item = Game.createItem(itemid, subType)
if Player(cid):addItemEx(item, ignoreCap) ~= RETURNVALUE_NOERROR then
break
end
a = i
end
return a, 0
end