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

AutoLoot System for tfs 1.x

Its a "reverse" loop, iterates from the last slot to the first slot of the container
Get it!

thanksss
I have an issue here..
The thing is that this function works great, but it only scan the main container (dead body) but if the monster drops a bag with items inside, the code doesnt recognizes and ignores them... is there anyway to get the code to read the items inside the bag, inside the main corpse?



Lua:
    if corpse:getType():isCorpse() and corpse:getAttribute(ITEM_ATTRIBUTE_CORPSEOWNER) == cid then
        for a = corpse:getSize() - 1, 0, -1 do
            local containerItem = corpse:getItem(a)
            local insideBag = ???????
            if containerItem then
                for b = AUTOLOOT_STORAGE_START, AUTOLOOT_STORAGE_END do
                    if player:getStorageValue(b) == containerItem:getId() and player:getStorageValue(b) == insideBag:getId() then
                            containerItem:moveTo(player)
                    end
                end
            end
        end
    end

I was trying to index a local, but I cant get it because I dont know how to code :(
 
I think a recursive function would be the best shot
Lua:
local function scanContainer(cid, position, virtualContainer)
    local player = Player(cid)
    if not player then
        return
    end

    local corpse = virtualContainer or Tile(position):getTopDownItem()
    if not corpse or not corpse:isContainer() then
        return
    end

    if (virtualContainer or (corpse:getType():isCorpse() and corpse:getAttribute(ITEM_ATTRIBUTE_CORPSEOWNER) == cid)) then
        for a = corpse:getSize() - 1, 0, -1 do
            local containerItem = corpse:getItem(a)
            if containerItem then
                if not containerItem:isContainer() then
                    for b = AUTOLOOT_STORAGE_START, AUTOLOOT_STORAGE_END do
                        if player:getStorageValue(b) == containerItem:getId() then
                            containerItem:moveTo(player)
                        end
                    end
                else
                    scanContainer(player:getId(), 0, containerItem)
                end
            end
        end
    end
end

function onKill(player, target)
    if not target:isMonster() then
        return true
    end

    addEvent(scanContainer, 100, player:getId(), target:getPosition())
    return true
end
 
I think a recursive function would be the best shot
Lua:
local function scanContainer(cid, position, virtualContainer)
    local player = Player(cid)
    if not player then
        return
    end

    local corpse = virtualContainer or Tile(position):getTopDownItem()
    if not corpse or not corpse:isContainer() then
        return
    end

    if (virtualContainer or (corpse:getType():isCorpse() and corpse:getAttribute(ITEM_ATTRIBUTE_CORPSEOWNER) == cid)) then
        for a = corpse:getSize() - 1, 0, -1 do
            local containerItem = corpse:getItem(a)
            if containerItem then
                if not containerItem:isContainer() then
                    for b = AUTOLOOT_STORAGE_START, AUTOLOOT_STORAGE_END do
                        if player:getStorageValue(b) == containerItem:getId() then
                            containerItem:moveTo(player)
                        end
                    end
                else
                    scanContainer(player:getId(), 0, containerItem)
                end
            end
        end
    end
end

function onKill(player, target)
    if not target:isMonster() then
        return true
    end

    addEvent(scanContainer, 100, player:getId(), target:getPosition())
    return true
end
that works great! thank you very much
Post automatically merged:

I tried to add an error message if player runs out of cap


Lua:
local function scanContainer(cid, position, virtualContainer)
    local player = Player(cid)
    if not player then
        return
    end

    local corpse = virtualContainer or Tile(position):getTopDownItem()
    if not corpse or not corpse:isContainer() then
        return
    end

    if (virtualContainer or (corpse:getType():isCorpse() and corpse:getAttribute(ITEM_ATTRIBUTE_CORPSEOWNER) == cid)) then
        for a = corpse:getSize() - 1, 0, -1 do
            local containerItem = corpse:getItem(a)
            if containerItem then
                if not containerItem:isContainer() then
                    for b = AUTOLOOT_STORAGE_START, AUTOLOOT_STORAGE_END do
                        if player:getStorageValue(b) == containerItem:getId() then
                            if player:getCapacity() < containerItem:getAttribute(ITEM_ATTRIBUTE_WEIGHT) then
                            player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "Not enough cap.")
                            else
                            containerItem:moveTo(player)
                            end
                        end
                    end
                else
                    scanContainer(player:getId(), 0, containerItem)
                end
            end
        end
    end
end
can't read "getAttribute" on containerItem variable? or maybe "player:getCapacity" doesnt look for player weight capacity?
 
Last edited:
Guys, will it be possible to make the item go to the backpack that already has the same item? For example, a knight legs dropped and when another one drops, it goes to the same backpack as the first one.
 
I'm looking for onUSE instead onKill, on use the corpse..
Like:
funcion Player:OnUse ..
if itemType:isCorpse() and itemType:isMovable() then
...

but I dont know how put this onuse in events.. any help?
 
I'm looking for onUSE instead onKill, on use the corpse..
Like:
funcion Player:OnUse ..
if itemType:isCorpse() and itemType:isMovable() then
...

but I dont know how put this onuse in events.. any help?

I guess you can set this into actions instead... Nice photo! xD
 
Back
Top