Hey guys,
A few weeks ago I worked on converting onDeath events to Lua for more flexibility. The first of my endeavors was working with items.
This is the result. It does not work.
Selected items are not sent to the corpse. I've got no idea what's wrong with the code or even how to get it to work. So I decided to leave it here. If someone can get it working, hopefully it can be added to the official repository.
I know lots of servers want to change the default way items are handled on death.
Cheers,
Red
A few weeks ago I worked on converting onDeath events to Lua for more flexibility. The first of my endeavors was working with items.
This is the result. It does not work.
Selected items are not sent to the corpse. I've got no idea what's wrong with the code or even how to get it to work. So I decided to leave it here. If someone can get it working, hopefully it can be added to the official repository.
I know lots of servers want to change the default way items are handled on death.
Code:
function onDeath(cid, corpse, killer, mostDamage, unjustified, mostDamage_unjustified)
local player = Player(cid)
if not player then
return
end
local corpse = Container(corpse)
if not getPlayerFlagValue(cid, PlayerFlag_NotGenerateLoot) and player:getVocation() ~= VOCATION_NONE then
local amulet = player:getSlotItem(CONST_SLOT_NECKLACE)
if amulet and amulet:getId() == ITEM_AMULETOFLOSS and player:getSkull() ~= SKULL_RED and player:getSkull() ~= SKULL_BLACK then
local blessings = 0
for i = 1, 5 do
if player:hasBlessing(i) then
blessings = blessings + 1
end
end
if blessings < 5 then
player:removeItem(ITEM_AMULETOFLOSS, 1, -1, false)
end
else
local item
for i = CONST_SLOT_HEAD, CONST_SLOT_AMMO do
item = player:getSlotItem(i)
if item then
-- is player:getDeathPenalty() the correct function?
if (player:getSkull() == SKULL_RED or player:getSkull() == SKULL_BLACK) or math.random(1, item:isContainer() and 10 or 100) <= player:getDeathPenalty() then
item:moveTo(corpse) -- item(s) won't send to corpse
end
end
end
end
end
if not player:getSlotItem(CONST_SLOT_BACKPACK) then
player:addItem(ITEM_BAG, 1, false, CONST_SLOT_BACKPACK)
end
end
Cheers,
Red