• 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!

Lua attempt to compare table with number

darkmu

Well-Known Member
Joined
Aug 26, 2007
Messages
274
Solutions
1
Reaction score
50
Location
Paraná,Brazil

I'm trying to follow this topic, but I got an error.

If more than 2 people attack the same monster it simply returns this error:

Lua:
Lua Script Error: [CreatureScript Interface]
data/creaturescripts/scripts/mostDamage.lua:onKill
data/creaturescripts/scripts/mostDamage.lua:23: attempt to compare table with number
stack traceback:
        [C]: in function '__lt'
        data/creaturescripts/scripts/mostDamage.lua:23: in function <data/creaturescripts/scripts/mostDamage.lua:10>


If one person attacks right.

Lua:
local config = {
    ['shaburak demon'] = {amount = 400, achievement = 'Shaburak Nemesis'},
    ['shaburak prince'] = {amount = 400, achievement = 'Shaburak Nemesis'},
    ['askarak prince'] = {amount = 400, achievement = 'Askarak Nemesis'},
    ['askarak demon'] = {amount = 400, achievement = 'Askarak Nemesis'},
    ['anmothra'] = {amount = 1, achievement = 'Slayer of Anmothra'},
    ['rat'] = {amount = 10, achievement = 'rat'}
}

function onKill(creature, target)
    local targetMonster = Monster(target)
    local player = Player(creature)
    local targetMonsterConfig = config[targetMonster:getName():lower()]
   
    if not targetMonster or targetMonster:getMaster() or not player or not targetMonsterConfig then
        return true
    end
   
    temp = {playerId = 0, damage = 0}
    for currentPlayerId, currentDamage in pairs(targetMonster:getDamageMap()) do
        local attackerPlayer = Player(currentPlayerId)
        if attackerPlayer then
            if temp.damage < currentDamage.total then
                temp.playerId = currentPlayerId
                temp.damage = currentDamage
            end
        end
    end
 
    if temp.playerId == 0 then
        return true
    end
   
    winnerPlayer = Player(temp.playerId)
   
    if not winnerPlayer then
        return true
    end
   
    winnerPlayer:addItem(2160,5)
 
end
 
Last edited:
Back
Top