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

Problem with autoloot

kaparzo231

New Member
Joined
Mar 22, 2022
Messages
29
Solutions
1
Reaction score
4
Location
Poland
GitHub
XxX
Hey,

Tibia 8.60
The Forgotten Server 0.4

After using the commands !autoloot add name: I can't add items but a table appears:

autoloot.jpg

I have no bugs:

server.jpg

mods/Autoloot.xml:

XML:
<?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[
domodlib("AutolootRevolutionBT")
if isPlayer(cid) and isMonster(target) then
    if not isInArray(autolootConfig.blockMonsters, string.lower(getCreatureName(target))) then
        registerCreatureEvent(target, "AutolootRBTDeath")
    end
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>


I will be grateful for any suggestions on how to fix this error
 
Solution
I don't see anything wrong with it.

The only way to show the autoloot window is if none of the other commands are being found.

Try it like this. The comma is important.
/autoloot add, gold coin
I don't see anything wrong with it.

The only way to show the autoloot window is if none of the other commands are being found.

Try it like this. The comma is important.
/autoloot add, gold coin
 
Solution
Back
Top