Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local creatureevent = CreatureEvent("taskSystem1")
- creatureevent:type('kill')
- ------------------------------------------------
- -- Functions
- ------------------------------------------------
- function Player:getTask()
- local task = self:getStorageValue(Storage.taskSystem.taskStorage)
- if task > 0 then
- return taskSystem.tasks[self:getStorageValue(Storage.taskSystem.taskStorage)].taskName
- end
- return 'none'
- end
- function getTaskId(taskName)
- local tasks = taskSystem.tasks
- for i = 1, #tasks do
- if tasks[i].taskName:lower() == taskName:lower() then
- return i
- end
- end
- return 'Task ID not found.'
- end
- ------------------------------------------------
- -- On Kill script
- ------------------------------------------------
- function creatureevent.onKill(creature, target)
- print('hi')
- local killedMonster = target:getName():lower()
- local task = creature:getStorageValue(Storage.taskSystem.taskStorage)
- if creature:isPlayer() and target:isMonster() then -- Check if the killer was a player and the dead creature was a monster
- if taskSystem.tasks[task] then -- Check if the player has started a task.
- -- Check if the killed monster is required for the task
- for i = 1, #taskSystem.tasks[task].monsters do
- if killedMonster == taskSystem.tasks[task].monsters[i].monster:lower() then
- -- If the mosnter is required for the task add it to the total count.
- local reqKills = taskSystem.tasks[task].monsters[i].kills
- local baseCount = Storage.taskSystem.baseCountStorage + (task * 10) + i -- Find the unique storage for the monster.
- local oldCount = creature:getStorageValue(baseCount) -- Get the amount of monsters the player has already killed.
- local newCount = math.max(0, oldCount) + 1 -- Add +1 to the old count to give new count.
- creature:setStorageValue(baseCount, newCount) -- Set the new count.
- if newCount == reqKills then
- 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.
- return true
- end
- if newCount > reqKills then
- 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.
- return true
- end
- creature:sendTextMessage(MESSAGE_STATUS_CONSOLE_RED, "You have killed ["..newCount.."/"..reqKills.."] "..capAll(killedMonster).."'s for task [".. taskSystem.tasks[task].taskName .. "]") -- Send message to player.
- break -- Break the loop so it doesnt keep running.
- end
- end
- end
- end
- end
- creatureevent:register()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement