• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!
  • 2026 staff recruitment is open! Check it out and consider applying!

Lua Deathlist damage map

darkmu

Well-Known Member
Joined
Aug 26, 2007
Messages
278
Solutions
1
Reaction score
50
Location
Paraná,Brazil
Can someone help me make some adjustments to this script?

It is currently being flagged this way on my channel:

LUA:
22:53 [0]: Soraka [409] was killed by a true dawnfire asura, , , , a true midnight asura, a true dawnfire asura, , , a true midnight asura, a true midnight asura, a true dawnfire asura, , a true dawnfire asura, a hellhound, a true dawnfire asura, a true dawnfire asura, , a true midnight asura, a true midnight asura, , a true midnight asura, a true dawnfire asura, a hellspawn, , a true dawnfire asura, , a true midnight asura, , a hellspawn, , , , , a true dawnfire asura, a true midnight asura, , a true dawnfire asura, a hellhound, a true frost flower asura, a true dawnfire asura, , a true midnight asura, a true frost flower asura, , , a true dawnfire asura, a hellspawn, , , a true frost flower asura, , 

22:44 [0]: Fofoqueira [106] was killed by , , , , a wyrm, , , , , , , , , , , , , , , , , , , a wyrm, , , , , a dragon, , , , ..


I would like you not to repeat the same monsters so much and leave only 1 time for each different monster and I would also like to know why he gets [0] in the beginning?

LUA:
function table.size(t)
    local size = 0
    for k, v in pairs(t) do
        size = size + 1
    end
    return size
end

function onDeath(creature, corpse, lasthitkiller, mostdamagekiller, lasthitunjustified, mostdamageunjustified)
    local damageMap = creature:getDamageMap()
    local str = creature:getName().." ["..creature:getLevel().."]"

    if(#damageMap <= 1) then
        str = str.." was killed by "
    elseif(#damageMap > 1 and #damageMap <= 4) then
        str = str.." was slain by "
    elseif(#damageMap > 4 and #damageMap <= 7) then
        str = str.." was crushed by "
    elseif(#damageMap > 7 and #damageMap <= 10) then
        str = str.." was eliminated by "
    elseif(#damageMap > 10) then
        str = str.." was annihilated by "
    end

    local i = 0
    for pid, _ in pairs(damageMap) do
        i = i + 1

        if (i == #damageMap) then
            str = str.." and "
        elseif (i ~= 1) then
            str = str..", "
        end     
      
        if isPlayer(pid) then
            str = str..""..getCreatureName(pid)
        elseif isMonster(pid) then
            str = str.."a "..getCreatureName(pid):lower()
        end
    end

    str = str.."."
    --Game.broadcastMessage(str, MESSAGE_STATUS_WARNING)
    sendChannelMessage(4, TALKTYPE_CHANNEL_R1, str)   
    return true
end



TFS 1.X+ - Deathlist damage map (https://otland.net/threads/deathlist-damage-map.266695/) @Evil Puncker
 
Solution
modify this part:
LUA:
    local i = 0
    for pid, _ in pairs(damageMap) do
        i = i + 1

        if (i == #damageMap) then
            str = str.." and "
        elseif (i ~= 1) then
            str = str..", "
        end    
     
        if isPlayer(pid) then
            str = str..""..getCreatureName(pid)
        elseif isMonster(pid) then
            str = str.."a "..getCreatureName(pid):lower()
        end
    end

change it to something like:
LUA:
local uniqueDamageNames = {}
local strToAdd
for cid, _ in pairs(damageMap) do
  strToAdd = ""

  if isPlayer(cid) then
    strToAdd = getCreatureName(pid)
  elseif isMonster(cid) then
    strToAdd = "a " .. getCreatureName(pid):lower()
  end

  if strToAdd ~= "" and not...
Could someone help me?

I would like to know why [0] and if it is possible not to repeat the same monster several times.

Example:
10:32 [0]: Morri Tentando [374] was killed by a rift brood, a rift scythe, a demon skeleton, a rift scythe, , a rift worm, a necromancer, a rift scythe, a rift scythe, a rift scythe, a rift worm, a rift scythe, a necromancer, a war golem, , a rift brood, , a rift worm, a ghost, , , , , , a demon skeleton, a azerus, , , a necromancer, a banshee, , a banshee, a banshee, a banshee, , , a banshee, , , , a necromancer, , , a banshee, a hero, a banshee, , , , a banshee, , , , , , , a hero, a banshee, , a demon skeleton, , , , , a warlock, , , , , , , , , a demon skeleton, , a demon skeleton, a warlock, a banshee, , , a fire devil, , , a warlock, a braindeath, a demon skeleton, , a demon skeleton, , a necromancer, a banshee, a necromancer, a demon skeleton, , , , , a necromancer, , a necromancer, a necromancer, , , a banshee, , a necromancer, , , , , a necromancer, , a hero, , a vampire, , , a banshee, a banshee, , , , , a hero, a hero, , .
 
Code:
function table.size(t)
    local size = 0
    for k, v in pairs(t) do
        size = size + 1
    end
    return size
end

local function contains(table, val)
   for i=1,#table do
      if table[i] == val then
         return true
      end
   end
   return false
end

function onDeath(creature, corpse, lasthitkiller, mostdamagekiller, lasthitunjustified, mostdamageunjustified)
    local damageMap = creature:getDamageMap()
    local str = creature:getName().." ["..creature:getLevel().."]"

    if(#damageMap <= 1) then
        str = str.." was killed by "
    elseif(#damageMap > 1 and #damageMap <= 4) then
        str = str.." was slain by "
    elseif(#damageMap > 4 and #damageMap <= 7) then
        str = str.." was crushed by "
    elseif(#damageMap > 7 and #damageMap <= 10) then
        str = str.." was eliminated by "
    elseif(#damageMap > 10) then
        str = str.." was annihilated by "
    end

    local i = 0
    monsters = {}
    for pid, _ in pairs(damageMap) do
        i = i + 1
        creature_name = getCreatureName(pid)
        if not contains(monsters, creature_name:lower()) then
            monsters[i] = creature_name
        else
            if (i == #damageMap) then
                str = str.." and "
            elseif (i ~= 1) then
                str = str..", "
            end   
        
            if isPlayer(pid) then
                str = str..""..creature_name(pid)
            elseif isMonster(pid) then
                str = str.."a "..creature_name:lower()
            end
        end
    end

    str = str.."."
    --Game.broadcastMessage(str, MESSAGE_STATUS_WARNING)
    sendChannelMessage(4, TALKTYPE_CHANNEL_R1, str) 
    return true
end
 
Last edited:
modify this part:
LUA:
    local i = 0
    for pid, _ in pairs(damageMap) do
        i = i + 1

        if (i == #damageMap) then
            str = str.." and "
        elseif (i ~= 1) then
            str = str..", "
        end    
     
        if isPlayer(pid) then
            str = str..""..getCreatureName(pid)
        elseif isMonster(pid) then
            str = str.."a "..getCreatureName(pid):lower()
        end
    end

change it to something like:
LUA:
local uniqueDamageNames = {}
local strToAdd
for cid, _ in pairs(damageMap) do
  strToAdd = ""

  if isPlayer(cid) then
    strToAdd = getCreatureName(pid)
  elseif isMonster(cid) then
    strToAdd = "a " .. getCreatureName(pid):lower()
  end

  if strToAdd ~= "" and not isInArray(uniqueDamageNames, strToAdd) then
    table.insert(uniqueDamageNames, strToAdd)
  end
end

for i, name in ipairs(uniqueDamageNames) do
  if i > 1 and i == #uniqueDamageNames then
    str = str .. " and "
  elseif i > 1 then
    str = str .. ", "
  end

  str = str .. name
end

This is simple and not the best solution as you cannot manipulate the collection after filtering (it might not be sorted alphabetically). But I think it does what you want. And the article is still wrong for vowels.
Also you might want show some message when player dies from something else. I think that if player dies just from a neutral fire field it might display just a dot ("... was killed by ."). So add some simple if at the bottom, like:
Code:
if #uniqueDamageNames == 0 then
  str = str .. "unidentified enemy"
end
 
Last edited:
Solution
test that:
LUA:
function table.size(t)
    local size = 0
    for k, v in pairs(t) do
        size = size + 1
    end
    return size
end
function onDeath(creature, corpse, lasthitkiller, mostdamagekiller, lasthitunjustified, mostdamageunjustified)
    local damageMap = creature:getDamageMap()
    local str = string.format("%s [%u]", creature:getName(), creature:getLevel())
    if (#damageMap <= 1) then
        str = str.." was killed by "
    elseif (#damageMap > 1 and #damageMap <= 4) then
        str = str.." was slain by "
    elseif (#damageMap > 4 and #damageMap <= 7) then
        str = str.." was crushed by "
    elseif (#damageMap > 7 and #damageMap <= 10) then
        str = str.." was eliminated by "
    elseif (#damageMap > 10) then
        str = str.." was annihilated by "
    end
    local saveNames = {}
    local i = 0
    for pid, _ in pairs(damageMap) do
        i = i + 1
        local creatureName = getCreatureName(pid)
        if isPlayer(pid) or (isMonster(pid) and not saveNames[creatureName]) then
            if (i == #damageMap) then
                str = string.format("%s and ", str)
            elseif (i ~= 1) then
                str = string.format("%s, ", str)
            end
            saveNames[creatureName] = true
            str = string.format("%s %s", str, creatureName:lower())
        end
    end
    sendChannelMessage(4, TALKTYPE_CHANNEL_R1, str..".")
    return true
end
 
Back
Top