Postado Dezembro 19, 2021 3 anos Basicamente o que eu quero é : Setar um limite de 1 vez para cada monstro da task. No caso o meu sistema possui 3 niveis de task: short, normal e long. Então, queria que se a pessoa fizesse uma vez cada monstro da task no nivel short, normal e long, o npc escondesse o nome desse monstro na próxima vez que ele for pedir a task no seu respectivo nível. Exemplo : o jogador fez task de rot (short) , então depois que completa-la, não vai aparecer mais na lista dos shorts, mas vai continuar aparecendo em normal e long até que complete também. Segue o Código: Citar local keywordHandler = KeywordHandler:new() local npcHandler = NpcHandler:new(keywordHandler) NpcSystem.parseParameters(npcHandler) function onCreatureAppear(cid) npcHandler:onCreatureAppear(cid) end function onCreatureDisappear(cid) npcHandler:onCreatureDisappear(cid) end function onCreatureSay(cid, type, msg) npcHandler:onCreatureSay(cid, type, msg) end function onThink() npcHandler:onThink() end -- TaskTypes -- 1 Easy -- 2 Medium -- 3 Hard local taskList = { [1] = { {monsterName = "rotworm", reqLevel = 1, killCount = 50, storageValue = 2039}, {monsterName = "carrion worm", reqLevel = 12, killCount = 50, storageValue = 2040}, {monsterName = "dwarf", reqLevel = 1, killCount = 50, storageValue = 2041}, {monsterName = "minotaur", reqLevel = 1, killCount = 50, storageValue = 2042}, {monsterName = "ghoul", reqLevel = 1, killCount = 50, storageValue = 2043}, {monsterName = "elf", reqLevel = 1, killCount = 50, storageValue = 2044}, {monsterName = "beholder", reqLevel = 15, killCount = 50, storageValue = 2045}, {monsterName = "cyclops", reqLevel = 10, killCount = 50, storageValue = 2046}, {monsterName = "minotaur guard", reqLevel = 20, killCount = 50, storageValue = 2047}, {monsterName = "orc berserker", reqLevel = 20, killCount = 50, storageValue = 2048}, {monsterName = "dwarf guard", reqLevel = 18, killCount = 50, storageValue = 2049}, {monsterName = "vampire", reqLevel = 30, killCount = 50, storageValue = 2050}, {monsterName = "necromancer", reqLevel = 30, killCount = 50, storageValue = 2051}, {monsterName = "wyvern", reqLevel = 30, killCount = 50, storageValue = 2052}, {monsterName = "demon skeleton", reqLevel = 30, killCount = 50, storageValue = 2053}, {monsterName = "frost giant", reqLevel = 20, killCount = 50, storageValue = 2054}, {monsterName = "frost giantess", reqLevel = 20, killCount = 50, storageValue = 2055}, {monsterName = "ice golem", reqLevel = 20, killCount = 50, storageValue = 2056}, {monsterName = "barbarian bloodwalker", reqLevel = 15, killCount = 50, storageValue = 2057}, {monsterName = "barbarian headsplitter", reqLevel = 15, killCount = 50, storageValue = 2058}, {monsterName = "pirate cutthroat", reqLevel = 25, killCount = 50, storageValue = 2059}, {monsterName = "pirate marauder", reqLevel = 25, killCount = 50, storageValue = 2060} }, [2] = { {monsterName = "quara hydromancer", reqLevel = 8, killCount = 50, storageValue = 2061}, {monsterName = "quara pincher", reqLevel = 8, killCount = 50, storageValue = 2062}, {monsterName = "quara predator", reqLevel = 8, killCount = 50, storageValue = 2063}, {monsterName = "crystal spider", reqLevel = 8, killCount = 50, storageValue = 2064}, {monsterName = "elder beholder", reqLevel = 8, killCount = 50, storageValue = 2065}, {monsterName = "giant spider", reqLevel = 8, killCount = 50, storageValue = 2066}, {monsterName = "dragon", reqLevel = 8, killCount = 50, storageValue = 2067}, {monsterName = "black knight", reqLevel = 8, killCount = 50, storageValue = 2068}, {monsterName = "hero", reqLevel = 8, killCount = 50, storageValue = 2069}, {monsterName = "dragon lord", reqLevel = 8, killCount = 50, storageValue = 2070}, {monsterName = "frost dragon", reqLevel = 8, killCount = 50, storageValue = 2071}, {monsterName = "betrayed wraith", reqLevel = 8, killCount = 50, storageValue = 2072}, {monsterName = "fury", reqLevel = 8, killCount = 50, storageValue = 2073}, {monsterName = "hellfire fighter", reqLevel = 8, killCount = 50, storageValue = 2074}, {monsterName = "nightmare", reqLevel = 8, killCount = 50, storageValue = 2075} }, [3] = { {monsterName = "warlock", reqLevel = 8, killCount = 50, storageValue = 2076}, {monsterName = "behemoth", reqLevel = 8, killCount = 50, storageValue = 2077}, {monsterName = "demon", reqLevel = 8, killCount = 50, storageValue = 2078}, {monsterName = "blightwalker", reqLevel = 8, killCount = 50, storageValue = 2079}, {monsterName = "dark torturer", reqLevel = 8, killCount = 50, storageValue = 2080}, {monsterName = "hand of cursed fate", reqLevel = 8, killCount = 50, storageValue = 2081}, {monsterName = "hellhound", reqLevel = 8, killCount = 50, storageValue = 2082}, {monsterName = "juggernaut", reqLevel = 8, killCount = 50, storageValue = 2083} } } function Player.hasTask(self) local task = taskList[self:getStorageValue(2037)] if not task then return false end for i = 1, #task do if self:getStorageValue(task[i].storageValue) >= 0 then return true end end return false end function Player.getCurrentTask(self) local task = taskList[self:getStorageValue(2037)] if not task then return 0 end for i = 1, #task do if self:getStorageValue(task[i].storageValue) >= 0 then return task[i].storageValue end end return 0 end function Player.hasCompletedTask(self) local task = taskList[self:getStorageValue(2037)] if not task then return false end for i = 1, #task do local storage = self:getStorageValue(task[i].storageValue) if storage >= 0 then if storage == self:getStorageValue(2036) then return true end end end return false end local tasks = {} local function generateTasks(cid, taskType) local player = Player(cid) local task = taskList[taskType] for i = 1, #task do if player:getLevel() >= task[i].reqLevel then tasks[#tasks + 1] = task[i].monsterName end end --while #tasks > 6 - taskType do --table.remove(tasks, math.random(#tasks)) --end end local taskSelected = nil local taskLengthSelected = nil local taskTypeSelected = nil local function creatureSayCallback(cid, type, msg) if not npcHandler:isFocused(cid) then return false end local player = Player(cid) if npcHandler.topic[cid] == 0 then if isInArray({"tasks", "task", "mission", "challenge"}, msg:lower()) then if player:hasTask() then npcHandler:say("You are already doing a task! You can try to complete or cancel it.", cid) npcHandler.topic[cid] = 1 else npcHandler:say("Great! Do you want my challenge to be: easy, medium or hard?", cid) npcHandler.topic[cid] = 5 end end elseif npcHandler.topic[cid] == 1 then if isInArray({"complete", "reward", "report"}, msg:lower()) then if player:hasCompletedTask() then npcHandler:say("How do you wish to be rewarded? You can have: exp or gold", cid) npcHandler.topic[cid] = 3 local task = taskList[player:getStorageValue(2037)] for i = 1, #task do local storage = player:getStorageValue(task[i].storageValue) if storage >= 0 then taskSelected = task[i].monsterName break end end else local task = taskList[player:getStorageValue(2037)] for i = 1, #task do local storage = player:getStorageValue(task[i].storageValue) if storage >= 0 then npcHandler:say(string.format("You still not finished your task, you have %i %ss left to kill.", player:getStorageValue(2036) - storage, task[i].monsterName:titleCase()), cid) break end end npcHandler.topic[cid] = 0 end elseif msgcontains(msg, "cancel") then npcHandler:say("Are you sure to cancel the current task?", cid) npcHandler.topic[cid] = 4 end elseif npcHandler.topic[cid] == 3 then local monsterType = MonsterType(taskSelected) if not monsterType then print("[Grizzly Adams]: This monster does not exists ".. taskSelected) return true end if isInArray({"experience", "exp"}, msg:lower()) then npcHandler:say("Exp Reward.", cid) player:addExperienceStage((monsterType:getExperience() * player:getCurrentTask()) / player:getStorageValue(2037), true, true) elseif isInArray({"gold", "money"}, msg:lower()) then npcHandler:say("Gold Reward.", cid) local taskType = player:getStorageValue(2037) player:addMoney(((monsterType:getExperience() * player:getCurrentTask()) / taskType) / (2 + taskType)) end player:setStorageValue(player:getCurrentTask(), -1) player:setStorageValue(2037, 0) player:setStorageValue(2038, 0) npcHandler.topic[cid] = 0 elseif npcHandler.topic[cid] == 4 then if msgcontains(msg, "yes") then npcHandler:say("Alright, task cancelled. Talk to me again if you want another task.", cid) player:setStorageValue(player:getCurrentTask(), -1) player:setStorageValue(2038, 0) npcHandler:resetNpc(cid) npcHandler:releaseFocus(cid) else npcHandler:say("Talk to me again when you get the decision.", cid) npcHandler:releaseFocus(cid) end elseif npcHandler.topic[cid] == 5 then if msgcontains(msg, "easy") then npcHandler:say("Easy? Deal! Should the challenge be: short, normal or long?", cid) taskTypeSelected = 1 player:setStorageValue(2037, 1) npcHandler.topic[cid] = 6 elseif msgcontains(msg, "medium") then npcHandler:say("Medium? Deal! Should the challenge be: short, normal or long?", cid) taskTypeSelected = 2 player:setStorageValue(2037, 2) npcHandler.topic[cid] = 6 elseif msgcontains(msg, "hard") then npcHandler:say("Hard? Deal! Should the challenge be: short, normal or long?", cid) taskTypeSelected = 3 player:setStorageValue(2037, 3) npcHandler.topic[cid] = 6 else npcHandler.topic[cid] = 2 end elseif npcHandler.topic[cid] == 6 then if msgcontains(msg, "short") then taskLengthSelected = 1 elseif msgcontains(msg, "normal") then taskLengthSelected = 2 elseif msgcontains(msg, "long") then taskLengthSelected = 3 else npcHandler.topic[cid] = 5 end generateTasks(cid, taskTypeSelected) if #tasks == 0 then npcHandler:say("There is no tasks available for you.", cid) return true end local message = "You can select one of these tasks: " if #tasks > 1 then for i = 1, #tasks do if i < #tasks - 1 then message = message .. tasks[i]:titleCase() .. ", " elseif i == #tasks - 1 then message = message .. tasks[i]:titleCase() .. " " else message = message .. "and ".. tasks[i]:titleCase() .."." end end else message = message .. tasks[1]:titleCase() .. "." end npcHandler:say(message .."", cid) npcHandler.topic[cid] = 7 elseif npcHandler.topic[cid] == 7 then local taskExsist = false for i = 1, #tasks do if tasks[i] == msg:lower() then taskExsist = true end end if taskExsist then for i = 1, #taskList[taskTypeSelected] do if taskList[taskTypeSelected][i].monsterName == msg:lower() then if taskLengthSelected ~= nil then if taskLengthSelected == 1 then player:setStorageValue(2036, taskList[taskTypeSelected][i].killCount + math.random(30, 70)) elseif taskLengthSelected == 2 then player:setStorageValue(2036, taskList[taskTypeSelected][i].killCount + math.random(100, 150)) elseif taskLengthSelected == 3 then player:setStorageValue(2036, taskList[taskTypeSelected][i].killCount + math.random(200, 300)) end end npcHandler:say(string.format("So, you have to kill %i %ss for me. Come back when you have slayed them all!", player:getStorageValue(2036), msg:titleCase()), cid) player:setStorageValue(taskList[taskTypeSelected][i].storageValue, 0) break end end player:setStorageValue(2038, 1) player:registerEvent("TaskKill") npcHandler:resetNpc(cid) npcHandler:releaseFocus(cid) end end return true end local function onAddFocus(cid) for i = 1, #tasks do tasks[i] = nil end taskSelected = nil taskLengthSelected = nil taskTypeSelected = nil end npcHandler:setCallback(CALLBACK_ONADDFOCUS, onAddFocus) npcHandler:setMessage(MESSAGE_GREET, "Hello, |PLAYERNAME|! Are you looking for a task?") npcHandler:setMessage(MESSAGE_FAREWELL, "Happy hunting, old chap!") npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback) npcHandler:addModule(FocusModule:new()) Editado Dezembro 19, 2021 3 anos por Jordan422 (veja o histórico de edições)
Participe da conversa
Você pode postar agora e se cadastrar mais tarde. Se você tem uma conta, faça o login para postar com sua conta.