local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}
local xmsg = {}
local monster = ''
local storage = -1
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 greet(cid)
talkState[cid] = 0
return true
end
function getNpcName()
return getCreatureName(getNpcId())
end
-- this function returns a list of all the index values of tasks with a period at the end
function getListOfTasks(t, s)
local x = {}
for v, _ in pairs(t) do
table.insert(x, s and v .. s or v )
end
s = table.concat(x)
return s:sub(1, #s - 2)..'.'
end
-- the tasks table is constant its values never change
local tasks = {
["wasps"] = {storage = 45003, count = 51, experience = 1000, reward = 2160, rewardCount = 1},
["trolls"] = {storage = 45005, count = 51, experience = 1000, reward = 2160, rewardCount = 1},
["goblins"] = {storage = 45007, count = 51, experience = 1000, reward = 2160, rewardCount = 1},
["slimes"] = {storage = 45009, count = 51, experience = 1000, reward = 2160, rewardCount = 1},
["rotworms"] = {storage = 45011, count = 51, experience = 1000, reward = 2160, rewardCount = 1},
["amazons"] = {storage = 45013, count = 51, experience = 1000, reward = 2160, rewardCount = 1},
["valkyries"] = {storage = 45015, count = 51, experience = 1000, reward = 2160, rewardCount = 1},
["larva"] = {storage = 45017, count = 51, experience = 1000, reward = 2160, rewardCount = 1},
["orcs"] = {storage = 45019, count = 51, experience = 1000, reward = 2160, rewardCount = 1},
["dwarves"] = {storage = 45021, count = 51, experience = 1000, reward = 2160, rewardCount = 1},
["minotaurs"] = {storage = 45023, count = 51, experience = 1000, reward = 2160, rewardCount = 1},
["ghouls"] = {storage = 45025, count = 51, experience = 1000, reward = 2160, rewardCount = 1},
["scarabs"] = {storage = 45027, count = 51, experience = 1000, reward = 2160, rewardCount = 1},
["ancient scarabs"] = {storage = 45029, count = 51, experience = 1000, reward = 2160, rewardCount = 1},
["demons skeletons"] = {storage = 45031, count = 51, experience = 1000, reward = 2160, rewardCount = 1},
["cyclops"] = {storage = 45033, count = 51, experience = 1000, reward = 2160, rewardCount = 1},
["vampires"] = {storage = 45035, count = 51, experience = 1000, reward = 2160, rewardCount = 1},
["necromancers"] = {storage = 45037, count = 51, experience = 1000, reward = 2160, rewardCount = 1},
["giant spiders"] = {storage = 45039, count = 51, experience = 1000, reward = 2160, rewardCount = 1},
["dragons"] = {storage = 45041, count = 51, experience = 1000, reward = 2160, rewardCount = 1},
["dragon lords"] = {storage = 45043, count = 51, experience = 1000, reward = 2160, rewardCount = 1},
["demons"] = {storage = 45045, count = 51, experience = 1000, reward = 2160, rewardCount = 1}
}
function creatureSayCallback(cid, type, msg)
if(not npcHandler:isFocused(cid)) then
return false
end
local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
msg = msg:lower()
if msgcontains(msg, "task") then
selfSay("Tasks available: " ..getListOfTasks(tasks, ', '), cid)
elseif tasks[msg] then
storage = getPlayerStorageValue(cid, tasks[msg].storage)
monster = msg
if storage < 1 then
selfSay("Would like you like to start the ".. monster .." task?", cid)
talkState[talkUser] = 1
elseif storage >= 1 and storage < tasks[monster].count then
selfSay("You have not completed your task yet, you still need to kill " .. ((tasks[monster].count - 1) - storage ) .. ' of ' .. monster .. '.', cid)
talkState[talkUser] = 0
elseif storage == tasks[monster].count then
selfSay("You've completed the task of killing " .. (tasks[monster].count - 1) .. ' of ' .. monster .. '.', cid)
-- reset the task, so they can do it again
setPlayerStorageValue(cid, tasks[monster].storage, 0)
doPlayerAddExperience(cid, tasks[monster].experience)
doPlayerAddItem(cid, tasks[monster].reward, tasks[monster].rewardCount, true)
talkState[talkUser] = 0
end
elseif msgcontains(msg, "yes") and talkState[talkUser] == 1 then
selfSay("Great! Once you have killed ".. ( tasks[monster].count - 1 ) .." of ".. monster .." come back and see me.", cid)
setPlayerStorageValue(cid, tasks[monster].storage, 1)
-- maybe needed?
talkState[talkUser] = 0
end
talkState[talkUser] = 0
return true
end
npcHandler:setCallback(CALLBACK_GREET, greet)
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())