local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local Topic = {}
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 config = {
item1 = 5901,
item2 = 5902,
timeX = 10, -- Seconds per item
delayStorage = 50530, -- empty storage value delay time
branchCount = 50531, -- empty storage value for branch count
}
local function creatureSayCallback(cid, type, msg)
if not npcHandler:isFocused(cid) then
return false
end
local itemCount = getPlayerItemCount(cid, config.item1)
if msgcontains(msg, "convert") then
npcHandler:say("Would you like to convert {item1} into {item2}?", cid)
Topic[cid] = 1
elseif msgcontains(msg, "pickup") then
if getPlayerStorageValue(cid, config.branchCount) > 0 then
if getPlayerStorageValue(cid, config.delayStorage) > os.time() then
npcHandler:say("Please come back later I need more time. Come back in ".. (getPlayerStorageValue(cid, config.delayStorage) - os.time()) .." seconds.", cid)
Topic[cid] = 0
else
npcHandler:say("Ah yes here are your ".. getPlayerStorageValue(cid, config.branchCount) .." branches.", cid)
doPlayerAddItem(cid, config.item2, getPlayerStorageValue(cid, config.branchCount))
setPlayerStorageValue(cid, config.branchCount, 0)
end
else
npcHandler:say("I'm sorry you don't have any items to be picked up.", cid)
Topic[cid] = 0
end
elseif msgcontains(msg, "yes") then
if itemCount < 1 then
npcHandler:say("I'm sorry you don't have any items to convert.", cid)
Topic[cid] = 0
else
npcHandler:say("It will take ".. (itemCount * 10) .." seconds to convert these items. Please check back later.", cid)
doPlayerRemoveItem(cid, config.item1, itemCount)
setPlayerStorageValue(cid, config.delayStorage, os.time() + (itemCount * 10))
setPlayerStorageValue(cid, config.branchCount, itemCount)
Topic[cid] = 0
end
elseif msgcontains(msg, "no") then
if Topic[cid] > 1 then
npcHandler:say("Then no.", cid)
Topic[cid] = 0
end
return true
end
end
npcHandler:setMessage(MESSAGE_GREET, "Welcome to my adventurer shop, |PLAYERNAME|! Would you like to {convert} or {pickup} any items?")
npcHandler:setMessage(MESSAGE_FAREWELL, "Good bye, |PLAYERNAME|.")
npcHandler:setMessage(MESSAGE_WALKAWAY, "Good bye.")
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())