Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local keywordHandler = KeywordHandler:new()
- local npcHandler = NpcHandler:new(keywordHandler)
- NpcSystem.parseParameters(npcHandler)
- local tasks =
- {
- }
- local taskSelected =
- {
- }
- 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 player = Player(cid)
- if (not npcHandler.topic[cid] or npcHandler.topic[cid] == 0) then
- if (msgcontains(msg, 'task')) then
- if (weeklyTaskSys:hasFinishedTaskToday(player)) then
- npcHandler:say("You have already done a task today.", cid)
- return false
- end
- if (weeklyTaskSys:hasStartedTask(player)) then
- npcHandler:say("You have already started a task.", cid)
- return false
- end
- local message = "Today you can kill %d %s or %d %s. What do you want to kill?"
- message = string.format(message, tasks[cid][1].amount, tasks[cid][1].name, tasks[cid][2].amount, tasks[cid][2].name)
- npcHandler:say(message, cid)
- npcHandler.topic[cid] = 1
- end
- elseif(npcHandler.topic[cid] == 1 ) then
- local monster = msg:lower()
- if (monster == tasks[cid][1].name) then
- taskSelected[cid] = tasks[cid][1]
- elseif (monster == tasks[cid][2].name) then
- taskSelected[cid] = tasks[cid][2]
- else
- npcHandler:say("Wrong monster name.", cid)
- return true
- end
- local message = "So do you want to kill %d %s?"
- message = string.format(message, taskSelected[cid].amount, taskSelected[cid].name)
- npcHandler:say(message, cid)
- npcHandler.topic[cid] = 2
- elseif(npcHandler.topic[cid] == 2) then
- if (msgcontains(msg, "yes")) then
- weeklyTaskSys:startTask(player, taskSelected[cid])
- local message = "You have started %s task!"
- message = string.format(message, taskSelected[cid].name)
- npcHandler:say(message, cid)
- npcHandler.topic[cid] = 0
- end
- end
- return true
- end
- local function greetCallback(cid)
- local player = Player(cid)
- local first, second = weeklyTaskSys:getAssignedTasks(player)
- if (first <= 0) then
- local generatedTasks = weeklyTaskSys:getRandomTasks(player)
- weeklyTaskSys:assignTasks(player, generatedTasks)
- tasks[cid] = generatedTasks
- else
- tasks[cid] = {}
- tasks[cid][1] = weeklyTaskSys:getTaskById(player, first)
- tasks[cid][2] = weeklyTaskSys:getTaskById(player, second)
- end
- print(tostring(tasks[cid][1]), tostring(tasks[cid][2]))
- return true
- end
- local function onReleaseFocus(cid)
- tasks[cid] = nil
- taskSelected[cid] = nil
- end
- npcHandler:setCallback(CALLBACK_GREET, greetCallback)
- npcHandler:setCallback(CALLBACK_ONRELEASEFOCUS, onReleaseFocus)
- npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
- npcHandler:addModule(FocusModule:new())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement