Advertisement
Guest User

Untitled

a guest
Mar 29th, 2020
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.71 KB | None | 0 0
  1. local creatureevent = CreatureEvent("taskSystem1")
  2. creatureevent:type('kill')
  3.  
  4. ------------------------------------------------
  5. -- Functions
  6. ------------------------------------------------
  7. function Player:getTask()
  8. local task = self:getStorageValue(Storage.taskSystem.taskStorage)
  9. if task > 0 then
  10. return taskSystem.tasks[self:getStorageValue(Storage.taskSystem.taskStorage)].taskName
  11. end
  12. return 'none'
  13. end
  14.  
  15. function getTaskId(taskName)
  16. local tasks = taskSystem.tasks
  17. for i = 1, #tasks do
  18. if tasks[i].taskName:lower() == taskName:lower() then
  19. return i
  20. end
  21. end
  22. return 'Task ID not found.'
  23. end
  24.  
  25. ------------------------------------------------
  26. -- On Kill script
  27. ------------------------------------------------
  28. function creatureevent.onKill(creature, target)
  29. print('hi')
  30. local killedMonster = target:getName():lower()
  31. local task = creature:getStorageValue(Storage.taskSystem.taskStorage)
  32. if creature:isPlayer() and target:isMonster() then -- Check if the killer was a player and the dead creature was a monster
  33. if taskSystem.tasks[task] then -- Check if the player has started a task.
  34. -- Check if the killed monster is required for the task
  35. for i = 1, #taskSystem.tasks[task].monsters do
  36. if killedMonster == taskSystem.tasks[task].monsters[i].monster:lower() then
  37. -- If the mosnter is required for the task add it to the total count.
  38. local reqKills = taskSystem.tasks[task].monsters[i].kills
  39. local baseCount = Storage.taskSystem.baseCountStorage + (task * 10) + i -- Find the unique storage for the monster.
  40. local oldCount = creature:getStorageValue(baseCount) -- Get the amount of monsters the player has already killed.
  41. local newCount = math.max(0, oldCount) + 1 -- Add +1 to the old count to give new count.
  42. creature:setStorageValue(baseCount, newCount) -- Set the new count.
  43. if newCount == reqKills then
  44. 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.
  45. return true
  46. end
  47. if newCount > reqKills then
  48. 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.
  49. return true
  50. end
  51. creature:sendTextMessage(MESSAGE_STATUS_CONSOLE_RED, "You have killed ["..newCount.."/"..reqKills.."] "..capAll(killedMonster).."'s for task [".. taskSystem.tasks[task].taskName .. "]") -- Send message to player.
  52. break -- Break the loop so it doesnt keep running.
  53. end
  54. end
  55. end
  56. end
  57. end
  58.  
  59. creatureevent:register()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement