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

kor

PHP ziom
Premium User
Joined
Jul 12, 2008
Messages
252
Solutions
13
Reaction score
410
Location
Bialystok, Poland
GitHub
rookgaard
YouTube
Rookgaard
Hello. Inspired psychonaut's solution I've adjusted it for latest TFS code (loot is generated now in LUA instead of C++). This one is different from login12's and nekiro's where you have to click on corpse to get loot - now it will land in your backpack right after monster death. I can prepare similar solution for 0.4 if there are enough votes for it (let's say 2).

I won't post what to change in what line, instead here you have GitHub branch:
- otland/forgottenserver (https://github.com/otland/forgottenserver/compare/master...rookgaard:feature/autoloot)

You will have to also run this SQL command
SQL:
CREATE TABLE IF NOT EXISTS `player_autoloot` (
  `player_id` int(11) NOT NULL,
  `list` blob,
  UNIQUE KEY `player_id` (`player_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

I've prepared two usage examples:
  • first by using rope (can be another item which have "use with" option) on item inside container (that way you won't add dustbin or tree)
  • second by using talkaction

Main difference is inside data/events/scripts/monster.lua where every autolooted item from corpse (gathered by custom method from data/lib/core/container.lua) is moved to virtual container and later moved to player - that way it will stack items like gold.

Feel free to ask any question regarding to this. Hope you enjoy :)
 
It will work for 1.3 tfs downgraded to 8.6? And used by cips client?
 
Hello. Inspired psychonaut's solution I've adjusted it for latest TFS code (loot is generated now in LUA instead of C++). This one is different from login12's and nekiro's where you have to click on corpse to get loot - now it will land in your backpack right after monster death. I can prepare similar solution for 0.4 if there are enough votes for it (let's say 2).

I won't post what to change in what line, instead here you have GitHub branch:
- otland/forgottenserver (https://github.com/otland/forgottenserver/compare/master...rookgaard:feature/autoloot)

You will have to also run this SQL command
SQL:
CREATE TABLE IF NOT EXISTS `player_autoloot` (
  `player_id` int(11) NOT NULL,
  `list` blob,
  UNIQUE KEY `player_id` (`player_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

I've prepared two usage examples:
  • first by using rope (can be another item which have "use with" option) on item inside container (that way you won't add dustbin or tree)
  • second by using talkaction

Main difference is inside data/events/scripts/monster.lua where every autolooted item from corpse (gathered by custom method from data/lib/core/container.lua) is moved to virtual container and later moved to player - that way it will stack items like gold.

Feel free to ask any question regarding to this. Hope you enjoy :)

Wait a second.
You said "virtual container"?

Code:
local autolootContainer = Game.createItem(1987, 1)

It look's nice. Can I open container in player inventory that doesn't exist on map or his inventory?
Or I can just use it in similar scenario like here?

Great idea!
 
Well, you can do (almost) everything you imagine - it's just need to be coded :) But in my case "virtual" means it lays only in memory, because it's never assigned to a player - only items from inside.
 
Hello. Inspired psychonaut's solution I've adjusted it for latest TFS code (loot is generated now in LUA instead of C++). This one is different from login12's and nekiro's where you have to click on corpse to get loot - now it will land in your backpack right after monster death. I can prepare similar solution for 0.4 if there are enough votes for it (let's say 2).

I won't post what to change in what line, instead here you have GitHub branch:
- otland/forgottenserver (https://github.com/otland/forgottenserver/compare/master...rookgaard:feature/autoloot)

You will have to also run this SQL command
SQL:
CREATE TABLE IF NOT EXISTS `player_autoloot` (
  `player_id` int(11) NOT NULL,
  `list` blob,
  UNIQUE KEY `player_id` (`player_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

I've prepared two usage examples:
  • first by using rope (can be another item which have "use with" option) on item inside container (that way you won't add dustbin or tree)
  • second by using talkaction

Main difference is inside data/events/scripts/monster.lua where every autolooted item from corpse (gathered by custom method from data/lib/core/container.lua) is moved to virtual container and later moved to player - that way it will stack items like gold.

Feel free to ask any question regarding to this. Hope you enjoy :)

Im not sure by isnt there a memory leak cuz u're creating container item every time someone kill a mob and then not remove it? Shoudnt you use autolootContainer:remove() after that?
 
@gicu0770 You can get the list before adding item and then compare
Lua:
local autoLootList = player:getAutoLootList()

if (#autoLootList > LIMIT) then
  return player:sendCancelMessage("Sorry, you can't add more items to the list.")
end
Thanks you.
Post automatically merged:

@gicu0770 You can get the list before adding item and then compare
Lua:
local autoLootList = player:getAutoLootList()

if (#autoLootList > LIMIT) then
  return player:sendCancelMessage("Sorry, you can't add more items to the list.")
end
Sorry do you can created command remove all ?
 
question

i did put gold coin as autolooting
after my bp was full
he still looted the gold coins but where is it then?
 
So can people config ingame what items they want to loot or did it loot everything? Cuz thats what it sounds like..
 
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()
 
Back
Top