Advertisement
Guest User

Untitled

a guest
Aug 21st, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.24 KB | None | 0 0
  1. -- Monster Tasks by Limos
  2. local keywordHandler = KeywordHandler:new()
  3. local npcHandler = NpcHandler:new(keywordHandler)
  4. NpcSystem.parseParameters(npcHandler)
  5. local xmsg = {}
  6.  
  7. function onCreatureAppear(cid) npcHandler:onCreatureAppear(cid) end
  8. function onCreatureDisappear(cid) npcHandler:onCreatureDisappear(cid) end
  9. function onCreatureSay(cid, type, msg) npcHandler:onCreatureSay(cid, type, msg) end
  10. function onThink() npcHandler:onThink() end
  11.  
  12. local storage = 62003
  13.  
  14. local monsters = {
  15. ["Fallen"] = {
  16. storage = 5010,
  17. mstorage = 19000,
  18. amount = 3,
  19. exp = 5000,
  20. items = {
  21. {
  22. id = 2157,
  23. count = 1
  24. },
  25. {
  26. id = 2160,
  27. count = 3
  28. }
  29. }
  30. },
  31. ["Quill Rat"] = {
  32. storage = 5010,
  33. mstorage = 19000,
  34. amount = 3,
  35. exp = 5000,
  36. items = {
  37. {
  38. id = 2157,
  39. count = 1
  40. },
  41. {
  42. id = 2160,
  43. count = 3
  44. }
  45. }
  46. },
  47. }
  48.  
  49.  
  50. local function getItemsFromTable(itemtable)
  51. local text = ""
  52. for v = 1, #itemtable do
  53. count, info = itemtable[v].count, ItemType(itemtable[v].id)
  54. local ret = ", "
  55. if v == 1 then
  56. ret = ""
  57. elseif v == #itemtable then
  58. ret = " and "
  59. end
  60. text = text .. ret
  61. text = text .. (count > 1 and count or info:getArticle()).." "..(count > 1 and info:getPluralName() or info:getName())
  62. end
  63. return text
  64. end
  65.  
  66. local function Cptl(f, r)
  67. return f:upper()..r:lower()
  68. end
  69.  
  70. function creatureSayCallback(cid, type, msg)
  71.  
  72. local player, cmsg = Player(cid), msg:gsub("(%a)([%w_']*)", Cptl)
  73. if not npcHandler:isFocused(cid) then
  74. if msg == "hi" or msg == "hello" then
  75. npcHandler:addFocus(cid)
  76. if player:getStorageValue(storage) == -1 then
  77. local text, n = "", 0
  78. for k, x in pairs(monsters) do
  79. if player:getStorageValue(x.mstorage) < x.amount then
  80. n = n + 1
  81. text = text .. ", "
  82. text = text .. ""..x.amount.." {"..k.."}"
  83. end
  84. end
  85. if n > 1 then
  86. npcHandler:say("I have several tasks for you to kill monsters"..text..", which one do you choose? I can also show you a {list} with rewards and you can {stop} a task if you want.", cid)
  87. npcHandler.topic[cid] = 1
  88. xmsg[cid] = msg
  89. elseif n == 1 then
  90. npcHandler:say("I have one last task for you"..text..".", cid)
  91. npcHandler.topic[cid] = 1
  92. else
  93. npcHandler:say("You already did all tasks, I have nothing for you to do anymore, good job though.", cid)
  94. end
  95. elseif player:getStorageValue(storage) == 1 then
  96. for k, x in pairs(monsters) do
  97. if player:getStorageValue(x.storage) == 1 then
  98. npcHandler:say("Did you kill "..x.amount.." "..k.."?", cid)
  99. npcHandler.topic[cid] = 2
  100. xmsg[cid] = k
  101. end
  102. end
  103. end
  104. else
  105. return false
  106. end
  107. elseif monsters[cmsg] and npcHandler.topic[cid] == 1 then
  108. if player:getStorageValue(monsters[cmsg].storage) == -1 then
  109. npcHandler:say("Good luck, come back when you killed "..monsters[cmsg].amount.." "..cmsg..".", cid)
  110. player:setStorageValue(storage, 1)
  111. player:setStorageValue(monsters[cmsg].storage, 1)
  112. else
  113. npcHandler:say("You already did the "..cmsg.." mission.", cid)
  114. end
  115. npcHandler.topic[cid] = 0
  116. elseif msgcontains(msg, "yes") and npcHandler.topic[cid] == 2 then
  117. local x = monsters[xmsg[cid]]
  118. if player:getStorageValue(x.mstorage) >= x.amount then
  119. npcHandler:say("Good job, here is your reward, "..getItemsFromTable(x.items)..".", cid)
  120. for g = 1, #x.items do
  121. player:addItem(x.items[g].id, x.items[g].count)
  122. end
  123. player:addExperience(x.exp)
  124. player:setStorageValue(x.storage, 2)
  125. player:setStorageValue(storage, -1)
  126. npcHandler.topic[cid] = 3
  127. else
  128. npcHandler:say("You didn't kill them all, you still need to kill "..x.amount -(player:getStorageValue(x.mstorage) + 1).." "..xmsg[cid]..".", cid)
  129. end
  130. elseif msgcontains(msg, "task") and npcHandler.topic[cid] == 3 then
  131. local text, n = "", 0
  132. for k, x in pairs(monsters) do
  133. if player:getStorageValue(x.mstorage) < x.amount then
  134. n = n + 1
  135. text = text .. (n == 1 and "" or ", ")
  136. text = text .. "{"..k.."}"
  137. end
  138. end
  139. if text ~= "" then
  140. npcHandler:say("Want to do another task? You can choose "..text..".", cid)
  141. npcHandler.topic[cid] = 1
  142. else
  143. npcHandler:say("You already did all tasks.", cid)
  144. end
  145. elseif msgcontains(msg, "no") and npcHandler.topic[cid] == 1 then
  146. npcHandler:say("Ok then.", cid)
  147. npcHandler.topic[cid] = 0
  148. elseif msgcontains(msg, "stop") then
  149. local text, n = "", 0
  150. for k, x in pairs(monsters) do
  151. if player:getStorageValue(x.mstorage) < x.amount then
  152. n = n + 1
  153. text = text .. (n == 1 and "" or ", ")
  154. text = text .. "{"..k.."}"
  155. if player:getStorageValue(x.storage) == 1 then
  156. player:setStorageValue(x.storage, -1)
  157. end
  158. end
  159. end
  160. if player:getStorageValue(storage) == 1 then
  161. npcHandler:say("Alright, let me know if you want to continue an other task, you can still choose "..text..".", cid)
  162. else
  163. npcHandler:say("You didn't start any new task yet, if you want to start one, you can choose "..text..".", cid)
  164. end
  165. player:setStorageValue(storage, -1)
  166. npcHandler.topic[cid] = 1
  167. elseif msgcontains(msg, "list") then
  168. local text = "Tasks\n\n"
  169. for k, x in pairs(monsters) do
  170. if player:getStorageValue(x.mstorage) < x.amount then
  171. text = text ..k .." ["..(player:getStorageValue(x.mstorage) + 1).."/"..x.amount.."]:\n Rewards:\n "..getItemsFromTable(x.items).."\n "..x.exp.." experience \n\n"
  172. else
  173. text = text .. k .." [DONE]\n"
  174. end
  175. end
  176. player:showTextDialog(1949, "" .. text)
  177. npcHandler:say("Here you are.", cid)
  178. elseif msgcontains(msg, "bye") then
  179. npcHandler:say("Bye.", cid)
  180. npcHandler:releaseFocus(cid)
  181. else
  182. npcHandler:say("What?", cid)
  183. end
  184. return true
  185. end
  186.  
  187. npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement