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

My Autoloot System for TFS 0.4

did i put the if in a wrong place?
Code:
<event type="combat" name="AutolootRBTCombat" event="script">
<![CDATA[
local monsters = {
    ["rat"] = true,
    ["cave rat"] = true,
    ["demon"] = true,
    ["troll"] = true,
    ["rotworm"] = true,
}
if not monsters[getCreatureName(target):lower()] then
    registerCreatureEvent(target, "AutolootRBTDeath")
end
return true
]]>
</event>

@Alpha
 
did i put the if in a wrong place?
Code:
<event type="combat" name="AutolootRBTCombat" event="script">
<![CDATA[
local monsters = {
    ["rat"] = true,
    ["cave rat"] = true,
    ["demon"] = true,
    ["troll"] = true,
    ["rotworm"] = true,
}
if not monsters[getCreatureName(target):lower()] then
    registerCreatureEvent(target, "AutolootRBTDeath")
end
return true
]]>
</event>
bump
 
i'm trying to use @Sarah Wesker code (My Autoloot System for TFS 0.4 (https://otland.net/threads/my-autoloot-system-for-tfs-0-4.264702/)) with @Alpha suggestion (My Autoloot System for TFS 0.4 (https://otland.net/threads/my-autoloot-system-for-tfs-0-4.264702/post-2688617)), but it is not working here

!autoloot (legion helmet added)
Code:
Welcomen to Autoloot System Create by Millhiore BT Options: help, clear, add, remove You available slots: 3 Your autoloot items:  legion helmet

i kill a rotworm, drops a legion helmet
Code:
00:53 Loot of a rotworm: a legion helmet, a lump of dirt, a mace, ham, meat, 11 gold coins.
but the script didn't send it to my backpack

did i put the if in a wrong place?
Code:
<event type="combat" name="AutolootRBTCombat" event="script">
<![CDATA[
local monsters = {
    ["rat"] = true,
    ["cave rat"] = true,
    ["demon"] = true,
    ["troll"] = true,
    ["rotworm"] = true,
}
if not monsters[getCreatureName(target):lower()] then
    registerCreatureEvent(target, "AutolootRBTDeath")
end
return true
]]>
</event>

full code:
Code:
<?xml version="1.0" encoding="ISO-8859-1"?>
<mod name="Autoloot Revolution BT" version="1.0" author="Millhiore BT" contact="none.com" enabled="yes">
<config name="AutolootRevolutionBT">
<![CDATA[
---@ You configurations:
autolootConfig = {}
autolootConfig.storageItems = 27000
autolootConfig.blockMonsters = {}
autolootConfig.goldToBank = true
autolootConfig.goldBankAnimation = true
autolootConfig.distanceLooting = 7
autolootConfig.freeSlots = 3
autolootConfig.premiumSlots = 6
autolootConfig.vipStorage = {0,0}
autolootConfig.playerLevel = 8
autolootConfig.corpseEffect = CONST_ME_NONE
autolootConfig.golds = {2148, 2152, 2160}
autolootConfig.tittle = "Welcomen to Autoloot System\nCreate by Millhiore BT\n\nOptions: help, clear, add, remove\n"
autolootConfig.notHaveCapDrop = false
---@ getPlayerPremiumEnabled(cid)
--# Return boolean
--# Create by Millhiore BT
function getPlayerPremiumEnabled(cid)
    if getConfigValue("freePremium") then
        return true
    end
    return getPlayerPremiumDays(cid) > 0
end
---@ getPlayerAutolootVip(cid)
--# Return boolean
--# Create by Millhiore BT
function getPlayerAutolootVip(cid)
    if autolootConfig.vipStorage[1] > 0 then
        if autolootConfig.vipStorage[2] > 0 then
            return getPlayerStorageValue(cid, autolootConfig.vipStorage[1]) == autolootConfig.vipStorage[2]
        else
            return getPlayerStorageValue(cid, autolootConfig.vipStorage[1]) >= os.time()
        end
    end
    return true
end
---@ getPositionDistance(position, positionEx)
--# Return number
--# Create by Millhiore BT
function getPositionDistance(position, positionEx)
    return math.max(math.max(math.abs(position.x - positionEx.x), math.abs(position.y - positionEx.y)), math.abs(position.z - positionEx.z))
end
---@ getPositionCorpse(pos [, itemid])
--# Return thing/nil
--# Create by Millhiore BT
function getPositionCorpse(pos, itemid)
    local tile = getTileInfo(pos)
    for index = 0, tile.things do
        pos.stackpos = index
        local corpse = getThingFromPos(pos, false)
        if corpse.itemid > 1 and isCorpse(corpse.uid) then
            local itemid = itemid or corpse.itemid
            if corpse.itemid == itemid then
                return corpse
            end
        end
    end
end
---@ getContainerItems(uid [, array])
--# Return array
--# Create by Millhiore BT
function getContainerItems(container, array, haveCap)
    array = array or {}
    haveCap = haveCap or false
    if not isContainer(container.uid) or getContainerSize(container.uid) == 0 then
        array[#array +1] = container
    else
        local size = getContainerSize(container.uid)
        haveCap = (getContainerCap(container.uid) -size) > 0
        for slot = 0, (size -1) do
            local item = getContainerItem(container.uid, slot)
            if item.itemid > 1 then
                getContainerItems(item, array, haveCap)
            end
        end
    end
    return #array >= 1 and array, haveCap
end
---@ getContainerItemsById(array/uid, itemid)
--# Return array
--# Create by Millhiore BT
function getContainerItemsById(container, itemid)
    local founds = {}
    local items = not container.uid and container or getContainerItems(container)
    for index, item in pairs(items) do
        if item.itemid == itemid then
            founds[#founds +1] = item
        end
    end
    return #founds >= 1 and founds
end
---@ doPlayerAddItemStackable(cid, itemid, count)
--# Return boolean
--# Create by Millhiore BT
function doPlayerAddItemStackable(cid, itemid, count)
    local container = getPlayerSlotItem(cid, CONST_SLOT_BACKPACK)
    if container.itemid > 1 then
        local items = getContainerItemsById(container, itemid)
        if not items then
            return doPlayerAddItem(cid, itemid, count)
        else
            local piles = #items
            for index, item in pairs(items) do
                if item.type < 100 then
                    local sum = item.type + count
                    local result = doTransformItem(item.uid, itemid, sum)
                    if sum <= 100 then
                        return result
                    else
                        return doPlayerAddItem(cid, itemid, sum - 100)
                    end
                else
                    piles = piles - 1
                    if piles == 0 then
                        return doPlayerAddItem(cid, itemid, count)
                    end
                end
            end
        end
    end
    return false
end
---@ getContainerMoneys(items)
--# Return array/false
--# Create by Millhiore BT
function getContainerMoneys(items)
    local moneys = {}
    for slot, item in pairs(items) do
        if isInArray(autolootConfig.golds, item.itemid) then
            moneys[#moneys +1] = item
        end
    end
    return #moneys > 0 and moneys
end
---@ doCorpseAutoloot(cid, pos itemid)
--# Return boolean/nil
--# Create by Millhiore BT
function doCorpseAutoloot(cid, pos, itemid, moneys)
    if not getPlayerAutolootVip(cid) or getPositionDistance(getThingPosition(cid), pos) > autolootConfig.distanceLooting
    or getPlayerLevel(cid) < autolootConfig.playerLevel then
        return nil
    end
    local corpse = getPositionCorpse(pos, itemid)
    if corpse and isContainer(corpse.uid) then
        local items, haveCap = moneys or getContainerItems(corpse)
        local sendEffect = false
        if items then
            for slot, item in pairs(items) do
                if isInArray(getPlayerAutolootItems(cid), item.itemid) then
                    sendEffect = true
                    local removeIt = false
                    local goldToBank = autolootConfig.goldToBank and isInArray(autolootConfig.golds, item.itemid)
                    if not goldToBank then
                        if not haveCap and autolootConfig.notHaveCapDrop then
                            return doCorpseAutoloot(cid, pos, itemid, getContainerMoneys(items))
                        end
                        if isItemStackable(item.itemid) then
                            removeIt = doPlayerAddItemStackable(cid, item.itemid, item.type)
                        else
                            removeIt = doPlayerAddItem(cid, item.itemid)
                        end
                    else
                        local add = (getItemInfo(item.itemid).worth * item.type)
                        removeIt = doPlayerSetBalance(cid, getPlayerBalance(cid) + add)
                        if autolootConfig.goldBankAnimation then
                            doSendAnimatedText(pos, string.format("+%u gps", add), TEXTCOLOR_YELLOW, cid)
                        end
                    end
                    if removeIt then
                        doRemoveItem(item.uid)
                    end
                end
            end
            if sendEffect then
                doSendMagicEffect(pos, autolootConfig.corpseEffect, cid)
            end
            return true
        end
    end
end
---@ getPlayerAutolootItems(cid)
--# Return array
--# Create by Millhiore BT
function getPlayerAutolootItems(cid)
    local array = {}
    local content = tostring(getPlayerStorageValue(cid, autolootConfig.storageItems))
    for itemid in string.gmatch(content, "(%d+):") do
        array[#array +1] = tonumber(itemid)
    end
    return array
end
---@ getPlayerAutolootItem(cid, itemid)
--# Return number/nil
--# Create by Millhiore BT
function getPlayerAutolootItem(cid, itemid)
    local autolootItems = getPlayerAutolootItems(cid)
    for index, id in pairs(autolootItems) do
        if itemid == id then
            return index
        end
    end
end
---@ setPlayerAutolootItems(cid [, array])
--# Return boolean
--# Create by Millhiore BT
function setPlayerAutolootItems(cid, array)
    local array = array or {}
    local content = "&"
    for index, itemid in pairs(array) do
        content = string.format("%s%u:", content, itemid)
    end
    return setPlayerStorageValue(cid, autolootConfig.storageItems, content)
end
---@ addPlayerAutolootItem(cid, itemid)
--# Return boolean
--# Create by Millhiore BT
function addPlayerAutolootItem(cid, itemid)
    local autolootItems = getPlayerAutolootItems(cid)
    local found = getPlayerAutolootItem(cid, itemid)
    if not found then
        autolootItems[#autolootItems +1] = itemid
        return setPlayerAutolootItems(cid, autolootItems)
    end
end
---@ removePlayerAutolootItem(cid, itemid)
--# Return boolean/nil
--# Create by Millhiore BT
function removePlayerAutolootItem(cid, itemid)
    local autolootItems = getPlayerAutolootItems(cid)
    local found = getPlayerAutolootItem(cid, itemid)
    if found then
        table.remove(autolootItems, found)
        return setPlayerAutolootItems(cid, autolootItems)
    end
end
---@ showPlayerAutoloot(cid)
--# Return boolean
--# Create by Millhiore BT
function showPlayerAutoloot(cid)
    local maxItems = getPlayerPremiumEnabled(cid) and autolootConfig.premiumSlots or autolootConfig.freeSlots
    local content = string.format("%sYou available slots: %u\n\n%s", autolootConfig.tittle, maxItems, "Your autoloot items:\n")
    local autolootItems = getPlayerAutolootItems(cid)
    for index, itemid in pairs(autolootItems) do
        local it = getItemInfo(itemid)
        content = string.format("%s %c %s\n", content, 155, it.name)
    end
    return doShowTextDialog(cid, 2529, content)
end
---@ showPlayerAutolootHelp(cid)
--# Return boolean
--# Create by Millhiore BT
function showPlayerAutolootHelp(cid)
    local content = autolootConfig.tittle .. "For you info:\n"
    for key, value in pairs(autolootConfig) do
        if not isInArray({"storageItems", "blockMonsters", "vipStorage", "golds", "tittle"}, key) then
            content = string.format("%s%c %s: %s\n", content, 155, tostring(key), tostring(value))
        end
    end
    return doShowTextDialog(cid, 2529, content)
end
]]>
</config>
<event type="login" name="AutolootRBTLogin" event="script">
<![CDATA[
function onLogin(cid)
    local maxItems = getPlayerPremiumEnabled(cid) and autolootConfig.premiumSlots or autolootConfig.freeSlots
    local autolootItems = getPlayerAutolootItems(cid)
    if #autolootItems > maxItems then
        for index = autolootConfig.premiumSlots, autolootConfig.freeSlots, -1 do
            table.remove(autolootItems, index)
        end
        setPlayerAutolootItems(cid, autolootItems)
        doPlayerSendCancel(cid, "Your list of items overflowed, you should check your list.")
    end
    registerCreatureEvent(cid, "AutolootRBTCombat")
    return true
end
]]>
</event>
<event type="death" name="AutolootRBTDeath" event="script">
<![CDATA[
domodlib("AutolootRevolutionBT")
function onDeath(cid, corpse, deathList)
    local killer = deathList[1]
    local position = getThingPosition(cid)
    if corpse.itemid > 1 then
        addEvent(doCorpseAutoloot, 100, killer, position, corpse.itemid)
    end
    return true
end
]]>
</event>
<event type="combat" name="AutolootRBTCombat" event="script">
<![CDATA[
local monsters = {
    ["rat"] = true,
    ["cave rat"] = true,
    ["demon"] = true,
    ["troll"] = true,
    ["rotworm"] = true,
}
if not monsters[getCreatureName(target):lower()] then
    registerCreatureEvent(target, "AutolootRBTDeath")
end
return true
]]>
</event>
<talkaction words="!autoloot;/autoloot" event="buffer">
<![CDATA[
domodlib("AutolootRevolutionBT")
local split = string.explode(param, ",") or {}
local action = tostring(split[1]):lower()
local name = tostring(split[2])
local itemid = getItemIdByName(name, false)
local it = getItemInfo(itemid and itemid or 0)
local position = getThingPosition(cid)
if action == "add" then
    if not it then
        doPlayerSendCancel(cid, string.format("This item %s does not exist.", name))
    else
        local maxItems = getPlayerPremiumEnabled(cid) and autolootConfig.premiumSlots or autolootConfig.freeSlots
        local autolootItems = getPlayerAutolootItems(cid)
        if #autolootItems > maxItems then
            for index = autolootConfig.premiumSlots, autolootConfig.freeSlots, -1 do
                table.remove(autolootItems, index)
            end
            setPlayerAutolootItems(cid, autolootItems)
            doPlayerSendCancel(cid, "Your list of items overflowed, you should check your list.")
        elseif #autolootItems == maxItems then
            doPlayerSendCancel(cid, string.format("Your maximum limit is %u items, you must eliminate one to add another.", maxItems))
        elseif addPlayerAutolootItem(cid, itemid) then
            doPlayerSendCancel(cid, string.format("You added the item %s in the list.", name))
        else
            doSendMagicEffect(position, CONST_ME_POFF, cid)
            doPlayerSendCancel(cid, string.format("This item %s already in the list.", name))
        end
    end
elseif action == "remove" then
    if not it then
        doPlayerSendCancel(cid, string.format("This item %s does not exist.", name))
    else
        if removePlayerAutolootItem(cid, itemid) then
            doPlayerSendCancel(cid, string.format("You removed the item %s from the list.", name))
        else
            doPlayerSendCancel(cid, string.format("This item %s is not in the list.", name))
        end
    end
elseif action == "help" then
    showPlayerAutolootHelp(cid)
elseif action == "clear" then
    setPlayerAutolootItems(cid)
    doPlayerSendCancel(cid, "The list of items is now empty.")
else
    showPlayerAutoloot(cid)
end
return true
]]>
</talkaction>
</mod>

idk what to do? anybody does?
 
Last edited:
Hello,
I made this event few years ago and since it's already free on internet because of some open source maniacs, I brought it to here
I have seen people selling it like it was of their own, so to avoid that, here it is
Let me me know if some code is missing. Too much time w/o seeing this code xD.
 
Hey guys. I just saw some people in another post saying something along the lines of "I cannot understand how people would uso a macro to autoloot these days" and wanted to give some of my perspective as well as hear about it from you guys.

Now, I am scared shitless about losing my character and I don't use it, so as an EK past level 800 who tries to team hunt here an there I'll tell you something: it is kind of expected that you do.

You are effectively affecting your team xp/h if you are not using it because you will lose an extra second or two pretty much every box. When people reach a certain level they start really caring about their xp/h, so if you are costing them xp they will start to get pissy about it. They might even start pressuring you to use it because "every other ek is using it". So, if you are scared to lose your character like me, you'll eventually get replaced.

I don't agree with using any kind of macros to play the game, but Cip needs to do something about this (I can dream). Either cracking down on it or making their own autoloot. The way this is now, the only people getting fucked are the people who refuse to use it. It has been like this for years and it makes no sense.





 
I recognize that there are already some systems that deal with the same, but this had been saved for some time and I want to share it with you now more than ever, as I plan to resume my stay as a scriptwriter, so this will be a good start. thanks!

go to their folder "mods" and create a new file "xml" with the name you want and paste the following code:
Code:
<?xml version="1.0" encoding="ISO-8859-1"?>
<mod name="Autoloot Revolution BT" version="1.0" author="Millhiore BT" contact="none.com" enabled="yes">
<config name="AutolootRevolutionBT">
<![CDATA[
---@ You configurations:
autolootConfig = {}
autolootConfig.storageItems = 27000
autolootConfig.blockMonsters = {}
autolootConfig.goldToBank = true
autolootConfig.goldBankAnimation = true
autolootConfig.distanceLooting = 7
autolootConfig.freeSlots = 3
autolootConfig.premiumSlots = 6
autolootConfig.vipStorage = {0,0}
autolootConfig.playerLevel = 8
autolootConfig.corpseEffect = CONST_ME_NONE
autolootConfig.golds = {2148, 2152, 2160}
autolootConfig.tittle = "Welcomen to Autoloot System\nCreate by Millhiore BT\n\nOptions: help, clear, add, remove\n"
autolootConfig.notHaveCapDrop = false
---@ getPlayerPremiumEnabled(cid)
--# Return boolean
--# Create by Millhiore BT
function getPlayerPremiumEnabled(cid)
    if getConfigValue("freePremium") then
        return true
    end
    return getPlayerPremiumDays(cid) > 0
end
---@ getPlayerAutolootVip(cid)
--# Return boolean
--# Create by Millhiore BT
function getPlayerAutolootVip(cid)
    if autolootConfig.vipStorage[1] > 0 then
        if autolootConfig.vipStorage[2] > 0 then
            return getPlayerStorageValue(cid, autolootConfig.vipStorage[1]) == autolootConfig.vipStorage[2]
        else
            return getPlayerStorageValue(cid, autolootConfig.vipStorage[1]) >= os.time()
        end
    end
    return true
end
---@ getPositionDistance(position, positionEx)
--# Return number
--# Create by Millhiore BT
function getPositionDistance(position, positionEx)
    return math.max(math.max(math.abs(position.x - positionEx.x), math.abs(position.y - positionEx.y)), math.abs(position.z - positionEx.z))
end
---@ getPositionCorpse(pos [, itemid])
--# Return thing/nil
--# Create by Millhiore BT
function getPositionCorpse(pos, itemid)
    local tile = getTileInfo(pos)
    for index = 0, tile.things do
        pos.stackpos = index
        local corpse = getThingFromPos(pos, false)
        if corpse.itemid > 1 and isCorpse(corpse.uid) then
            local itemid = itemid or corpse.itemid
            if corpse.itemid == itemid then
                return corpse
            end
        end
    end
end
---@ getContainerItems(uid [, array])
--# Return array
--# Create by Millhiore BT
function getContainerItems(container, array, haveCap)
    array = array or {}
    haveCap = haveCap or false
    if not isContainer(container.uid) or getContainerSize(container.uid) == 0 then
        array[#array +1] = container
    else
        local size = getContainerSize(container.uid)
        haveCap = (getContainerCap(container.uid) -size) > 0
        for slot = 0, (size -1) do
            local item = getContainerItem(container.uid, slot)
            if item.itemid > 1 then
                getContainerItems(item, array, haveCap)
            end
        end
    end
    return #array >= 1 and array, haveCap
end
---@ getContainerItemsById(array/uid, itemid)
--# Return array
--# Create by Millhiore BT
function getContainerItemsById(container, itemid)
    local founds = {}
    local items = not container.uid and container or getContainerItems(container)
    for index, item in pairs(items) do
        if item.itemid == itemid then
            founds[#founds +1] = item
        end
    end
    return #founds >= 1 and founds
end
---@ doPlayerAddItemStackable(cid, itemid, count)
--# Return boolean
--# Create by Millhiore BT
function doPlayerAddItemStackable(cid, itemid, count)
    local container = getPlayerSlotItem(cid, CONST_SLOT_BACKPACK)
    if container.itemid > 1 then
        local items = getContainerItemsById(container, itemid)
        if not items then
            return doPlayerAddItem(cid, itemid, count)
        else
            local piles = #items
            for index, item in pairs(items) do
                if item.type < 100 then
                    local sum = item.type + count
                    local result = doTransformItem(item.uid, itemid, sum)
                    if sum <= 100 then
                        return result
                    else
                        return doPlayerAddItem(cid, itemid, sum - 100)
                    end
                else
                    piles = piles - 1
                    if piles == 0 then
                        return doPlayerAddItem(cid, itemid, count)
                    end
                end
            end
        end
    end
    return false
end
---@ getContainerMoneys(items)
--# Return array/false
--# Create by Millhiore BT
function getContainerMoneys(items)
    local moneys = {}
    for slot, item in pairs(items) do
        if isInArray(autolootConfig.golds, item.itemid) then
            moneys[#moneys +1] = item
        end
    end
    return #moneys > 0 and moneys
end
---@ doCorpseAutoloot(cid, pos itemid)
--# Return boolean/nil
--# Create by Millhiore BT
function doCorpseAutoloot(cid, pos, itemid, moneys)
    if not getPlayerAutolootVip(cid) or getPositionDistance(getThingPosition(cid), pos) > autolootConfig.distanceLooting
    or getPlayerLevel(cid) < autolootConfig.playerLevel then
        return nil
    end
    local corpse = getPositionCorpse(pos, itemid)
    if corpse and isContainer(corpse.uid) then
        local items, haveCap = moneys or getContainerItems(corpse)
        local sendEffect = false
        if items then
            for slot, item in pairs(items) do
                if isInArray(getPlayerAutolootItems(cid), item.itemid) then
                    sendEffect = true
                    local removeIt = false
                    local goldToBank = autolootConfig.goldToBank and isInArray(autolootConfig.golds, item.itemid)
                    if not goldToBank then
                        if not haveCap and autolootConfig.notHaveCapDrop then
                            return doCorpseAutoloot(cid, pos, itemid, getContainerMoneys(items))
                        end
                        if isItemStackable(item.itemid) then
                            removeIt = doPlayerAddItemStackable(cid, item.itemid, item.type)
                        else
                            removeIt = doPlayerAddItem(cid, item.itemid)
                        end
                    else
                        local add = (getItemInfo(item.itemid).worth * item.type)
                        removeIt = doPlayerSetBalance(cid, getPlayerBalance(cid) + add)
                        if autolootConfig.goldBankAnimation then
                            doSendAnimatedText(pos, string.format("+%u gps", add), TEXTCOLOR_YELLOW, cid)
                        end
                    end
                    if removeIt then
                        doRemoveItem(item.uid)
                    end
                end
            end
            if sendEffect then
                doSendMagicEffect(pos, autolootConfig.corpseEffect, cid)
            end
            return true
        end
    end
end
---@ getPlayerAutolootItems(cid)
--# Return array
--# Create by Millhiore BT
function getPlayerAutolootItems(cid)
    local array = {}
    local content = tostring(getPlayerStorageValue(cid, autolootConfig.storageItems))
    for itemid in string.gmatch(content, "(%d+):") do
        array[#array +1] = tonumber(itemid)
    end
    return array
end
---@ getPlayerAutolootItem(cid, itemid)
--# Return number/nil
--# Create by Millhiore BT
function getPlayerAutolootItem(cid, itemid)
    local autolootItems = getPlayerAutolootItems(cid)
    for index, id in pairs(autolootItems) do
        if itemid == id then
            return index
        end
    end
end
---@ setPlayerAutolootItems(cid [, array])
--# Return boolean
--# Create by Millhiore BT
function setPlayerAutolootItems(cid, array)
    local array = array or {}
    local content = "&"
    for index, itemid in pairs(array) do
        content = string.format("%s%u:", content, itemid)
    end
    return setPlayerStorageValue(cid, autolootConfig.storageItems, content)
end
---@ addPlayerAutolootItem(cid, itemid)
--# Return boolean
--# Create by Millhiore BT
function addPlayerAutolootItem(cid, itemid)
    local autolootItems = getPlayerAutolootItems(cid)
    local found = getPlayerAutolootItem(cid, itemid)
    if not found then
        autolootItems[#autolootItems +1] = itemid
        return setPlayerAutolootItems(cid, autolootItems)
    end
end
---@ removePlayerAutolootItem(cid, itemid)
--# Return boolean/nil
--# Create by Millhiore BT
function removePlayerAutolootItem(cid, itemid)
    local autolootItems = getPlayerAutolootItems(cid)
    local found = getPlayerAutolootItem(cid, itemid)
    if found then
        table.remove(autolootItems, found)
        return setPlayerAutolootItems(cid, autolootItems)
    end
end
---@ showPlayerAutoloot(cid)
--# Return boolean
--# Create by Millhiore BT
function showPlayerAutoloot(cid)
    local maxItems = getPlayerPremiumEnabled(cid) and autolootConfig.premiumSlots or autolootConfig.freeSlots
    local content = string.format("%sYou available slots: %u\n\n%s", autolootConfig.tittle, maxItems, "Your autoloot items:\n")
    local autolootItems = getPlayerAutolootItems(cid)
    for index, itemid in pairs(autolootItems) do
        local it = getItemInfo(itemid)
        content = string.format("%s %c %s\n", content, 155, it.name)
    end
    return doShowTextDialog(cid, 2529, content)
end
---@ showPlayerAutolootHelp(cid)
--# Return boolean
--# Create by Millhiore BT
function showPlayerAutolootHelp(cid)
    local content = autolootConfig.tittle .. "For you info:\n"
    for key, value in pairs(autolootConfig) do
        if not isInArray({"storageItems", "blockMonsters", "vipStorage", "golds", "tittle"}, key) then
            content = string.format("%s%c %s: %s\n", content, 155, tostring(key), tostring(value))
        end
    end
    return doShowTextDialog(cid, 2529, content)
end
]]>
</config>
<event type="login" name="AutolootRBTLogin" event="script">
<![CDATA[
function onLogin(cid)
    local maxItems = getPlayerPremiumEnabled(cid) and autolootConfig.premiumSlots or autolootConfig.freeSlots
    local autolootItems = getPlayerAutolootItems(cid)
    if #autolootItems > maxItems then
        for index = autolootConfig.premiumSlots, autolootConfig.freeSlots, -1 do
            table.remove(autolootItems, index)
        end
        setPlayerAutolootItems(cid, autolootItems)
        doPlayerSendCancel(cid, "Your list of items overflowed, you should check your list.")
    end
    registerCreatureEvent(cid, "AutolootRBTCombat")
    return true
end
]]>
</event>
<event type="death" name="AutolootRBTDeath" event="script">
<![CDATA[
domodlib("AutolootRevolutionBT")
function onDeath(cid, corpse, deathList)
    local killer = deathList[1]
    local position = getThingPosition(cid)
    if corpse.itemid > 1 then
        addEvent(doCorpseAutoloot, 100, killer, position, corpse.itemid)
    end
    return true
end
]]>
</event>
<event type="combat" name="AutolootRBTCombat" event="script">
<![CDATA[
if isPlayer(cid) and isMonster(target) then
    registerCreatureEvent(target, "AutolootRBTDeath")
end
return true
]]>
</event>
<talkaction words="!autoloot;/autoloot" event="buffer">
<![CDATA[
domodlib("AutolootRevolutionBT")
local split = string.explode(param, ",") or {}
local action = tostring(split[1]):lower()
local name = tostring(split[2])
local itemid = getItemIdByName(name, false)
local it = getItemInfo(itemid and itemid or 0)
local position = getThingPosition(cid)
if action == "add" then
    if not it then
        doPlayerSendCancel(cid, string.format("This item %s does not exist.", name))
    else
        local maxItems = getPlayerPremiumEnabled(cid) and autolootConfig.premiumSlots or autolootConfig.freeSlots
        local autolootItems = getPlayerAutolootItems(cid)
        if #autolootItems > maxItems then
            for index = autolootConfig.premiumSlots, autolootConfig.freeSlots, -1 do
                table.remove(autolootItems, index)
            end
            setPlayerAutolootItems(cid, autolootItems)
            doPlayerSendCancel(cid, "Your list of items overflowed, you should check your list.")
        elseif #autolootItems == maxItems then
            doPlayerSendCancel(cid, string.format("Your maximum limit is %u items, you must eliminate one to add another.", maxItems))
        elseif addPlayerAutolootItem(cid, itemid) then
            doPlayerSendCancel(cid, string.format("You added the item %s in the list.", name))
        else
            doSendMagicEffect(position, CONST_ME_POFF, cid)
            doPlayerSendCancel(cid, string.format("This item %s already in the list.", name))
        end
    end
elseif action == "remove" then
    if not it then
        doPlayerSendCancel(cid, string.format("This item %s does not exist.", name))
    else
        if removePlayerAutolootItem(cid, itemid) then
            doPlayerSendCancel(cid, string.format("You removed the item %s from the list.", name))
        else
            doPlayerSendCancel(cid, string.format("This item %s is not in the list.", name))
        end
    end
elseif action == "help" then
    showPlayerAutolootHelp(cid)
elseif action == "clear" then
    setPlayerAutolootItems(cid)
    doPlayerSendCancel(cid, "The list of items is now empty.")
else
    showPlayerAutoloot(cid)
end
return true
]]>
</talkaction>
</mod>
that's it all!

The command is:
Code:
!autoloot
!autoloot help
!autoloot clear
!autoloot add
!autoloot remove

How to configure it?
in the first lines you will find the following:
Code:
---@ You configurations:
autolootConfig = {}
autolootConfig.storageItems = 27000
autolootConfig.blockMonsters = {}
autolootConfig.goldToBank = true
autolootConfig.goldBankAnimation = true
autolootConfig.distanceLooting = 7
autolootConfig.freeSlots = 3
autolootConfig.premiumSlots = 6
autolootConfig.vipStorage = {0,0}
autolootConfig.playerLevel = 8
autolootConfig.corpseEffect = CONST_ME_NONE
autolootConfig.golds = {2148, 2152, 2160}
autolootConfig.tittle = "Welcomen to Autoloot System\nCreate by Millhiore BT\n\nOptions: help, clear, add, remove\n"
autolootConfig.notHaveCapDrop = false

Notes:
  • I'm not sure if it works 100%, but I can assure +/- 99%
  • If you want to help me improve it, you are welcome to do it.
  • The system eliminates the elements that exceed the limit automatically, for example when you lose "premium".
Not sure if this is still up to date. If not, and anyone else know of another Autoloot for 8.6 0.4, please let me know.

I am currently facing this error in console, 8.6, 0.4


Lua:
[Error - CreatureScript Interface]
In a timer event called from:
domodlib("AutolootRevolutionBT")
function onDeath(cid, corpse, deathList)
    local killer = deathList[1]
    local position = getThingPosition(cid)
    if corpse.itemid > 1 then
        addEvent(doCorpseAutoloot, 100, killer, position, corpse.itemid)
    end
    return true
end
:onDeath
Description:
(luaGetThingPosition) Thing not found

[Error - CreatureScript Interface]
In a timer event called from:
domodlib("AutolootRevolutionBT")
function onDeath(cid, corpse, deathList)
    local killer = deathList[1]
    local position = getThingPosition(cid)
    if corpse.itemid > 1 then
        addEvent(doCorpseAutoloot, 100, killer, position, corpse.itemid)
    end
    return true
end
:onDeath
Description:
[string "---@ You configurations:..."]:42: attempt to index local 'position' (a boolean value)
stack traceback:
        [string "---@ You configurations:..."]:42: in function 'getPositionDistance'
        [string "---@ You configurations:..."]:140: in function <[string "---@ You configurations:..."]:139>
 
Hi,
Thanks for the script :D
Works nicely on tfs 0.4 despite what the comments above say. Though, I need to say, before testing I actually deleted half of the code so I won't bet my hand on the errors above being actually correct XD (I needed only gold looting and that done by having a pet creature, so a lot was removed)
edit; actually, in deathList[1], it isn't always player who kills the creature, it could be a summon and in that case there was still error. Yeah, I know about the check in combat:
Lua:
if isPlayer(cid) and isMonster(target) then
but it was somehow skipped and in onDeath the code wouldn't work.
There is a need for:

Lua:
domodlib("AutolootRevolutionBT")
function onDeath(cid, corpse, deathList)
    local killer = deathList[1]
    if not isPlayer(killer) then
        killer = getCreatureMaster(killer)
    end
 
Last edited:
I think we can check if item has worth instead of "isInArray(autolootConfig.golds, item.itemid)". This way, this doesn't even require to update the array whenever a new currency is added in items.xml. Though, I'm not sure which way is more optimal...
 
Back
Top