Advertisement
Guest User

Untitled

a guest
Apr 16th, 2016
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.39 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. monsters = {
  16. {name = "Rats", count = 1, storage = 21900},
  17. {name = "Rotworms", count = 1, storage = 21901}
  18. },
  19. message = "Thanks, for your next mission kill",
  20. level = 30,
  21. rewarditems = {
  22. {id = 2160, count = 5}
  23. },
  24. rewardexp = 40000
  25. },
  26. [2] = {
  27. monsters = {
  28. {name = "Dragon Lords", count = 1, storage = 21902}
  29. },
  30. message = "Good job, now kill",
  31. level = 70,
  32. rewarditems = {
  33. {id = 2160, count = 25}
  34. },
  35. rewardexp = 200000
  36. },
  37. }
  38.  
  39. local storage = 46661
  40.  
  41. local function getItemsMonstersFromTable(imtable)
  42. local text = ""
  43. for v = 1, #imtable do
  44. local ret = ", "
  45. if v == 1 then
  46. ret = ""
  47. elseif v == #imtable then
  48. ret = " and "
  49. end
  50. text = text .. ret
  51. count = imtable[v].count
  52. if imtable[v].id then
  53. info = getItemInfo(imtable[v].id)
  54. text = text .. (count > 1 and count or info.article).." "..(count > 1 and info.plural or info.name)
  55. else
  56. text = text .. count .." "..imtable[v].name
  57. end
  58. end
  59. return text
  60. end
  61.  
  62. function creatureSayCallback(cid, type, msg)
  63.  
  64. local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
  65.  
  66. if not npcHandler:isFocused(cid) then
  67. return false
  68. end
  69. local xstorage = getPlayerStorageValue(cid, storage)
  70. local x = missions[getPlayerStorageValue(cid, storage)]
  71.  
  72. if msgcontains(msg, 'mission') or msgcontains(msg, 'quest') then
  73. if not exhaustion.check(cid, 45946) and getPlayerStorageValue(cid, storage) > 0 then
  74. setPlayerStorageValue(cid, storage, -1)
  75. xstorage = getPlayerStorageValue(cid, storage)
  76. end
  77. if xstorage == -1 then
  78. selfSay("I have several missions for you, do you accept the challenge?", cid)
  79. talkState[talkUser] = 1
  80. elseif x then
  81. if getPlayerLevel(cid) >= x.level then
  82. local mess = x.items and "get "..getItemsMonstersFromTable(x.items) or "kill "..getItemsMonstersFromTable(x.monsters)
  83. selfSay("Did you "..mess.."?", cid)
  84. talkState[talkUser] = 1
  85. else
  86. selfSay("The mission I gave you is for level "..x.level..", come back later.", cid)
  87. end
  88. else
  89. selfSay("You already did all the missions, great job though.", cid)
  90. npcHandler:releaseFocus(cid)
  91. end
  92. elseif msgcontains(msg, 'yes') and talkState[talkUser] == 1 then
  93. if xstorage == -1 then
  94. setPlayerStorageValue(cid, storage, 1)
  95. local x = missions[getPlayerStorageValue(cid, storage)]
  96. local imtable = x.items or x.monsters
  97. selfSay(x.message.." "..getItemsMonstersFromTable(imtable)..".", cid)
  98. exhaustion.set(cid, 45946, 86400)
  99. elseif x then
  100. local imtable = x.items or x.monsters
  101. local amount = 0
  102. for it = 1, #imtable do
  103. local check = x.items and getPlayerItemCount(cid, imtable[it].id) or getPlayerStorageValue(cid, imtable[it].storage)
  104. if check >= imtable[it].count then
  105. amount = amount + 1
  106. end
  107. end
  108. if amount == #imtable then
  109. if x.items then
  110. for it = 1, #x.items do
  111. doPlayerRemoveItem(cid, x.items[it].id, x.items[it].count)
  112. end
  113. end
  114. if x.rewarditems then
  115. for r = 1, #x.rewarditems do
  116. doPlayerAddItem(cid, x.rewarditems[r].id, x.rewarditems[r].count)
  117. end
  118. doPlayerSendTextMessage(cid, MESSAGE_EVENT_DEFAULT, "You received "..getItemsMonstersFromTable(x.rewarditems)..".")
  119. end
  120. if x.rewardexp then
  121. doPlayerAddExp(cid, x.rewardexp)
  122. doPlayerSendTextMessage(cid, MESSAGE_EVENT_DEFAULT, "You received "..x.rewardexp.." experience.")
  123. end
  124. setPlayerStorageValue(cid, storage, getPlayerStorageValue(cid, storage) + 1)
  125. local x = missions[getPlayerStorageValue(cid, storage)]
  126. if x then
  127. selfSay(x.message.." "..getItemsMonstersFromTable(x.items or x.monsters)..".", cid)
  128. else
  129. selfSay("Well done! You did a great job on all your missions.", cid)
  130. exhaustion.set(cid, 45946, 86400)
  131. end
  132. else
  133. local n = 0
  134. for i = 1, #imtable do
  135. local check = x.items and getPlayerItemCount(cid, imtable[i].id) or getPlayerStorageValue(cid, imtable[i].storage)
  136. if check < imtable[i].count then
  137. n = n + 1
  138. end
  139. end
  140. local text = ""
  141. local c = 0
  142. for v = 1, #imtable do
  143. local check = x.items and getPlayerItemCount(cid, imtable[v].id) or getPlayerStorageValue(cid, imtable[v].storage)
  144. if check < imtable[v].count then
  145. c = c + 1
  146. local ret = ", "
  147. if c == 1 then
  148. ret = ""
  149. elseif c == n then
  150. ret = " and "
  151. end
  152. text = text .. ret
  153. if x.items then
  154. local count, info = imtable[v].count - getPlayerItemCount(cid, imtable[v].id), getItemInfo(imtable[v].id)
  155. text = text .. (count > 1 and count or info.article).." "..(count > 1 and info.plural or info.name)
  156. else
  157. local count = imtable[v].count - (getPlayerStorageValue(cid, imtable[v].storage) + 1)
  158. text = text .. count.." "..imtable[v].name
  159. end
  160. end
  161. end
  162. 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)
  163. end
  164. end
  165. talkState[talkUser] = 0
  166. elseif msgcontains(msg, 'no') and talkState[talkUser] == 1 then
  167. selfSay("Oh well, I guess not then.", cid)
  168. end
  169. return true
  170. end
  171.  
  172. npcHandler:setMessage(MESSAGE_FAREWELL, "Bye!")
  173. npcHandler:setMessage(MESSAGE_WALKAWAY, "Good bye, have a nice day!")
  174. npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
  175. npcHandler:addModule(FocusModule:new())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement