local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}
local hasItems = {}
local amuletStatus = 12000
local items = {
[1] = {8264, 1},
[2] = {8263, 1},
[3] = {8262, 1},
[4] = {8265, 1}
}
local wait = {
storage = 12001,
_time = 24 * 3600
}
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
function creatureSayCallback(cid, type, msg)
if(not npcHandler:isFocused(cid)) then
return false
end
local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
if(msgcontains(msg, 'amulet') and getCreatureStorage(cid, amuletStatus) <= 0) then
selfSay('Do you want me to forge all the amulet pieces?', cid)
talkState[talkUser] = 3
elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 3) then
hasItems[talkUser] = true
for _, data in ipairs(items) do
if(getPlayerItemCount(cid, data[1]) < data[2]) then
hasItems[talkUser] = false
end
end
if(hasItems[talkUser]) then
for _, data in ipairs(items) do
doPlayerRemoveItem(cid, data[1], data[2])
end
exhaustion.set(cid, wait.storage, wait._time)
doCreatureSetStorage(cid, amuletStatus, 2)
selfSay('Great, come back in 24 hours and ill have the amulet forged.', cid)
else
selfSay('You don\'t have required items.', cid)
end
hasItems[talkUser] = nil
talkState[talkUser] = nil
elseif(msgcontains(msg, 'amulet') and getCreatureStorage(cid, amuletStatus) == 2) then
if(not exhaustion.get(cid, wait.storage)) then
doSendMagicEffect(getCreaturePosition(cid), CONST_ME_MAGIC_GREEN)
doCreatureSetStorage(cid, amuletStatus, 3)
doPlayerAddItem(cid, 8266, 1)
selfSay('Just in time! Your amulet is forged and ready.', cid)
else
selfSay("Oh! you came sooner than i expected, I still need "..table.concat(string.timediff(exhaustion.get(cid, wait.storage))) ..".", cid)
end
end
return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())