function getTopItem(p)
p.stackpos = 0
local v = getThingFromPos(p)
repeat
p.stackpos = p.stackpos + 1
v = getThingFromPos(p)
until v.itemid == 0
p.stackpos = p.stackpos - 1
return getThingFromPos(p)
end
function getContentDescription(uid, comma)
local ret, i, containers = '', 0, {}
while i < getContainerSize(uid) do
local v, s = getContainerItem(uid, i), ''
local k = getItemInfo(v.itemid)
if k.name ~= '' then
if v.type > 1 and k.stackable and k.showCount then
s = v.type .. ' ' .. getItemInfo(v.itemid).plural
else
local article = k.article
s = (article == '' and '' or article .. ' ') .. k.name
end
ret = ret .. (i == 0 and not comma and '' or ', ') .. s
if isContainer(v.uid) and getContainerSize(v.uid) > 0 then
table.insert(containers, v.uid)
end
else
ret = ret .. (i == 0 and not comma and '' or ', ') .. 'an item of type ' .. v.itemid .. ', please report it to gamemaster'
end
i = i + 1
end
for i = 1, #containers do
ret = ret .. getContentDescription(containers[i], true)
end
return ret
end
function broadcastLoot(name, position, killers)
local corpse = getTopItem(position).uid
local str = 'Loot of ' .. name .. ': ' .. getContentDescription(corpse) .. '.'
for _, pid in ipairs(killers) do
if isPlayer(pid) then
doPlayerSendTextMessage(pid, MESSAGE_INFO_DESCR, str)
end
end
end
function onDeath(cid, corpse, deathList)
addEvent(broadcastLoot, 100, getCreatureName(cid), getThingPos(cid), deathList)
return true
end