Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ------------------------------------------------
- -- Task System -- by strutZ
- ------------------------------------------------
- local creatureevent = CreatureEvent("taskSystem")
- 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()
- ------------------------------------------------
- -- Talk Action
- ------------------------------------------------
- local talk = TalkAction("!task")
- function talk.onSay(player, words)
- if taskSystem.tasks[player:getStorageValue(Storage.taskSystem.taskStorage)] then -- Check if the player has started a task.
- local taskName = taskSystem.tasks[player:getStorageValue(Storage.taskSystem.taskStorage)].taskName
- local details = "Current Task:\n" .. taskName .. "\n\nYou have currently killed:"
- -- This loop will add all the mosnters to the detail window.
- for i = 1, #taskSystem.tasks[player:getStorageValue(Storage.taskSystem.taskStorage)].monsters do
- local monster = taskSystem.tasks[player:getStorageValue(Storage.taskSystem.taskStorage)].monsters[i].monster -- This line references the monsters to be killed
- local killedMonsters = player:getStorageValue(Storage.taskSystem.baseCountStorage + (player:getStorageValue(Storage.taskSystem.taskStorage)* 10) + i)
- local reqKills = taskSystem.tasks[player:getStorageValue(Storage.taskSystem.taskStorage)].monsters[i].kills
- details = details.."\n- "..monster.." ["..killedMonsters.."/"..reqKills.."]"
- end
- -- Push the detail window to user. Also give the user the player:getStorageValue(taskSystem.taskStorage) window so when he presses ok it pops up
- player:showTextDialog(7844, details.. "\n\nOnce you have completed this task. Speak to Carlos Fuego and ask for your 'Reward.'")
- return false
- end
- player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You are not currently completing a task.")
- end
- talk:separator(" ")
- talk:register()
- ------------------------------------------------
- -- Register script on login
- ------------------------------------------------
- local loginEvent = CreatureEvent('registerOnKill')
- loginEvent:type('login')
- function loginEvent.onLogin(player)
- player:registerEvent('taskSystem')
- return true
- end
- loginEvent:register()
- ------------------------------------------------
- -- ModalWindow Script
- ------------------------------------------------
- -- Main Task Window -- This is the modal window that is displayed first
- ------------------------------------------------
- function Player:sendTaskWindow(category)
- local function buttonCallback(button, choice)
- local taskId = getTaskId(choice.text)
- -- Modal Window Functionallity
- -- 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.
- if button.text == "Details" then
- local task = taskSystem.tasks[taskId].taskName
- local taskDesc = taskSystem.tasks[taskId].description
- local details = "Misson Report - "..task.."\n\n"..taskDesc.."\n\nWhat to kill:"
- local taskRewards = "Rewards:"
- -- This loop will add all the mosnters to the detail window.
- for i = 1, #taskSystem.tasks[taskId].monsters do
- local monster = taskSystem.tasks[taskId].monsters[i].monster -- This line references the monsters to be killed
- local killedMonsters = "0"
- local reqKills = taskSystem.tasks[taskId].monsters[i].kills
- details = details.."\n- "..monster.." ["..killedMonsters.."/"..reqKills.."]"
- end
- -- This loop will add all the rewards to the detail window.
- for i = 1, #taskSystem.tasks[taskId].rewards do
- local expReward = taskSystem.tasks[taskId].rewards[i].amount
- local itemReward = {
- item = taskSystem.tasks[taskId].rewards[i].item,
- count = taskSystem.tasks[taskId].rewards[i].count,
- }
- local outfitReward = {
- name = taskSystem.tasks[taskId].rewards[i].name,
- femaleId = taskSystem.tasks[taskId].rewards[i].femaleId,
- maleId = taskSystem.tasks[taskId].rewards[i].maleId,
- }
- local addonReward = {
- outfit = taskSystem.tasks[taskId].rewards[i].outfit,
- femaleId = taskSystem.tasks[taskId].rewards[i].femaleId,
- maleId = taskSystem.tasks[taskId].rewards[i].maleId,
- addon = taskSystem.tasks[taskId].rewards[i].addonNumber,
- }
- local mountReward = {
- name = taskSystem.tasks[taskId].rewards[i].mountName,
- }
- local moneyReward = {
- count = taskSystem.tasks[taskId].rewards[i].amount,
- }
- if taskSystem.tasks[taskId].rewards[i].type == "item" then
- taskRewards = taskRewards.."\n- "..capAll(getItemName(itemReward.item)).." ["..itemReward.count.."x] "
- elseif taskSystem.tasks[taskId].rewards[i].type == "experience" then
- taskRewards = taskRewards.."\n- "..expReward.." Experience Points"
- elseif taskSystem.tasks[taskId].rewards[i].type == "outfit" then
- taskRewards = taskRewards.."\n- The "..capAll(outfitReward.name).." Outfit"
- elseif taskSystem.tasks[taskId].rewards[i].type == "addon" then
- if addonReward.addon == 1 then
- taskRewards = taskRewards.."\n- The First "..capAll(addonReward.outfit).." Outfit Addon"
- elseif addonReward.addon == 2 then
- taskRewards = taskRewards.."\n- The Second "..capAll(addonReward.outfit).." Outfit Addon"
- elseif addonReward.addon == 3 then
- taskRewards = taskRewards.."\n- The Third "..capAll(addonReward.outfit).." Outfit Addon"
- end
- elseif taskSystem.tasks[taskId].rewards[i].type == "mount" then
- taskRewards = taskRewards.."\n- The "..capAll(mountReward.name).." Monut"
- elseif taskSystem.tasks[taskId].rewards[i].type == "money" then
- taskRewards = taskRewards.."\n- "..moneyReward.count.." gp"
- end
- end
- -- Push the detail window to user. Also give the user the task window so when he presses ok it pops up
- self:showTextDialog(7844, details.."\n\n"..taskRewards)
- self:sendTaskCategory()
- end
- if button.text == "Do Task" then
- local currentTask = self:getStorageValue(Storage.taskSystem.taskStorage)
- if currentTask < 1 then
- self:setStorageValue(Storage.taskSystem.taskStorage, taskId)
- self:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You have started the ["..taskSystem.tasks[taskId].taskName.."] task. Check your progress by typing !task.")
- return true
- end
- self:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You are already doing the ["..taskSystem.tasks[currentTask].taskName.."] task!")
- end
- if button.text == "Back" then
- self:sendTaskCategory()
- end
- end
- -- Modal window design
- local window = ModalWindow {
- title = "Task System: "..category, -- Title of the modal window
- 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
- }
- -- Add buttons to the window (Note: if you change the names of these you must change the functions in the modal window functionallity!)
- window:addButton("Exit")
- window:addButton("Back", buttonCallback)
- window:addButton("Details", buttonCallback)
- window:addButton("Do Task", buttonCallback)
- -- Set what button is pressed when the player presses enter or escape
- window:setDefaultEnterButton("Details")
- window:setDefaultEscapeButton("Exit")
- -- Add choices from the action script
- local categoryId = 0
- for i = 1, #taskSystem.categories do
- if taskSystem.categories[i] == category then
- categoryId = i
- end
- end
- for i = 1, #taskSystem.tasks do
- local o = taskSystem.tasks[i].taskName
- if taskSystem.tasks[i].categoryId == categoryId then
- if taskSystem.tasks[i].vip then
- if self:isVip() then
- window:addChoice(o.." [VIP TASK]")
- end
- else
- window:addChoice(o)
- end
- end
- end
- -- Send the window to player
- window:sendToPlayer(self)
- end
- --------------------------------------------------------
- -- Category Window
- --------------------------------------------------------
- function Player:sendTaskCategory()
- -- Modal Window Functionallity
- local function buttonCallback(button, choice)
- if button.text == "Confirm" then
- local category = choice.text
- self:sendTaskWindow(category)
- end
- end
- -- Modal window design
- local window = ModalWindow {
- title = "Task System", -- Title of the modal window
- message = "Choose the level you would like your task to be based on.\n", -- The message to be displayed on the modal window
- }
- -- Add buttons to the window (Note: if you change the names of these you must change the functions in the modal window functionallity!)
- window:addButton("Exit")
- window:addButton("Confirm", buttonCallback)
- -- Set what button is pressed when the player presses enter or escape
- window:setDefaultEnterButton("Confirm")
- window:setDefaultEscapeButton("Exit")
- for i = 1, #taskSystem.categories do
- window:addChoice(taskSystem.categories[i])
- end
- -- Send the window to player
- window:sendToPlayer(self)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement