Advertisement
Guest User

Untitled

a guest
Sep 21st, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.08 KB | None | 0 0
  1. -- CONFIGURATIONS
  2. local configurations    = {
  3.     ["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}}
  4. }
  5.  
  6. -- INITIALIZATION
  7. local keywordHandler    = KeywordHandler:new()
  8. local npcHandler        = NpcHandler:new(keywordHandler)
  9. NpcSystem.parseParameters(npcHandler)
  10. npcHandler:setMessage(MESSAGE_GREET, "Hi |PLAYERNAME|, are you looking for a {task} to do?")
  11. npcHandler:addModule(FocusModule:new())
  12.  
  13. -- INTERACTIONS
  14. function onCreatureAppear(cid)          npcHandler:onCreatureAppear(cid)            end
  15. function onCreatureDisappear(cid)       npcHandler:onCreatureDisappear(cid)         end
  16. function onCreatureSay(cid, type, msg)  npcHandler:onCreatureSay(cid, type, msg)    end
  17. function onThink()                      npcHandler:onThink()                        end
  18.  
  19. -- FUNCTIONS & INTERFACES
  20. function StdModule_getTasks(cid, message, keywords, parameters, node)
  21.     local npcHandler, message, count = parameters.npcHandler, "These are the tasks that I can offer you: ", 0
  22.     if(npcHandler == nil) then
  23.         print('StdModule.say called without any npcHandler instance.')
  24.         return false
  25.     end
  26.  
  27.     local onlyFocus = (parameters.onlyFocus == nil or parameters.onlyFocus == true)
  28.     if(not npcHandler:isFocused(cid) and onlyFocus) then
  29.         return false
  30.     end
  31.    
  32.     for title, task in pairs(configurations) do
  33.         if (getPlayerStorageValue(cid, task.storage) == -1 and getPlayerLevel(cid) >= task.require.level and getPlayerMagLevel(cid) >=
  34.         task.require.magiclevel and (task.require.storage == 0 or getPlayerStorageValue(cid, task.require.storage) ~= -1)) then
  35.             message = message .."{".. title .."},"
  36.             count = count + 1
  37.         end
  38.     end
  39.    
  40.     local parseInfo = {[TAG_PLAYERNAME] = getCreatureName(cid)}
  41.     if (count == 0) then
  42.         npcHandler:say(npcHandler:parseMessage("I don't have any task for you, sorry.", parseInfo), cid, parameters.publicize and true)
  43.     else
  44.         npcHandler:say(npcHandler:parseMessage(string.sub(message, 0, -2) ..".", parseInfo), cid, parameters.publicize and true)
  45.     end
  46. end
  47.  
  48. function StdModule_addTask(cid, message, keywords, parameters, node)
  49.     local npcHandler, title = parameters.npcHandler, node:getParent():getParameters().task
  50.     if(npcHandler == nil) then
  51.         print('StdModule.say called without any npcHandler instance.')
  52.         return false
  53.     end
  54.  
  55.     local onlyFocus = (parameters.onlyFocus == nil or parameters.onlyFocus == true)
  56.     if(not npcHandler:isFocused(cid) and onlyFocus) then
  57.         return false
  58.     end
  59.    
  60.     local parseInfo, task = {[TAG_PLAYERNAME] = getCreatureName(cid)}, configurations[title]
  61.     if (not task) then
  62.     elseif (getPlayerStorageValue(cid, task.storage) ~= -1) then
  63.         npcHandler:say(npcHandler:parseMessage('You have done or are currently doing this task.', parseInfo), cid, parameters.publicize and true)
  64.     elseif (getPlayerLevel(cid) < task.require.level) then
  65.         npcHandler:say(npcHandler:parseMessage('You have too little experience level.', parseInfo), cid, parameters.publicize and true)
  66.     elseif (getPlayerMagLevel(cid) < task.require.magiclevel) then
  67.         npcHandler:say(npcHandler:parseMessage('You have too little magic level.', parseInfo), cid, parameters.publicize and true)
  68.     elseif (task.require.storage ~= 0 and getPlayerStorageValue(cid, task.require.storage) == -1) then
  69.         npcHandler:say(npcHandler:parseMessage('This mission is not yet available for you.', parseInfo), cid, parameters.publicize and true)
  70.     else
  71.         local message = "The mission is kill: "
  72.         for index, monster in pairs(task.kill) do
  73.             doCreatureSetStorage(cid, task.storage + index, 0)
  74.             message = message .. monster.count .."x ".. monster.monster ..","
  75.         end
  76.         npcHandler:say(npcHandler:parseMessage(string.sub(message, 0, -2) ..".", parseInfo), cid, parameters.publicize and true)
  77.         doCreatureSetStorage(cid, task.storage, 0)
  78.     end
  79.     npcHandler:resetNpc()
  80. end
  81.  
  82. function StdModule_doFinishTasks(cid, message, keywords, parameters, node)
  83.     local npcHandler = parameters.npcHandler
  84.     if(npcHandler == nil) then
  85.         print('StdModule.say called without any npcHandler instance.')
  86.         return false
  87.     end
  88.  
  89.     local onlyFocus = (parameters.onlyFocus == nil or parameters.onlyFocus == true)
  90.     if(not npcHandler:isFocused(cid) and onlyFocus) then
  91.         return false
  92.     end
  93.    
  94.     local parseInfo = {[TAG_PLAYERNAME] = getCreatureName(cid)}
  95.     for title, task in pairs(configurations) do
  96.         if (getPlayerStorageValue(cid, task.storage) == 0) then
  97.             local accepted = 0
  98.             for index, monster in pairs(task.kill) do
  99.                 if (getPlayerStorageValue(cid, task.storage + index) == monster.count) then
  100.                     accepted = accepted + 1
  101.                 end
  102.             end
  103.             if (accepted == #task.kill) then
  104.                 for thing, count in pairs(task.rewards) do
  105.                     if (thing == "storage") then
  106.                         doCreatureSetStorage(cid, count, 0)
  107.                     elseif (thing == "experience") then
  108.                         doPlayerAddExperience(cid, count)
  109.                     else
  110.                         doPlayerAddItem(cid, thing, count)
  111.                     end
  112.                 end
  113.                 npcHandler:say(npcHandler:parseMessage('You have completed the task "'.. title ..'".', parseInfo), cid, parameters.publicize and true)
  114.                 doCreatureSetStorage(cid, task.storage, 1)
  115.             end
  116.         end
  117.     end
  118. end
  119.  
  120.  
  121. -- CONVERSATIONS
  122. local nodeYes  = KeywordNode:new({'yes'}, StdModule_addTask, {npcHandler = npcHandler, onlyFocus = true})
  123. local nodeNo   = KeywordNode:new({'no'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Well, forget about our conversation.', reset = true})
  124. local nodeTask = nil
  125. keywordHandler:addKeyword({'task'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'I am giving away the {task}. If you\'re willing to check out {list}.'})
  126. keywordHandler:addKeyword({'list'}, StdModule_getTasks, {npcHandler = npcHandler, onlyFocus = true})
  127. keywordHandler:addKeyword({'finish'}, StdModule_doFinishTasks, {npcHandler = npcHandler, onlyFocus = true})
  128. for title, task in pairs(configurations) do
  129.     nodeTask = keywordHandler:addKeyword({string.lower(title)}, StdModule.say, {task = title, npcHandler = npcHandler, onlyFocus = true, text = 'Would you like to do this task?'})
  130.     nodeTask:addChildKeywordNode(nodeNo) nodeTask:addChildKeywordNode(nodeYes)
  131. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement