Advertisement
Guest User

Untitled

a guest
Feb 24th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.30 KB | None | 0 0
  1. local keywordHandler = KeywordHandler:new()
  2. local npcHandler = NpcHandler:new(keywordHandler)
  3. NpcSystem.parseParameters(npcHandler)
  4.  
  5. local tasks =
  6. {
  7. }
  8. local taskSelected =
  9. {
  10.  
  11. }
  12.  
  13. function onCreatureAppear(cid) npcHandler:onCreatureAppear(cid) end
  14. function onCreatureDisappear(cid) npcHandler:onCreatureDisappear(cid) end
  15. function onCreatureSay(cid, type, msg) npcHandler:onCreatureSay(cid, type, msg) end
  16. function onThink() npcHandler:onThink() end
  17.  
  18. function creatureSayCallback(cid, type, msg)
  19.  
  20.  
  21. if not npcHandler:isFocused(cid) then
  22. return false
  23. end
  24. local player = Player(cid)
  25. if (not npcHandler.topic[cid] or npcHandler.topic[cid] == 0) then
  26. if (msgcontains(msg, 'task')) then
  27. if (weeklyTaskSys:hasFinishedTaskToday(player)) then
  28. npcHandler:say("You have already done a task today.", cid)
  29. return false
  30. end
  31.  
  32. if (weeklyTaskSys:hasStartedTask(player)) then
  33. npcHandler:say("You have already started a task.", cid)
  34. return false
  35. end
  36.  
  37. local message = "Today you can kill %d %s or %d %s. What do you want to kill?"
  38. message = string.format(message, tasks[cid][1].amount, tasks[cid][1].name, tasks[cid][2].amount, tasks[cid][2].name)
  39. npcHandler:say(message, cid)
  40. npcHandler.topic[cid] = 1
  41. end
  42. elseif(npcHandler.topic[cid] == 1 ) then
  43. local monster = msg:lower()
  44.  
  45. if (monster == tasks[cid][1].name) then
  46. taskSelected[cid] = tasks[cid][1]
  47. elseif (monster == tasks[cid][2].name) then
  48. taskSelected[cid] = tasks[cid][2]
  49. else
  50. npcHandler:say("Wrong monster name.", cid)
  51. return true
  52. end
  53.  
  54. local message = "So do you want to kill %d %s?"
  55. message = string.format(message, taskSelected[cid].amount, taskSelected[cid].name)
  56. npcHandler:say(message, cid)
  57. npcHandler.topic[cid] = 2
  58. elseif(npcHandler.topic[cid] == 2) then
  59. if (msgcontains(msg, "yes")) then
  60. weeklyTaskSys:startTask(player, taskSelected[cid])
  61. local message = "You have started %s task!"
  62. message = string.format(message, taskSelected[cid].name)
  63. npcHandler:say(message, cid)
  64. npcHandler.topic[cid] = 0
  65. end
  66. end
  67.  
  68. return true
  69. end
  70.  
  71. local function greetCallback(cid)
  72. local player = Player(cid)
  73.  
  74. local first, second = weeklyTaskSys:getAssignedTasks(player)
  75. if (first <= 0) then
  76. local generatedTasks = weeklyTaskSys:getRandomTasks(player)
  77. weeklyTaskSys:assignTasks(player, generatedTasks)
  78. tasks[cid] = generatedTasks
  79. else
  80. tasks[cid] = {}
  81. tasks[cid][1] = weeklyTaskSys:getTaskById(player, first)
  82. tasks[cid][2] = weeklyTaskSys:getTaskById(player, second)
  83. end
  84. print(tostring(tasks[cid][1]), tostring(tasks[cid][2]))
  85. return true
  86. end
  87.  
  88.  
  89.  
  90.  
  91. local function onReleaseFocus(cid)
  92. tasks[cid] = nil
  93. taskSelected[cid] = nil
  94.  
  95. end
  96.  
  97. npcHandler:setCallback(CALLBACK_GREET, greetCallback)
  98. npcHandler:setCallback(CALLBACK_ONRELEASEFOCUS, onReleaseFocus)
  99.  
  100. npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
  101. npcHandler:addModule(FocusModule:new())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement