Skip to content

OnPlayerCorpse

A dead player respawns and their body stays behind as a corpse - fill it here if it should hold anything.

Only on a server with [combat] corpse_seconds above 0: the body lies where it fell for that long, on the screens of the players who saw it. It holds nothing and the player keeps everything unless the mode says otherwise here: this runs before the respawn, the player’s inventory still the one they died with - SetCorpseItems puts things on the corpse (anyone may then search it, [combat] loot_bodies allowing) and SetPlayerInventory / EmptyPlayerInventory take them from the player. The two are separate on purpose: putting a thing on the corpse does not take it from the player.

function OnPlayerCorpse(pid, corpse)
-- ...
end
Parameter Type
pid number the player who respawns
corpse number the corpse’s id, for SetCorpseItems, GetCorpseItems and RemoveCorpse

nothing

-- the bag stays on the corpse; the player comes back in what they wore
function OnPlayerCorpse(pid, corpse)
local worn = {}
for _, class in ipairs(GetPlayerEquipment(pid)) do worn[class] = (worn[class] or 0) + 1 end
local bag = {}
for _, stack in ipairs(GetPlayerInventory(pid)) do
local kept = math.min(stack.amount, worn[stack.class] or 0)
worn[stack.class] = (worn[stack.class] or 0) - kept
if stack.amount > kept then bag[#bag + 1] = {class = stack.class, amount = stack.amount - kept} end
end
SetCorpseItems(corpse, bag)
EmptyPlayerInventory(pid, true)
end

SetCorpseItems · EmptyPlayerInventory · OnPlayerDeath · OnPlayerLootBody · the Combat group of the index