Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- CONFIGURATIONS
- local configurations = {
- ["Rats"] = {storage = 1010, kill = {[1] = {monster = "Rat", count = 50}, [2] = {monster = "Cave Rat", count = 10}}, require = {level = 1, magiclevel = 0, storage = 0}, rewards = {[2152] = 5, ["storage"] = 1000, ["experience"] = 1000}}
- }
- -- INITIALIZATION
- local keywordHandler = KeywordHandler:new()
- local npcHandler = NpcHandler:new(keywordHandler)
- NpcSystem.parseParameters(npcHandler)
- npcHandler:setMessage(MESSAGE_GREET, "Hi |PLAYERNAME|, are you looking for a {task} to do?")
- npcHandler:addModule(FocusModule:new())
- -- INTERACTIONS
- 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
- -- FUNCTIONS & INTERFACES
- function StdModule_getTasks(cid, message, keywords, parameters, node)
- local npcHandler, message, count = parameters.npcHandler, "These are the tasks that I can offer you: ", 0
- if(npcHandler == nil) then
- print('StdModule.say called without any npcHandler instance.')
- return false
- end
- local onlyFocus = (parameters.onlyFocus == nil or parameters.onlyFocus == true)
- if(not npcHandler:isFocused(cid) and onlyFocus) then
- return false
- end
- for title, task in pairs(configurations) do
- if (getPlayerStorageValue(cid, task.storage) == -1 and getPlayerLevel(cid) >= task.require.level and getPlayerMagLevel(cid) >=
- task.require.magiclevel and (task.require.storage == 0 or getPlayerStorageValue(cid, task.require.storage) ~= -1)) then
- message = message .."{".. title .."},"
- count = count + 1
- end
- end
- local parseInfo = {[TAG_PLAYERNAME] = getCreatureName(cid)}
- if (count == 0) then
- npcHandler:say(npcHandler:parseMessage("I don't have any task for you, sorry.", parseInfo), cid, parameters.publicize and true)
- else
- npcHandler:say(npcHandler:parseMessage(string.sub(message, 0, -2) ..".", parseInfo), cid, parameters.publicize and true)
- end
- end
- function StdModule_addTask(cid, message, keywords, parameters, node)
- local npcHandler, title = parameters.npcHandler, node:getParent():getParameters().task
- if(npcHandler == nil) then
- print('StdModule.say called without any npcHandler instance.')
- return false
- end
- local onlyFocus = (parameters.onlyFocus == nil or parameters.onlyFocus == true)
- if(not npcHandler:isFocused(cid) and onlyFocus) then
- return false
- end
- local parseInfo, task = {[TAG_PLAYERNAME] = getCreatureName(cid)}, configurations[title]
- if (not task) then
- elseif (getPlayerStorageValue(cid, task.storage) ~= -1) then
- npcHandler:say(npcHandler:parseMessage('You have done or are currently doing this task.', parseInfo), cid, parameters.publicize and true)
- elseif (getPlayerLevel(cid) < task.require.level) then
- npcHandler:say(npcHandler:parseMessage('You have too little experience level.', parseInfo), cid, parameters.publicize and true)
- elseif (getPlayerMagLevel(cid) < task.require.magiclevel) then
- npcHandler:say(npcHandler:parseMessage('You have too little magic level.', parseInfo), cid, parameters.publicize and true)
- elseif (task.require.storage ~= 0 and getPlayerStorageValue(cid, task.require.storage) == -1) then
- npcHandler:say(npcHandler:parseMessage('This mission is not yet available for you.', parseInfo), cid, parameters.publicize and true)
- else
- local message = "The mission is kill: "
- for index, monster in pairs(task.kill) do
- doCreatureSetStorage(cid, task.storage + index, 0)
- message = message .. monster.count .."x ".. monster.monster ..","
- end
- npcHandler:say(npcHandler:parseMessage(string.sub(message, 0, -2) ..".", parseInfo), cid, parameters.publicize and true)
- doCreatureSetStorage(cid, task.storage, 0)
- end
- npcHandler:resetNpc()
- end
- function StdModule_doFinishTasks(cid, message, keywords, parameters, node)
- local npcHandler = parameters.npcHandler
- if(npcHandler == nil) then
- print('StdModule.say called without any npcHandler instance.')
- return false
- end
- local onlyFocus = (parameters.onlyFocus == nil or parameters.onlyFocus == true)
- if(not npcHandler:isFocused(cid) and onlyFocus) then
- return false
- end
- local parseInfo = {[TAG_PLAYERNAME] = getCreatureName(cid)}
- for title, task in pairs(configurations) do
- if (getPlayerStorageValue(cid, task.storage) == 0) then
- local accepted = 0
- for index, monster in pairs(task.kill) do
- if (getPlayerStorageValue(cid, task.storage + index) == monster.count) then
- accepted = accepted + 1
- end
- end
- if (accepted == #task.kill) then
- for thing, count in pairs(task.rewards) do
- if (thing == "storage") then
- doCreatureSetStorage(cid, count, 0)
- elseif (thing == "experience") then
- doPlayerAddExperience(cid, count)
- else
- doPlayerAddItem(cid, thing, count)
- end
- end
- npcHandler:say(npcHandler:parseMessage('You have completed the task "'.. title ..'".', parseInfo), cid, parameters.publicize and true)
- doCreatureSetStorage(cid, task.storage, 1)
- end
- end
- end
- end
- -- CONVERSATIONS
- local nodeYes = KeywordNode:new({'yes'}, StdModule_addTask, {npcHandler = npcHandler, onlyFocus = true})
- local nodeNo = KeywordNode:new({'no'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Well, forget about our conversation.', reset = true})
- local nodeTask = nil
- keywordHandler:addKeyword({'task'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'I am giving away the {task}. If you\'re willing to check out {list}.'})
- keywordHandler:addKeyword({'list'}, StdModule_getTasks, {npcHandler = npcHandler, onlyFocus = true})
- keywordHandler:addKeyword({'finish'}, StdModule_doFinishTasks, {npcHandler = npcHandler, onlyFocus = true})
- for title, task in pairs(configurations) do
- nodeTask = keywordHandler:addKeyword({string.lower(title)}, StdModule.say, {task = title, npcHandler = npcHandler, onlyFocus = true, text = 'Would you like to do this task?'})
- nodeTask:addChildKeywordNode(nodeNo) nodeTask:addChildKeywordNode(nodeYes)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement