Advertisement
Guest User

Untitled

a guest
May 5th, 2015
247
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.64 KB | None | 0 0
  1. -- Collecting items and monster missions by Limos
  2. local keywordHandler = KeywordHandler:new()
  3. local npcHandler = NpcHandler:new(keywordHandler)
  4. NpcSystem.parseParameters(npcHandler)
  5.  
  6. local talkState = {}
  7.  
  8. function onCreatureAppear(cid) npcHandler:onCreatureAppear(cid) end
  9. function onCreatureDisappear(cid) npcHandler:onCreatureDisappear(cid) end
  10. function onCreatureSay(cid, type, msg) npcHandler:onCreatureSay(cid, type, msg) end
  11. function onThink() npcHandler:onThink() end
  12.  
  13. local missions = {
  14. [1] = {
  15. items = {
  16. {id = 5890, count = 12},
  17. {id = 5878, count = 20},
  18. {id = 5894, count = 8}
  19. },
  20. message = "Great, for your first mission you need to collect some items, I need",
  21. level = 15, -- minimum level voor this mission
  22. rewarditems = {
  23. {id = 2160, count = 1},
  24. {id = 2152, count = 1}
  25. },
  26. rewardexp = 15000
  27. },
  28. [2] = {
  29. monsters = {
  30. {name = "Rat", count = 20, storage = 21900},
  31. {name = "Rotworm", count = 26, storage = 21901}
  32. },
  33. message = "Thanks, for your next mission kill",
  34. level = 30,
  35. rewarditems = {
  36. {id = 2160, count = 5}
  37. },
  38. rewardexp = 40000
  39. },
  40. [3] = {
  41. items = {
  42. {id = 5920, count = 45},
  43. {id = 5877, count = 22}
  44. },
  45. message = "Awesome, now get",
  46. level = 50,
  47. rewarditems = {
  48. {id = 2160, count = 15}
  49. },
  50. rewardexp = 100000
  51. },
  52. [4] = {
  53. monsters = {
  54. {name = "Dragon Lords", count = 2, storage = 21902}
  55. },
  56. message = "Good job, now kill",
  57. level = 70,
  58. rewarditems = {
  59. {id = 2160, count = 25}
  60. },
  61. rewardexp = 200000
  62. },
  63. [5] = {
  64. items = {
  65. {id = 5906, count = 35},
  66. {id = 5882, count = 42},
  67. {id = 4850, count = 1}
  68. },
  69. message = "Good, now your final mission, there are a few more items you need to get,",
  70. level = 100,
  71. rewarditems = {
  72. {id = 2160, count = 50}
  73. },
  74. rewardexp = 450000
  75. }
  76. }
  77.  
  78. local storage = 45551
  79.  
  80. local function getItemsMonstersFromTable(imtable)
  81. local text = ""
  82. for v = 1, #imtable do
  83. local ret = ", "
  84. if v == 1 then
  85. ret = ""
  86. elseif v == #imtable then
  87. ret = " and "
  88. end
  89. text = text .. ret
  90. count = imtable[v].count
  91. if imtable[v].id then
  92. info = getItemInfo(imtable[v].id)
  93. text = text .. (count > 1 and count or info.article).." "..(count > 1 and info.plural or info.name)
  94. else
  95. text = text .. count .." "..imtable[v].name
  96. end
  97. end
  98. return text
  99. end
  100.  
  101. function creatureSayCallback(cid, type, msg)
  102.  
  103. local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
  104.  
  105. if not npcHandler:isFocused(cid) then
  106. return false
  107. end
  108.  
  109. local x = missions[getPlayerStorageValue(cid, storage)]
  110.  
  111. if msgcontains(msg, 'mission') or msgcontains(msg, 'quest') then
  112. if not exhaustion.check(cid, 45648) and getPlayerStorageValue(cid, storage) > 0 then
  113. setPlayerStorageValue(cid, storage, -1)
  114. xstorage = getPlayerStorageValue(cid, storage)
  115. end
  116. if getPlayerStorageValue(cid, storage) == -1 then
  117. selfSay("I have several missions for you, do you accept the challenge?", cid)
  118. talkState[talkUser] = 1
  119. elseif x then
  120. if getPlayerLevel(cid) >= x.level then
  121. local mess = x.items and "get "..getItemsMonstersFromTable(x.items) or "kill "..getItemsMonstersFromTable(x.monsters)
  122. selfSay("Did you "..mess.."?", cid)
  123. talkState[talkUser] = 1
  124. else
  125. selfSay("The mission I gave you is for level "..x.level..", come back later.", cid)
  126. end
  127. else
  128. selfSay("You already did all the missions, great job though.", cid)
  129. exhaustion.set(cid, 45648, 86400)
  130. npcHandler:releaseFocus(cid)
  131. end
  132. elseif msgcontains(msg, 'yes') and talkState[talkUser] == 1 then
  133. if getPlayerStorageValue(cid, storage) == -1 then
  134. setPlayerStorageValue(cid, storage, 1)
  135. local x = missions[getPlayerStorageValue(cid, storage)]
  136. local imtable = x.items or x.monsters
  137. selfSay(x.message.." "..getItemsMonstersFromTable(imtable)..".", cid)
  138. exhaustion.set(cid, 45648, 86400)
  139.  
  140. elseif x then
  141. local imtable = x.items or x.monsters
  142. local amount = 0
  143. for it = 1, #imtable do
  144. local check = x.items and getPlayerItemCount(cid, imtable[it].id) or getPlayerStorageValue(cid, imtable[it].storage)
  145. if check >= imtable[it].count then
  146. amount = amount + 1
  147. end
  148. end
  149. if amount == #imtable then
  150. if x.items then
  151. for it = 1, #x.items do
  152. doPlayerRemoveItem(cid, x.items[it].id, x.items[it].count)
  153. end
  154. end
  155. if x.rewarditems then
  156. for r = 1, #x.rewarditems do
  157. doPlayerAddItem(cid, x.rewarditems[r].id, x.rewarditems[r].count)
  158. end
  159. doPlayerSendTextMessage(cid, MESSAGE_EVENT_DEFAULT, "You received "..getItemsMonstersFromTable(x.rewarditems)..".")
  160. end
  161. if x.rewardexp then
  162. doPlayerAddExp(cid, x.rewardexp)
  163. doPlayerSendTextMessage(cid, MESSAGE_EVENT_DEFAULT, "You received "..x.rewardexp.." experience.")
  164. end
  165. setPlayerStorageValue(cid, storage, getPlayerStorageValue(cid, storage) + 1)
  166. local x = missions[getPlayerStorageValue(cid, storage)]
  167. if x then
  168. selfSay(x.message.." "..getItemsMonstersFromTable(x.items or x.monsters)..".", cid)
  169. else
  170. selfSay("Well done! You did a great job on all your missions.", cid)
  171. end
  172. else
  173. local n = 0
  174. for i = 1, #imtable do
  175. local check = x.items and getPlayerItemCount(cid, imtable[i].id) or getPlayerStorageValue(cid, imtable[i].storage)
  176. if check < imtable[i].count then
  177. n = n + 1
  178. end
  179. end
  180. local text = ""
  181. local c = 0
  182. for v = 1, #imtable do
  183. local check = x.items and getPlayerItemCount(cid, imtable[v].id) or getPlayerStorageValue(cid, imtable[v].storage)
  184. if check < imtable[v].count then
  185. c = c + 1
  186. local ret = ", "
  187. if c == 1 then
  188. ret = ""
  189. elseif c == n then
  190. ret = " and "
  191. end
  192. text = text .. ret
  193. if x.items then
  194. local count, info = imtable[v].count - getPlayerItemCount(cid, imtable[v].id), getItemInfo(imtable[v].id)
  195. text = text .. (count > 1 and count or info.article).." "..(count > 1 and info.plural or info.name)
  196. else
  197. local count = imtable[v].count - (getPlayerStorageValue(cid, imtable[v].storage) + 1)
  198. text = text .. count.." "..imtable[v].name
  199. end
  200. end
  201. end
  202. selfSay(x.items and "You don't have all items, you still need to get "..text.."." or "You didn't kill all monsters, you still need to kill "..text..".", cid)
  203. end
  204. end
  205. talkState[talkUser] = 0
  206. elseif msgcontains(msg, 'no') and talkState[talkUser] == 1 then
  207. selfSay("Oh well, I guess not then.", cid)
  208. end
  209. return true
  210. end
  211.  
  212. npcHandler:setMessage(MESSAGE_FAREWELL, "Bye!")
  213. npcHandler:setMessage(MESSAGE_WALKAWAY, "Good bye, have a nice day!")
  214. npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
  215. npcHandler:addModule(FocusModule:new())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement