• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

Lua AUTO LOOT BUG HELP

Sigoles

Discord: @sigoles
Joined
Nov 20, 2015
Messages
1,209
Solutions
2
Reaction score
154
The system works, but appears on screen this error:

Code:
Lua Script Error: [Main Interface]
in a timer event called from:
(Unknown scriptfile)
data/creaturescripts/scripts/autoloot.lua:13: attempt to call method 'getSize' (a nil value)
stack traceback:
        [C]: in function 'getSize'
        data/creaturescripts/scripts/autoloot.lua:13: in function <data/creaturescripts/scripts/autoloot.lua:1>

Script:

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

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

    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)
            if containerItem then
                for b = AUTOLOOT_STORAGE_START, AUTOLOOT_STORAGE_END do
                    if player:getStorageValue(b) == containerItem:getId() then
                        containerItem:moveTo(player)
                    end
                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



Font: http://www.tibiaking.com/forum/forums/topic/63838-tfs-1x-autoloot-system/

Help to solve this error please :)
 
thanks but, how to solve this man? I copy this script :s

@Jeffro
the problem with the script is it's trying to call a method from something defined in the wrong place (you can't call a container method when the object is defined as a tile)

change
Code:
for a = 0, container:getSize()-1 do
add this above it
Code:
local container = Container(corpse.uid)
change
Code:
local containerItem = container:getItem(a)
 
Last edited:
@Xeraphus @Jeffro

I got another error now, look:

Code:
Lua Script Error: [Main Interface]
in a timer event called from:
(Unknown scriptfile)
data/creaturescripts/scripts/autoloot.lua:14: attempt to index local 'container' (a nil value)
stack traceback:
        [C]: in function '__index'
        data/creaturescripts/scripts/autoloot.lua:14: in function <data/creaturescripts/scripts/autoloot.lua:1>
 
@Xeraphus @Jeffro

I got another error now, look:

Code:
Lua Script Error: [Main Interface]
in a timer event called from:
(Unknown scriptfile)
data/creaturescripts/scripts/autoloot.lua:14: attempt to index local 'container' (a nil value)
stack traceback:
        [C]: in function '__index'
        data/creaturescripts/scripts/autoloot.lua:14: in function <data/creaturescripts/scripts/autoloot.lua:1>
try printing corpse and container and show me what it prints in console
 
why dont you provide the entire script here? some things are missing like
AUTOLOOT_STORAGE_START, AUTOLOOT_STORAGE_END

what id corpse are you trying to loot?
 
Last edited:
why dont you provide the entire script here? some things are missing like
AUTOLOOT_STORAGE_START, AUTOLOOT_STORAGE_END

what id corpse are you trying to loot?

Sorry, in global.lua
Its for all corpses

Code:
-- AutoLoot config
    AUTO_LOOT_MAX_ITEMS = 5

    -- Reserved storage
    AUTOLOOT_STORAGE_START = 10000
    AUTOLOOT_STORAGE_END = AUTOLOOT_STORAGE_START + AUTO_LOOT_MAX_ITEMS
-- AutoLoot config end
 
this?:

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

    local corpse = Tile(position):getTopDownItem()
    local container = Container(corpse.uid)
    if not corpse or not container then
        return
    end
   
   

    if corpse:getType():isCorpse() and corpse:getAttribute(ITEM_ATTRIBUTE_CORPSEOWNER) == cid then
    local container = Container(corpse.uid)
        for a = 0, container:getSize()-1 do
      
            local containerItem = container:getItem(a)
         
            if containerItem then
                for b = AUTOLOOT_STORAGE_START, AUTOLOOT_STORAGE_END do
                    if player:getStorageValue(b) == containerItem:getId() then
                        containerItem:moveTo(player)
                    end
                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
 
¬¬ all the soluctions mentioned is wrong, the problem is caused in items.xml, some corpses that not has the attribute key "corpseType" cause it ;) check it
 
Back
Top