Lua Deathlist killer name

Evil Puncker

I'd rather kiss a rattlesnake
Joined
May 30, 2009
Messages
5,431
Reaction score
1,562
Location
brazol
I found a really old script for death broadcast, but it is just showing "player name [lvl]" and not the rest of was killed by etc... message:

Lua:
function onDeath(cid, corpse)
    local creature = Creature(cid)
    local damageMap = creature:getDamageMap()
    for creatureId, damage in pairs(damageMap) do
        local thing = Creature(creatureId)
    end
    i = 0
    str = getCreatureName(cid).." ["..getPlayerLevel(cid).."]"
    for _, pid in ipairs(damageMap) do
        i = i + 1
        if (i == 1) then
            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
        elseif (i == #damageMap) then
            str = str.." and "
        else
            str = str..", "
        end

        if not(isPlayer(pid) or isMonster(pid)) then
            str = str.."a field item"
        elseif isSummon(pid) then
            str = str.."a "..getCreatureName(pid):lower().." summoned by "..(isPlayer(getCreatureMaster(pid)) and "" or "a ")..""..getCreatureName(getCreatureMaster(pid))
        elseif 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)
    print(str)
    return true
end
what could be wrong? I'm using tfs 1.3
 

zetibia

Intermediate OT User
Joined
Jun 23, 2013
Messages
104
Reaction score
13
Try this:


Lua:
function onDeath(cid, corpse)
    local creature = Creature(cid)
    local damageMap = creature:getDamageMap()
   
    local str = getCreatureName(cid).." ["..getPlayerLevel(cid).."]"
   
    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 ipairs(damageMap) do
        i = i + 1
       
        
        if (i == #damageMap) then
            str = str.." and "
        elseif (i ~= 1) then
            str = str..", "
        end

        if not(isPlayer(pid) or isMonster(pid)) then
            str = str.."a field item"
        elseif isSummon(pid) then
            str = str.."a "..getCreatureName(pid):lower().." summoned by "..(isPlayer(getCreatureMaster(pid)) and "" or "a ")..""..getCreatureName(getCreatureMaster(pid))
        elseif 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)
    print(str)
    return true
end
 

Stigma

Veteran OT User
Joined
Feb 14, 2015
Messages
4,587
Reaction score
2,147
Use pairs not ipairs, damage maps are not ordered tables so ipairs will fail to traverse the table.
 

zetibia

Intermediate OT User
Joined
Jun 23, 2013
Messages
104
Reaction score
13
What version of TFS you are using?
 
Top