Postado Setembro 18, 2019 5 anos Boa noite pessoal do TK. Estou ajeitando meu sistema de tasks, e fui colocar pra todos os players que causam dano na criatura receberem a storage de contagem. No entanto, está contando 2 vezes pra cada criatura abatida (Exemplo: matei 1 rohirim, ele conta direto 1/80 e 2/80, mandando até duas mensagens, basicamente ta rodando o script 2x dentro do for, acho). Gostaria de corrigir isso pra que só fizesse a contagem 1x pra cada criatura abatida. Segue o código: Spoiler function onKill(creature, target) local player = creature:getPlayer() if not player then return true end if target:isPlayer() or target:getMaster() then return true end for uid in pairs(target:getDamageMap()) do local killer = Player(uid) if killer:getTask() then local task = killer:getTask() if table.contains(task.monsters_list, target:getName():lower()) and killer:getStorageValue(task.storage) < task.amount then killer:setStorageValue(task.storage, killer:getStorageValue(task.storage) + 1) killer:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, '[Task System] You killed ['..killer:getStorageValue(task.storage)..'/'..task.amount..'] '..target:getName()..'.') end elseif killer:getDailyTask() then local task = killer:getDailyTask() if table.contains(task.monsters_list, target:getName():lower()) and killer:getStorageValue(task.storage) < task.amount then killer:setStorageValue(task.storage, killer:getStorageValue(task.storage) + 1) killer:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, '[Task System Daily] You killed ['..killer:getStorageValue(task.storage)..'/'..task.amount..'] '..target:getName()..'.') end elseif killer:getSpecialTask() then local task = killer:getSpecialTask() if table.contains(task.monsters_list, target:getName():lower()) and killer:getStorageValue(task.storage) < task.amount then killer:setStorageValue(task.storage, killer:getStorageValue(task.storage) + 1) killer:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, '[Task System Special] You killed ['..killer:getStorageValue(task.storage)..'/'..task.amount..'] '..target:getName()..'.') end end end return true end function onLogin(cid) registerCreatureEvent(cid, "taskSystem") return true end
Postado Setembro 18, 2019 5 anos Teste esse script -- <event type="login" name="TesteLogin" script="teste.lua" /> -- <event type="kill" name="TesteKill" script="teste.lua"/> function onKill(creature, target) local player = creature:getPlayer() if not player then return true end if not target:isMonster() or target:getMaster() then return true end local targetName = target:getName():lower() if targetName ~= "rotworm" then return true end print("") local damageMap = target:getDamageMap() for attackerId, damage in pairs(damageMap) do local uid = Player(attackerId) if uid then print("Player: " .. uid:getName() .. " - Damage: ".. damage.total .. " target: " .. targetName) end end return true end function onLogin(player) player:registerEvent("TesteKill") return true end Só se o seu servidor tive algum bug na função getDamageMap(), aqui deu certinho ... STYLLER OT 2022
Postado Setembro 18, 2019 5 anos Autor @luanluciano93 Quando fiz o teste com esse teu script, imprimiu certinho o nome 1x só. Mas quando eu rodo no meu, ele imprime o nome 2x... O que pode estar errado? Alterei o script pra que se a pessoa tiver varias tasks simultâneas, consiga fazer elas (com o original, se ele tivesse uma task, o primeiro if, ele contaria pra ela mas não pras outras). Tu consegue encontrar onde ta o erro nesse script que faz com que ele conte os nomes 2x? function onKill(creature, target) local player = creature:getPlayer() if not player then return true end if not target:isMonster() or target:getMaster() then return true end local damageMap = target:getDamageMap() for attackerId, damage in pairs(damageMap) do local uid = Player(attackerId) if uid then if uid:getTask() or uid:getDailyTask() or uid:getSpecialTask() then if uid:getTask() then local task = uid:getTask() if table.contains(task.monsters_list, target:getName():lower()) and uid:getStorageValue(task.storage) < task.amount then uid:setStorageValue(task.storage, uid:getStorageValue(task.storage) + 1) uid:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, '[Task Comum System] You killed ['..uid:getStorageValue(task.storage)..'/'..task.amount..'] '..target:getName()..'.') end end if uid:getDailyTask() then local taskdaily = uid:getDailyTask() if table.contains(taskdaily.monsters_list, target:getName():lower()) and uid:getStorageValue(taskdaily.storage) < taskdaily.amount then uid:setStorageValue(taskdaily.storage, uid:getStorageValue(taskdaily.storage) + 1) uid:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, '[Daily Task System] You killed ['..uid:getStorageValue(taskdaily.storage)..'/'..taskdaily.amount..'] '..target:getName()..'.') end end if uid:getSpecialTask() then local task = uid:getSpecialTask() if table.contains(task.monsters_list, target:getName():lower()) and uid:getStorageValue(task.storage) < task.amount then uid:setStorageValue(task.storage, uid:getStorageValue(task.storage) + 1) uid:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, '[Task Especial System] You killed ['..uid:getStorageValue(task.storage)..'/'..task.amount..'] '..target:getName()..'.') end end end end end return true end function onLogin(cid) registerCreatureEvent(cid, "taskSystem") return true end Só matei um... mas ele faz o if todo duas vezes. Editado Setembro 18, 2019 5 anos por MatCollier (veja o histórico de edições)
Postado Setembro 18, 2019 5 anos function onKill(creature, target) local p = creature:getPlayer() if not p then return true end if not target:isMonster() or target:getMaster() then return true end local damageMap = target:getDamageMap() for attackerId, damage in pairs(damageMap) do local player = Player(attackerId) if player then ------------------------------------------------ local task = player:getTask() if task then if table.contains(task.monsters_list, target:getName():lower()) then local monstersKilled = player:getStorageValue(task.storage) if monstersKilled < task.amount then player:setStorageValue(task.storage, monstersKilled + 1) player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, '[Task Comum System] You killed ['..monstersKilled..'/'..task.amount..'] '..target:getName()..'.') end end end ------------------------------------------------ end end return true end function onLogin(cid) registerCreatureEvent(cid, "taskSystem") return true end STYLLER OT 2022
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.