• 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!

[Function][TFS 1.1]item:getParentsList()

2Rec

Excellent OT User
Joined
Jul 31, 2013
Messages
550
Solutions
48
Reaction score
885
A small function i made while ago. Maybe would be useful to someone.
Function returns a table of every item's parent userdata.

Don't know if it's scripted good or can be more efficient.
Would be glad for some more experienced scripter to revise it in this case.
Lua:
function Item.getParentsList(self, PList)
local PList = {}

    if self:getParent() == self:getTopParent() then
        if self:getTopParent():isItem() then
            table.insert(PList, 1, self:getTopParent())
        end
    return PList
    end

    if not self:getParent() then
    return PList
    end

local actualParent = self:getParent()
local topParent = self:getTopParent()

table.insert(PList, 1, actualParent)

    while actualParent ~= topParent do
        actualParent = actualParent:getParent()
            if actualParent:isItem() then
            table.insert(PList, 1, actualParent)
            end
    end

return PList
end
 
Back
Top