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.
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