Advertisement
Guest User

Untitled

a guest
Mar 29th, 2020
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.51 KB | None | 0 0
  1. ------------------------------------------------
  2.  
  3. -- Task System -- by strutZ
  4.  
  5. ------------------------------------------------
  6. local creatureevent = CreatureEvent("taskSystem")
  7. creatureevent:type('kill')
  8.  
  9. ------------------------------------------------
  10. -- Functions
  11. ------------------------------------------------
  12. function Player:getTask()
  13. local task = self:getStorageValue(Storage.taskSystem.taskStorage)
  14. if task > 0 then
  15. return taskSystem.tasks[self:getStorageValue(Storage.taskSystem.taskStorage)].taskName
  16. end
  17. return 'none'
  18. end
  19.  
  20. function getTaskId(taskName)
  21. local tasks = taskSystem.tasks
  22. for i = 1, #tasks do
  23. if tasks[i].taskName:lower() == taskName:lower() then
  24. return i
  25. end
  26. end
  27. return 'Task ID not found.'
  28. end
  29.  
  30. ------------------------------------------------
  31. -- On Kill script
  32. ------------------------------------------------
  33. function creatureevent.onKill(creature, target)
  34. print('hi')
  35. local killedMonster = target:getName():lower()
  36. local task = creature:getStorageValue(Storage.taskSystem.taskStorage)
  37. if creature:isPlayer() and target:isMonster() then -- Check if the killer was a player and the dead creature was a monster
  38. if taskSystem.tasks[task] then -- Check if the player has started a task.
  39. -- Check if the killed monster is required for the task
  40. for i = 1, #taskSystem.tasks[task].monsters do
  41. if killedMonster == taskSystem.tasks[task].monsters[i].monster:lower() then
  42. -- If the mosnter is required for the task add it to the total count.
  43. local reqKills = taskSystem.tasks[task].monsters[i].kills
  44. local baseCount = Storage.taskSystem.baseCountStorage + (task * 10) + i -- Find the unique storage for the monster.
  45. local oldCount = creature:getStorageValue(baseCount) -- Get the amount of monsters the player has already killed.
  46. local newCount = math.max(0, oldCount) + 1 -- Add +1 to the old count to give new count.
  47. creature:setStorageValue(baseCount, newCount) -- Set the new count.
  48. if newCount == reqKills then
  49. creature:sendTextMessage(MESSAGE_STATUS_CONSOLE_RED, "You have now killed the required number of "..capAll(killedMonster).."'s for task [".. taskSystem.tasks[task].taskName .. "]") -- Send message to player.
  50. return true
  51. end
  52. if newCount > reqKills then
  53. creature:sendTextMessage(MESSAGE_STATUS_CONSOLE_RED, "You have already killed the required number of "..capAll(killedMonster).."'s for task [".. taskSystem.tasks[task].taskName .. "]") -- Send message to player.
  54. return true
  55. end
  56. creature:sendTextMessage(MESSAGE_STATUS_CONSOLE_RED, "You have killed ["..newCount.."/"..reqKills.."] "..capAll(killedMonster).."'s for task [".. taskSystem.tasks[task].taskName .. "]") -- Send message to player.
  57. break -- Break the loop so it doesnt keep running.
  58. end
  59. end
  60. end
  61. end
  62. end
  63.  
  64. creatureevent:register()
  65.  
  66. ------------------------------------------------
  67. -- Talk Action
  68. ------------------------------------------------
  69. local talk = TalkAction("!task")
  70.  
  71. function talk.onSay(player, words)
  72. if taskSystem.tasks[player:getStorageValue(Storage.taskSystem.taskStorage)] then -- Check if the player has started a task.
  73. local taskName = taskSystem.tasks[player:getStorageValue(Storage.taskSystem.taskStorage)].taskName
  74. local details = "Current Task:\n" .. taskName .. "\n\nYou have currently killed:"
  75. -- This loop will add all the mosnters to the detail window.
  76. for i = 1, #taskSystem.tasks[player:getStorageValue(Storage.taskSystem.taskStorage)].monsters do
  77. local monster = taskSystem.tasks[player:getStorageValue(Storage.taskSystem.taskStorage)].monsters[i].monster -- This line references the monsters to be killed
  78. local killedMonsters = player:getStorageValue(Storage.taskSystem.baseCountStorage + (player:getStorageValue(Storage.taskSystem.taskStorage)* 10) + i)
  79. local reqKills = taskSystem.tasks[player:getStorageValue(Storage.taskSystem.taskStorage)].monsters[i].kills
  80. details = details.."\n- "..monster.." ["..killedMonsters.."/"..reqKills.."]"
  81. end
  82.  
  83. -- Push the detail window to user. Also give the user the player:getStorageValue(taskSystem.taskStorage) window so when he presses ok it pops up
  84. player:showTextDialog(7844, details.. "\n\nOnce you have completed this task. Speak to Carlos Fuego and ask for your 'Reward.'")
  85. return false
  86. end
  87. player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You are not currently completing a task.")
  88. end
  89.  
  90. talk:separator(" ")
  91. talk:register()
  92.  
  93. ------------------------------------------------
  94. -- Register script on login
  95. ------------------------------------------------
  96. local loginEvent = CreatureEvent('registerOnKill')
  97. loginEvent:type('login')
  98.  
  99. function loginEvent.onLogin(player)
  100. player:registerEvent('taskSystem')
  101. return true
  102. end
  103.  
  104. loginEvent:register()
  105.  
  106.  
  107. ------------------------------------------------
  108.  
  109. -- ModalWindow Script
  110.  
  111. ------------------------------------------------
  112. -- Main Task Window -- This is the modal window that is displayed first
  113. ------------------------------------------------
  114. function Player:sendTaskWindow(category)
  115. local function buttonCallback(button, choice)
  116. local taskId = getTaskId(choice.text)
  117.  
  118. -- Modal Window Functionallity
  119. -- If user presses deatils they will be directed to the mission report. Laying out the mission name, misson description, monsters to kill and the reward they will gain.
  120. if button.text == "Details" then
  121. local task = taskSystem.tasks[taskId].taskName
  122. local taskDesc = taskSystem.tasks[taskId].description
  123. local details = "Misson Report - "..task.."\n\n"..taskDesc.."\n\nWhat to kill:"
  124. local taskRewards = "Rewards:"
  125.  
  126. -- This loop will add all the mosnters to the detail window.
  127. for i = 1, #taskSystem.tasks[taskId].monsters do
  128. local monster = taskSystem.tasks[taskId].monsters[i].monster -- This line references the monsters to be killed
  129. local killedMonsters = "0"
  130. local reqKills = taskSystem.tasks[taskId].monsters[i].kills
  131. details = details.."\n- "..monster.." ["..killedMonsters.."/"..reqKills.."]"
  132. end
  133.  
  134. -- This loop will add all the rewards to the detail window.
  135. for i = 1, #taskSystem.tasks[taskId].rewards do
  136. local expReward = taskSystem.tasks[taskId].rewards[i].amount
  137. local itemReward = {
  138. item = taskSystem.tasks[taskId].rewards[i].item,
  139. count = taskSystem.tasks[taskId].rewards[i].count,
  140. }
  141. local outfitReward = {
  142. name = taskSystem.tasks[taskId].rewards[i].name,
  143. femaleId = taskSystem.tasks[taskId].rewards[i].femaleId,
  144. maleId = taskSystem.tasks[taskId].rewards[i].maleId,
  145. }
  146. local addonReward = {
  147. outfit = taskSystem.tasks[taskId].rewards[i].outfit,
  148. femaleId = taskSystem.tasks[taskId].rewards[i].femaleId,
  149. maleId = taskSystem.tasks[taskId].rewards[i].maleId,
  150. addon = taskSystem.tasks[taskId].rewards[i].addonNumber,
  151. }
  152. local mountReward = {
  153. name = taskSystem.tasks[taskId].rewards[i].mountName,
  154. }
  155. local moneyReward = {
  156. count = taskSystem.tasks[taskId].rewards[i].amount,
  157. }
  158. if taskSystem.tasks[taskId].rewards[i].type == "item" then
  159. taskRewards = taskRewards.."\n- "..capAll(getItemName(itemReward.item)).." ["..itemReward.count.."x] "
  160. elseif taskSystem.tasks[taskId].rewards[i].type == "experience" then
  161. taskRewards = taskRewards.."\n- "..expReward.." Experience Points"
  162. elseif taskSystem.tasks[taskId].rewards[i].type == "outfit" then
  163. taskRewards = taskRewards.."\n- The "..capAll(outfitReward.name).." Outfit"
  164. elseif taskSystem.tasks[taskId].rewards[i].type == "addon" then
  165. if addonReward.addon == 1 then
  166. taskRewards = taskRewards.."\n- The First "..capAll(addonReward.outfit).." Outfit Addon"
  167. elseif addonReward.addon == 2 then
  168. taskRewards = taskRewards.."\n- The Second "..capAll(addonReward.outfit).." Outfit Addon"
  169. elseif addonReward.addon == 3 then
  170. taskRewards = taskRewards.."\n- The Third "..capAll(addonReward.outfit).." Outfit Addon"
  171. end
  172. elseif taskSystem.tasks[taskId].rewards[i].type == "mount" then
  173. taskRewards = taskRewards.."\n- The "..capAll(mountReward.name).." Monut"
  174. elseif taskSystem.tasks[taskId].rewards[i].type == "money" then
  175. taskRewards = taskRewards.."\n- "..moneyReward.count.." gp"
  176. end
  177. end
  178.  
  179. -- Push the detail window to user. Also give the user the task window so when he presses ok it pops up
  180. self:showTextDialog(7844, details.."\n\n"..taskRewards)
  181. self:sendTaskCategory()
  182. end
  183.  
  184. if button.text == "Do Task" then
  185. local currentTask = self:getStorageValue(Storage.taskSystem.taskStorage)
  186. if currentTask < 1 then
  187. self:setStorageValue(Storage.taskSystem.taskStorage, taskId)
  188. self:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You have started the ["..taskSystem.tasks[taskId].taskName.."] task. Check your progress by typing !task.")
  189. return true
  190. end
  191. self:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You are already doing the ["..taskSystem.tasks[currentTask].taskName.."] task!")
  192. end
  193.  
  194. if button.text == "Back" then
  195. self:sendTaskCategory()
  196. end
  197.  
  198. end
  199.  
  200. -- Modal window design
  201. local window = ModalWindow {
  202. title = "Task System: "..category, -- Title of the modal window
  203. message = "Welcome to our task system! \nTo start a task, Choose one from the list below followed by the 'Do task' button. \nYou can also click on the details button to see information about the task.\n\n", -- The message to be displayed on the modal window
  204. }
  205.  
  206. -- Add buttons to the window (Note: if you change the names of these you must change the functions in the modal window functionallity!)
  207. window:addButton("Exit")
  208. window:addButton("Back", buttonCallback)
  209. window:addButton("Details", buttonCallback)
  210. window:addButton("Do Task", buttonCallback)
  211.  
  212.  
  213. -- Set what button is pressed when the player presses enter or escape
  214. window:setDefaultEnterButton("Details")
  215. window:setDefaultEscapeButton("Exit")
  216.  
  217. -- Add choices from the action script
  218. local categoryId = 0
  219. for i = 1, #taskSystem.categories do
  220. if taskSystem.categories[i] == category then
  221. categoryId = i
  222. end
  223. end
  224.  
  225. for i = 1, #taskSystem.tasks do
  226. local o = taskSystem.tasks[i].taskName
  227. if taskSystem.tasks[i].categoryId == categoryId then
  228. if taskSystem.tasks[i].vip then
  229. if self:isVip() then
  230. window:addChoice(o.." [VIP TASK]")
  231. end
  232. else
  233. window:addChoice(o)
  234. end
  235. end
  236. end
  237.  
  238. -- Send the window to player
  239. window:sendToPlayer(self)
  240. end
  241.  
  242. --------------------------------------------------------
  243. -- Category Window
  244. --------------------------------------------------------
  245. function Player:sendTaskCategory()
  246. -- Modal Window Functionallity
  247. local function buttonCallback(button, choice)
  248. if button.text == "Confirm" then
  249. local category = choice.text
  250. self:sendTaskWindow(category)
  251. end
  252. end
  253.  
  254. -- Modal window design
  255. local window = ModalWindow {
  256. title = "Task System", -- Title of the modal window
  257. message = "Choose the level you would like your task to be based on.\n", -- The message to be displayed on the modal window
  258. }
  259.  
  260. -- Add buttons to the window (Note: if you change the names of these you must change the functions in the modal window functionallity!)
  261. window:addButton("Exit")
  262. window:addButton("Confirm", buttonCallback)
  263.  
  264.  
  265. -- Set what button is pressed when the player presses enter or escape
  266. window:setDefaultEnterButton("Confirm")
  267. window:setDefaultEscapeButton("Exit")
  268.  
  269. for i = 1, #taskSystem.categories do
  270. window:addChoice(taskSystem.categories[i])
  271. end
  272.  
  273. -- Send the window to player
  274. window:sendToPlayer(self)
  275. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement