local BONUS_RATE = 3 -- 1 normal loot, 2 double loot etc
function onKill(player, target, lastHit)
if target:isMonster() then
target:registerEvent('bonusloot')
end
return true
end
function onDeath(creature, corpse, killer, mostDamageKiller, unjustified, mostDamageUnjustified)
if not creature then
return true
end
if not creature:getType():getLoot() then
return true
end
local tc = 0
for i, k in pairs(creature:getType():getLoot()) do
tc = tc + k.chance
end
for i = 1, BONUS_RATE-1 do
for i, k in pairs(creature:getType():getLoot()) do
if math.random() < k.chance/tc then
local item = corpse:addItem(k.itemId,math.random(k.maxCount) or k.subType)
if item then
if k.actionId then item:setActionId(k.actionId) end
if k.text then item:setAttribute(ITEM_ATTRIBUTE_TEXT, k.text) end
end
end
end
end
return true
end