Tenta assim:
local config = {
name = "monster_name", --Nome do monstro.
medal = xxx, --ID da medalha.
damagePrizes = {
--[{minDamage, maxDamage}] = {{itemid, count}, {itemid, count}, {itemid, count}, ...},
[{1, 1000}] = {{9281, 1}, {2160, 50}},
[{1001, 2000}] = {{9281, 1}, {2160, 50}, {2191, 100}, {9282, 1}},
},
storage = 91828
}
function onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
if attacker:isPlayer() and creature:isMonster() and creature:getName() == config.name and isInArray({ORIGIN_MELEE, ORIGIN_RANGED, ORIGIN_SPELL}, origin) and primaryType ~= COMBAT_HEALING then
local damage = attacker:getStorageValue(config.storage) < 1 and 0 or attacker:getStorageValue(config.storage)
attacker:setStorageValue(config.storage, damage + primaryDamage)
end
return primaryDamage, primaryType, secondaryDamage, secondaryType
end
function onDeath(cid, corpse, deathList)
for _, pid in pairs(deathList) do
local player = Player(pid)
local damage, prizes = player:getStorageValue(config.storage), {}
for dmg, items in pairs(config.damagePrizes) do
if damage >= dmg[1] and damage <= dmg[2] then
prizes = items
break
end
end
if #prizes > 0 then
local prize = prizes[math.random(#prizes)]
local item = Item(prize[1])
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Por ajudar matar o "..config.name..", voce recebeu uma medalha e " .. prize[2] .. "x " .. item:getName() .. ".")
player:addItem(item, prize[2])
local medalha = Item(config.medal)
medalha:setAttribute(ITEM_ATTRIBUTE_DESCRIPTION, "Medalha de honra ganhada por " .. player:getName() .. " por ajudar a derrotar o " .. config.name .. " no dia " .. os.date("%D").. ".")
player:addItem(medalha, 1)
player:setStorageValue(config.storage, -1)
end
end
db.query("UPDATE player_storage SET value = -1 WHERE key = "..config.storage)
return true
end