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

Simple Auto Loot System [TFS 1.3]

For anybody who is interested in it, I fixed it a bit in lua part.
Now if you have no space in backpack or cap the loot will simply stay in the corpse and player will get a message.
The memory leak is taken care of too.

data/scripts/eventcallbacks/monster/default_onDropLoot.lua
Lua:
local ec = EventCallback

ec.onDropLoot = function(self, corpse)
    if configManager.getNumber(configKeys.RATE_LOOT) == 0 then
        return
    end

    local player = Player(corpse:getCorpseOwner())
    local mType = self:getType()
    local monsterLoot = mType:getLoot()
    for i = 1, #monsterLoot do
        local item = corpse:createLootItem(monsterLoot[i])
        if not item then
            print('[Warning] DropLoot:', 'Could not add loot item to corpse.')
        end
    end

    if player then
        local autolootContainer = Game.createItem(1987, 1)
        local items = corpse:getItems()
        local item_weight = 0
        local item_slots = 0
       
        for _, item in ipairs(items) do
            if (player:getAutoLootItem(item.itemid)) then
                item_weight = item_weight + item:getWeight()
                item_slots = item_slots + 1
            end
        end
       
        local bp = player:getSlotItem(CONST_SLOT_BACKPACK)
        if bp and bp:getEmptySlots(true) < item_slots then
            player:sendCancelMessage("Autoloot: No space in backpack!")
        elseif player:getFreeCapacity() < (item_weight * 100) then
            player:sendCancelMessage("Autoloot: Not enough cap!")
        else
            for _, item in ipairs(items) do
                if (player:getAutoLootItem(item.itemid)) then
                    item:moveTo(autolootContainer)
                end
            end
        end
       
        local text = ("Loot of %s: %s"):format(mType:getNameDescription(), corpse:getContentDescription())
       
        if (autolootContainer:getSize() > 0) then
            text = text .. ' and ' .. autolootContainer:getContentDescription() .. ' that was auto looted'
            local autolootItems = autolootContainer:getItems()

            for _, item in ipairs(autolootItems) do
                item:moveTo(player)
            end
        end
       
        autolootContainer:remove()

        text = text .. '.'
           
        local party = player:getParty()
        if party then
            party:broadcastPartyLoot(text)
        else
            player:sendTextMessage(MESSAGE_INFO_DESCR, text)
        end
    end
end

ec:register()
aren't you checking for free slots in the player equipped backpack instead of the autolootContainer one?
 
aren't you checking for free slots in the player equipped backpack instead of the autolootContainer one?
Of course I am checking player backpack, because I want to know if he has the slots/cap to carry the items.
This was the reason why the items "disappeared". Script wasn't checking it at all, and was always moving the items to autolootContainer when the mob died.
In case player had not cap/slots it couldn't move the items to inventory, so it was just stuck in autolootContainer and the loot was gone.

Btw. (item_weight * 100) should be changed to just item_weight, I can't edit the post and don't know why it was even like that.
 
I'm getting this error when building solution:

iologindata.cpp(540,2): error C2065: 'query': undeclared identifier
iologindata.cpp(541,2): error C2065: 'query': undeclared identifier
iologindata.cpp(543,30): error C2065: 'query': undeclared identifier


Can somebody help me fix please? Using TFS 1.4, 10.98 version (latest release)

*edit
I was able to get it to work on TFS [1.4] by moving the //load autoloot code in iologindata.cpp further down to line 835, right before the /save autoloot list code. If anyone else gets this problem in 1.4, try this to solve it.

Thanks for an amazing auto loot system!

*edit again

I cannot get the autoloot to load lootlist correctly. Everything else works. If someone gets this script to work and load lootlist properly in [TFS 1.4], please share the solution 🥺

*edit again again
Obviously my moving of the code doesn't work... I cannot expect the code to load autoloot under a data saving function in the C++ code.. 😓
I'll update again again again if I find a way to load the autoloot query properly in the load sequence...

*as promised- edit again again again
I solved the loading issue by adding:
C++:
//load autoloot
    std::ostringstream query;//<-- this line
    query.str(std::string());
in the iologindata.cpp

Hope it helps someone else ;)
 
Last edited:
Hi! I tried to merge this at TFS 1.4 downgrade (8.60) and had this error
It says something about "query" is not defined, or not declared... did I do something wrong?

123456.png

Edit: woops sorry didn't saw the post above, because I wrote the post looking to the first page, thanks @krafttomten !!

Regards!
 
Not sure why, but this system ocasionally stops autolooting. It worked on some characters, and sometimes it just doesn't pick anything. Can't trigger any error logs 🤔
 
Back
Top