local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
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
local function greetCallback(cid)
npcHandler.topic[cid] = 0
return true
end
local playerResponse = {}
local combinationItems = {2461, 2467} -- itemId's
local resultItem = 2173 -- itemId
local function creatureSayCallback(cid, type, msg)
if not npcHandler:isFocused(cid) then
return false
end
local player = Player(cid)
if msgcontains(msg, "combine") then
npcHandler:say("How many " .. ItemType(combinationItems[1]):getPluralName() .. " and " .. ItemType(combinationItems[2]):getPluralName() .. " would you like to combine?", cid)
npcHandler.topic[cid] = 1
elseif npcHandler.topic[cid] == 1 then
local amount = tonumber(msg)
if amount == nil or amount < 1 then
npcHandler:say("That is not an amount I am familiar with. Can you translate {" .. msg .. "} into my local currency?", cid)
return true
end
npcHandler:say("Are you sure you would like to combine " .. msg .. " of each these items into " .. msg .. " " .. ItemType(resultItem):getPluralName() .. "? This process cannot be undone.", cid)
npcHandler.topic[cid] = 2
playerResponse[cid].amount = amount
elseif npcHandler.topic[cid] == 2 then
if not msgcontains(msg, "yes") then
npcHandler:say("Another time, then.", cid)
npcHandler.topic[cid] = 0
playerResponse[cid] = {}
return true
end
for i = 1, 2 do
if player:getItemCount(combinationItems[i]) < playerResponse[cid].amount then
npcHandler:say("You don't seem to have enough " .. ItemType(combinationItems[i]):getPluralName() .. " in your inventory for this transaction. How many were you wanting to combine today?", cid)
npcHandler.topic[cid] = 1
playerResponse[cid] = {}
return true
end
end
for i = 1, 2 do
player:removeItem(combinationItems[i], playerResponse[cid].amount)
end
player:addItem(resultItem, playerResponse[cid].amount, true)
npcHandler:say("Great! The items have all been combined into " .. playerResponse[cid].amount .. " " .. ItemType(resultItem):getPluralName() .. ". Let me know if you want to combine more items in the future!", cid)
npcHandler.topic[cid] = 0
playerResponse[cid] = {}
end
return true
end
local function onAddFocus(cid)
playerResponse[cid] = {}
end
local function onReleaseFocus(cid)
playerResponse[cid] = nil
end
npcHandler:setCallback(CALLBACK_ONADDFOCUS, onAddFocus)
npcHandler:setCallback(CALLBACK_ONRELEASEFOCUS, onReleaseFocus)
npcHandler:setMessage(MESSAGE_GREET, "Welcome back |PLAYERNAME|. Are you looking to {combine} some items today?")
npcHandler:setCallback(CALLBACK_GREET, greetCallback)
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())