• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Solved Help with corpse (onDeath) TFS 1.0

eduardbean

Member
Joined
Nov 26, 2010
Messages
129
Solutions
2
Reaction score
15
Code:
function onDeath(player, corpse, killer, mostDamageKiller, unjustified, mostDamageUnjustified)
print(getContainerSize(corpse))
return true
end

Why does this always returns 0 ?, how i can return corpse from game ? to check size and get itens from corpse ?
 
The items are created later in the corpse, so at the moment you check the amount of items it's 0.
You can do something like this, after 100 milliseconds the items are already added in the corpse.
Code:
local function getCorpseSize(pos)
     print(Tile(pos):getTopVisibleThing():getSize())
end
Code:
addEvent(getCorpseSize, 100, player:getPosition())
 
Last edited:
This is My Code
Code:
function onDeath(player, corpse, killer, mostDamageKiller, unjustified, mostDamageUnjustified)
        local loot = {}
        local pos = player:getPosition()
        local text = ""

        tile = Tile(pos):getTopVisibleThing()

        for i = 0, tile:getSize() do
            loot[i] = getContainerItem(tile.uid, i)
        end
        for i, v in pairs(loot) do
            if text == "" then
                text = "Loot from "..player:getName()..": "..getItemName(v)
            else
                text = text..", "..getItemName(v)
            end
        end
       print(text)
    return true
end

and this is my error

GBA4xFN.png


I Just want to return loot itens, for give it to player, and remove from corpse like a autoLoot.​
 
You should check whether the thing is an item (and container) or not before you proceed with getSize().
Code:
    local thing = Tile(position):getTopVisibleThing()
    if thing
            and thing:isItem()
            and thing:isContainer()
            and thing:getType():isCorpse() then
        -- something
    end
 
Back
Top