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

Lua bug with autoloot

TiagoTwo

New Member
Joined
Feb 5, 2013
Messages
18
Reaction score
0
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>

autoloot.lua
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 i = corpse:getSize() - 1, 0, -1 do
local containerItem = corpse:getItem(i)
if containerItem then
for i = AUTOLOOT_STORAGE_START, AUTOLOOT_STORAGE_END do
if player:getStorageValue(i) == 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
 
Solution
so, the corpse that can't open is the "bug"?
yes, you cannot use container methods on an item that is not a container
for example: you cant use container:getSize() on a tree, because it is not a container.
to fix this bug:
before for i = container:getSize()-1, 0, -1 do: put everything from there below inside this:
Code:
if ItemType(corpse:getId()):isContainer() then
    for i = corpse:getSize()-1, 0, -1 do
        ...
    end
end
is the corpse actually a container, like can you open it?
it should inherit container along with item as long as it's openable
 
so, the corpse that can't open is the "bug"?
yes, you cannot use container methods on an item that is not a container
for example: you cant use container:getSize() on a tree, because it is not a container.
to fix this bug:
before for i = container:getSize()-1, 0, -1 do: put everything from there below inside this:
Code:
if ItemType(corpse:getId()):isContainer() then
    for i = corpse:getSize()-1, 0, -1 do
        ...
    end
end
 
Solution
lol
quick fix
Code:
local corpse = Tile(position):getTopDownItem()
    if not corpse or not corpse:isContainer() then
        return
    end
 
yes, you cannot use container methods on an item that is not a container
for example: you cant use container:getSize() on a tree, because it is not a container.
to fix this bug:
before for i = container:getSize()-1, 0, -1 do: put everything from there below inside this:
Code:
if ItemType(corpse:getId()):isContainer() then
    for i = corpse:getSize()-1, 0, -1 do
        ...
    end
end

Thanks, is Working :)

-----

lol
quick fix
Code:
local corpse = Tile(position):getTopDownItem()
    if not corpse or not corpse:isContainer() then
        return
    end

thanks too, I don't test your code, but I guess other peoples have the same issue with me, can help them, thanks too :)
 
well, my code is just the inverse of xera... he check if is container, and I check if not is container
I saw, hey, do you know tutorial about lua ? I want to learn, tfs 1.2, have a suggestion for me ? is it possible ? sorry to comment this here .. I have a server 10.99 and I want to do some Scripts
 
Back
Top