adrianoswatt

Swatt TaskSystem NPC

Apr 1st, 2017
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 9.05 KB | None | 0 0
  1. local keywordHandler = KeywordHandler:new()
  2. local npcHandler = NpcHandler:new(keywordHandler)
  3. NpcSystem.parseParameters(npcHandler)
  4. local talkState = {}
  5.  
  6. function onCreatureAppear(cid) npcHandler:onCreatureAppear(cid) end
  7. function onCreatureDisappear(cid) npcHandler:onCreatureDisappear(cid) end
  8. function onCreatureSay(cid, type, msg) npcHandler:onCreatureSay(cid, type, msg) end
  9. function onThink() npcHandler:onThink() end
  10.  
  11. local taskList = _MONSTERS_TASK_SYSTEM_CONFIG
  12. local libcfg = _SETTING_TASK_SYSTEM_CONFIG
  13. function creatureSayCallback(cid, type, msg)
  14.     if(not npcHandler:isFocused(cid)) then
  15.     return false
  16.     end
  17.     local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
  18.  
  19.     --- [[  MENSAGENS PRIMÁRIAS  ]] ---
  20.     if (msgcontains(msg, 'task') or msgcontains(msg, 'tasks')) then
  21.         local str = ''
  22.         for index, result in pairs(taskList) do
  23.             str = str.."{"..index.."}, "
  24.         end
  25.         selfSay('Actually I have task for these monsters: '..str..'now tell me what monster you wanna do?', cid)
  26.         talkState[talkUser] = 1
  27.    
  28.     --- [[ CONSULTANDO RECOMPENSAS ]] ---
  29.     elseif (msgcontains(msg, 'awards') or msgcontains(msg, 'help')) then
  30.         selfSay('Tell me a monster name to know the awards.', cid)
  31.         talkState[talkUser] = 10
  32.    
  33.     --- [[ LISTANDO TASKS ]] ---
  34.     elseif (msgcontains(msg, 'consult') or msgcontains(msg, 'check')) then
  35.         getTask = checkPlayerIsInTask(cid)
  36.         if #getTask > 0 then
  37.             acTasks = doGiveTaskMonsterList(cid, getTask) -- Retorna Lista de Tasks Ativas como Texto
  38.             selfSay('This is your active task list: ['..acTasks..'].', cid)
  39.             talkState[talkUser] = 12
  40.         else
  41.             selfSay('You aren\'t in any task.', cid)
  42.             talkState[talkUser] = 0
  43.         end
  44.    
  45.     --- [[ CANCELANDO TASK ]] ---
  46.     elseif (msgcontains(msg, 'cancel') or msgcontains(msg, 'canceling')) then
  47.         getTask = checkPlayerIsInTask(cid)
  48.         if #getTask > 0 then
  49.             acTasks = doGiveTaskMonsterList(cid, getTask) -- Retorna Lista de Tasks Ativas como Texto
  50.             selfSay('This is your active task list: ['..acTasks..']. What task you wanna cancel?', cid)
  51.             talkState[talkUser] = 12
  52.         else
  53.             selfSay('You aren\'t in any task.', cid)
  54.             talkState[talkUser] = 0
  55.         end
  56.    
  57.     --- [[ CONCLUINDO TASKS ]] ---
  58.     elseif (msgcontains(msg, 'done') or msgcontains(msg, 'completed')) then
  59.         doneTask = doPlayerDonePersoTask(cid)
  60.         if doneTask then
  61.             confer = taskList[doneTask]
  62.             if confer then
  63.                 killeds = tonumber(getPlayerStorageValue(cid, confer.countSto))
  64.                 if killeds >= tonumber(confer.count) then
  65.                     --[[ Givin' The Awards ]]--
  66.                     doGiveTaskAwards(cid, confer.awards)
  67.                     --[[ Resetin' Values ]]--
  68.                     inativo = 0
  69.                     getInfo = getInfoPlayerTask(cid, doneTask)
  70.                     repet = getInfo[1] + 1
  71.                     newValue = "&"..inativo.."/"..repet.."/0"
  72.                     setPlayerStorageValue(cid, confer.storage, newValue)
  73.                     setPlayerStorageValue(cid, confer.countSto, 0)
  74.                     --[[ Sendin' Message ]]--
  75.                     getAwardList = getAwardsList(cid, confer.awards)
  76.                     selfSay('Congratulations, you have done the {'..doneTask..' task} and received: '..getAwardList..'.', cid)
  77.                     talkState[talkUser] = 0
  78.                 else
  79.                     selfSay('Sorry, you have killed '..killeds..' of '..confer.count..' '..doneTask..', go kill more '..(confer.count-killeds)..'.', cid)
  80.                     talkState[talkUser] = 0
  81.                 end
  82.             else
  83.                 selfSay('Sorry, but some error occurred with your task, contact to administrator.', cid)
  84.                 talkState[talkUser] = 0
  85.             end
  86.         else
  87.             selfSay('You don\'t have done any task.', cid)
  88.             talkState[talkUser] = 0
  89.         end
  90.  
  91.     --- [[  NEGOCIAÇÃO & CONFIRMAÇÃO  ]] ---
  92.     elseif talkState[talkUser] == 1 then
  93.         getMonster = taskList[msg:lower()]
  94.         if getMonster then
  95.             mMonster = msg:lower()
  96.             mCount = getMonster.count
  97.             mPrice = getMonster.price
  98.             mSto = getMonster.storage
  99.             mCountSto = getMonster.countSto
  100.             repetMax = getMonster.repeated
  101.             getAwardList = getAwardsList(cid, getMonster.awards)
  102.             if getMonster.inDay then -- Task com Tempo
  103.                 selfSay('Alright, in this task you have to kill {'..mCount..' '..mMonster..' in '..getMonster.inDay..' day(s)}, your award is '..getAwardList..' and will {cost '..mPrice..' gold coins}, do you wanna try?', cid)
  104.             else
  105.                 selfSay('Alright, in this task you have to kill {'..mCount..' '..mMonster..'}, your award is '..getAwardList..' and will {cost '..mPrice..' gold coins}, do you wanna try?', cid)
  106.             end
  107.             talkState[talkUser] = 2
  108.         else
  109.             selfSay('I\'m sorry, this monster isn\'t in my task system.', cid)
  110.             talkState[talkUser] = 1
  111.         end
  112.        
  113.     elseif talkState[talkUser] == 2 then
  114.         if (msgcontains(msg, 'sim') or msgcontains(msg, 'yes')) then
  115.             checkTask = checkPlayerIsInTask(cid) -- Retorna Lista de Tasks Ativas
  116.             acTasks = doGiveTaskMonsterList(cid, checkTask) -- Retorna Lista de Tasks Ativas como Texto
  117.             if #checkTask < libcfg.taskAtSameTime then
  118.                 getInfo = getInfoPlayerTask(cid, mMonster)
  119.                 if not getInfo or getInfo[1] < repetMax then
  120.                     getDoingTask = checkAlreadyDoingThisTask(cid, mMonster, checkTask)
  121.                     if not getDoingTask then
  122.                         if #checkTask > 0 then
  123.                             selfSay('Okay, actually you have '..acTasks..' task actives ['..#checkTask..'/'..libcfg.taskAtSameTime..']. Do you wanna active the {'..mMonster..' task} payin\' {'..mPrice..' gold coins}?', cid)
  124.                         else
  125.                             selfSay('Okay, do you wanna continue with the task and payin\' '..mPrice..' gold coins?', cid)
  126.                         end
  127.                         talkState[talkUser] = 3
  128.                     else
  129.                         selfSay('Sorry, but the {'..mMonster..'} task already is active.', cid)
  130.                         talkState[talkUser] = 0
  131.                     end
  132.                 else
  133.                     selfSay('Sorry, but you have done {'..mMonster..'} task for '..getInfo[1]..' times.', cid)
  134.                     talkState[talkUser] = 0
  135.                 end
  136.             else
  137.                 selfSay('Sorry, but you have '..acTasks..' task(s) actives, the limit of task actives at same time is '..libcfg.taskAtSameTime..', go done it.', cid)
  138.                 talkState[talkUser] = 0
  139.             end
  140.         elseif (msgcontains(msg, 'not') or msgcontains(msg, 'no')) then
  141.             selfSay('Okay, see u later.', cid)
  142.             talkState[talkUser] = 0
  143.         else
  144.             selfSay('Can I help you? Say {task} again if I do.', cid)
  145.             talkState[talkUser] = 0
  146.         end
  147.    
  148.     elseif talkState[talkUser] == 3 then
  149.         if (msgcontains(msg, 'sim') or msgcontains(msg, 'yes')) then
  150.             if doPlayerRemoveMoney(cid, mPrice) then
  151.                 ativo = 1
  152.                 if not getInfo then
  153.                     repet = 0
  154.                 else
  155.                     repet = getInfo[1]
  156.                 end
  157.                 if not getMonster.inDay then
  158.                     newValue = "&"..ativo.."/"..repet.."/0"
  159.                     selfSay('Congratulations, you have started the {'..mMonster..'} task, go kill {'..mCount..'} and come back.', cid)
  160.                 else
  161.                     finalDate = (os.time() + (86400 * getMonster.inDay))
  162.                     newValue = "&"..ativo.."/"..repet.."/"..finalDate..""
  163.                     selfSay('Congratulations, you have started the {'..mMonster..'} task, go kill {'..mCount..'} untill {'..os.date("%b %d, %Y at %X", finalDate)..'} and come back.', cid)
  164.                 end
  165.                 setPlayerStorageValue(cid, mSto, newValue)
  166.                 setPlayerStorageValue(cid, mCountSto, 0)
  167.                 talkState[talkUser] = 0
  168.             else
  169.                 selfSay('Sorry, but you don\'t have money enough.', cid)
  170.                 talkState[talkUser] = 0
  171.             end
  172.         else
  173.             selfSay('Okay, see u later.', cid)
  174.             talkState[talkUser] = 0
  175.         end
  176.  
  177.     --- [[  INFORMAÇÕES DE TASKS  ]] ---
  178.     elseif talkState[talkUser] == 10 then
  179.         getMonster = taskList[msg:lower()]
  180.         if getMonster then
  181.             getAwardList = getAwardsList(cid, getMonster.awards)
  182.             if getMonster.inDay then
  183.                 selfSay('Alright, killing {'..getMonster.count..' '..msg:lower()..'s in '..getMonster.inDay..' day(s)} payin\' {'..getMonster.price..' gold coins} give you the follow awards: '..getAwardList..'.', cid)
  184.             else
  185.                 selfSay('Alright, killing {'..getMonster.count..' '..msg:lower()..'s} payin\' {'..getMonster.price..' gold coins} give you the follow awards: '..getAwardList..'.', cid)
  186.             end
  187.             talkState[talkUser] = 0
  188.         else
  189.             selfSay('I\'m sorry, this monster isn\'t in my task system.', cid)
  190.             talkState[talkUser] = 10
  191.         end
  192.        
  193.     --- [[  CANCELANDO TASKS  ]] ---
  194.     elseif talkState[talkUser] == 12 then
  195.         monst = msg:lower()
  196.         saying = taskList[monst]
  197.         if saying then
  198.             checkTask = checkPlayerIsInTask(cid) -- Retorna Lista de Tasks Ativas
  199.             checking = checkAlreadyDoingThisTask(cid, monst, checkTask)
  200.             if checking then
  201.                 selfSay('You are sure that you wanna cancel the {'..monst..' task}?', cid)
  202.                 talkState[talkUser] = 13
  203.             else
  204.                 selfSay('I\'m sorry, you don\'t have this task active right now.', cid)
  205.                 talkState[talkUser] = 0
  206.             end        
  207.         else
  208.             selfSay('I\'m sorry, this monster isn\'t in my task system.', cid)
  209.             talkState[talkUser] = 12
  210.         end
  211.    
  212.     --- [[  CANCELANDO TASKS  ]] ---
  213.     elseif talkState[talkUser] == 13 then
  214.         if (msgcontains(msg, 'sim') or msgcontains(msg, 'yes')) then
  215.             inf = getInfoPlayerTask(cid, monst)
  216.             doCloseTimedTask(cid, monst)
  217.             selfSay('Congratulations, your {'..monst..' task} has been cancelled succesfully.', cid)
  218.             talkState[talkUser] = 0        
  219.         else
  220.             selfSay('Ok, I see you later.', cid)
  221.             talkState[talkUser] = 0
  222.         end
  223.        
  224.     end
  225. return true
  226. end
  227. npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
  228. npcHandler:addModule(FocusModule:new())
Advertisement
Add Comment
Please, Sign In to add comment