function ShopModule:addBuyableItem(names, itemid, cost, itemSubType, realName)
itemSubType = itemSubType or 1
local it = ItemType(itemid)
if it:getId() == 0 then
return -- Invalid item ID, simply return
end
local shopItem = self:getShopItem(itemid, itemSubType)
if shopItem == nil then
self.npcHandler.shopItems[#self.npcHandler.shopItems + 1] = {
id = itemid,
buy = cost,
sell = -1,
subType = itemSubType,
name = realName or it:getName()
}
else
shopItem.buy = cost
end
if names and SHOPMODULE_MODE ~= SHOPMODULE_MODE_TRADE then
for _, name in pairs(names) do
local parameters = {
itemid = itemid,
cost = cost,
module = self,
realName = realName or it:getName(),
subType = itemSubType or 1
}
local keywords = {name}
local node = self.npcHandler.keywordHandler:addKeyword(keywords, function(cid, message)
if string.match(message:lower(), "^sell") then
parameters.eventType = SHOPMODULE_SELL_ITEM
local shopItem = self:getShopItem(parameters.itemid, parameters.subType)
if shopItem and shopItem.sell > 0 then
parameters.cost = shopItem.sell
ShopModule.tradeItem(cid, message, keywords, parameters, node)
else
--self.npcHandler:say("I cannot buy this item from you.", cid)
end
else
parameters.eventType = SHOPMODULE_BUY_ITEM
local shopItem = self:getShopItem(parameters.itemid, parameters.subType)
if shopItem and shopItem.buy > 0 then
parameters.cost = shopItem.buy
ShopModule.tradeItem(cid, message, keywords, parameters, node)
else
self.npcHandler:say("I don't sell this item.", cid)
end
end
end, parameters)
node:addChildKeywordNode(self.yesNode)
node:addChildKeywordNode(self.noNode)
end
end
end