Lua:
local config = {
chance = 100,
tiers = {
[{ 1, 5000}] = { tier = {"Upgrade Stone!", true}, effect = {CONST_ME_TUTORIALARROW, true}, itemList = {
{32641, 1, 1, 100}
}
}
}
}
local lootstone = CreatureEvent("lootstone")
function lootstone.onKill(player, target, lastHit)
if not target:isMonster() or target:getMaster() then
return true
end
target:registerEvent('onDeath_lootstoneItemDrops')
return true
end
lootstone:register()
local onDeath_lootstoneItemDrop = CreatureEvent("onDeath_lootstoneItemDrops")
function onDeath_lootstoneItemDrop.onDeath(creature, corpse, killer, mostDamageKiller, unjustified, mostDamageUnjustified)
-- check if corpse item has available space to receive an additional item.
if corpse:getEmptySlots() > 0 then
-- check if an additional item will drop.
if math.random(10000) > config.chance then
return true
end
-- choose a tier.
local rand = math.random(10000)
for chance, index in pairs(config.tiers) do
if chance[1] <= rand and chance[2] >= rand then
-- create loot list.
local rewardItems = {}
for i = 1, #index.itemList do
if math.random(10000) <= index.itemList[i][4] then
rewardItems[#rewardItems + 1] = i
end
end
-- give a random item, if there are any to give.
if rewardItems[1] then
rand = math.random(#rewardItems)
corpse:addItem(index.itemList[rand][1], math.random(index.itemList[rand][2], index.itemList[rand][3]))
if index.tier[2] == true then
creature:say(index.tier[1], TALKTYPE_MONSTER_SAY, false, nil, creature:getPosition())
end
if index.effect[2] == true then
local position = creature:getPosition()
for i = 1, 4 do
addEvent(function() position:sendMagicEffect(index.effect[1]) end, (i - 1) * 500)
end
end
end
return true
end
end
end
return true
end
onDeath_lootstoneItemDrop:register()
error :54: attempt to call method 'getEmptySlots' (a nil value)