darkmu
Well-Known Member
Lua - [TFS 1.x] Help with getDamageMap and table
hello everyone, I'm trying to do a script to give achievement to the player that did the most damage to the creature, and there is a table with creatures, it looks like this: local config = { -- [names] {amount, achievement} ["Shaburak Demon", "Shaburak Prince"] = {amount = 400...
otland.net
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: