Code:
function StdModule.buyContainer(cid, message, keywords, parameters, node)
local npcHandler = parameters.npcHandler
if(npcHandler == nil) then
error('StdModule.buyContainer called without any npcHandler instance.')
end
if(cid ~= npcHandler.focus and (parameters.onlyFocus == nil or parameters.onlyFocus == true)) then
return false
end
if getPlayerMoney(cid) >= parameters.cost then
local container = doPlayerAddItem(cid, parameters.containerId, 1)
if isContainer(container) == TRUE then
while getContainerCap(container) ~= 0 do
doAddContainerItem(container, parameters.runeId, parameters.runeCharges)
end
elseif container == LUA_ERROR then
container = doCreateItem(parameters.containerId, 1, getThingPos(cid))
if isContainer(container) == TRUE then
while getContainerCap(container) ~= 0 do
doAddContainerItem(container, parameters.runeId, parameters.runeCharges)
end
end
end
doPlayerRemoveMoney(cid, parameters.cost)
npcHandler:say('Here you are.')
else
npcHandler:say('You do not have enough money.')
end
return true
end
Example npc:
Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
-- OTServ event handling functions start
function onCreatureAppear(cid) npcHandler:onCreatureAppear(cid) end
function onCreatureDisappear(cid) npcHandler:onCreatureDisappear(cid) end
function onCreatureSay(cid, type, msg) npcHandler:onCreatureSay(cid, type, msg) end
function onThink() npcHandler:onThink() end
-- OTServ event handling functions end
local SDNode = keywordHandler:addKeyword({'bp sd', 'backpack of sd', 'backpack of sudden death'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Do you want to buy a backpack of sudden death runes for 6000 gold?'})
SDNode:addChildKeyword({'yes'}, StdModule.buyContainer, {npcHandler = npcHandler, onlyFocus = true, cost = 6000, containerId = 2000, runeId = 2216, runeCharges = 1})
SDNode:addChildKeyword({'no'}, StdModuel.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Ok, can I help you in anything else?'})
npcHandler:addModule(FocusModule:new())
Hope tis helps
Obs: The IDs might be wrong.