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

Solved TFS 1.2 interesting bug with destroy.lua onDestroyItem, added video and ss to explain

Shadow Dan

Sh4dowDan
Joined
Jun 5, 2010
Messages
344
Reaction score
88
Location
Poland
Code:
Lua Script Error: [Action Interface]
data/actions/scripts/other/destroy.lua:onUse
data/actions/lib/actions.lua:89: attempt to call method 'isItem' (a nil value)
stack traceback:
        [C]: in function 'isItem'
        data/actions/lib/actions.lua:89: in function <data/actions/lib/actions.lua:88>

If you stand on this position and use sword (or any weapon that uses script destroy.lua) on wall
red = bug in console
green = no bug all fine
201507170_waaxxnh.png

201507170_waaxxnq.png

So bug happens when you are behind the wall and use sword on it.
actions/lib/actions.lua
Code:
88 function onDestroyItem(player, item, fromPosition, target, toPosition, isHotkey)
89     if not target or not target:isItem() then
90         return false
91     end
destroy.lua
Code:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    return onDestroyItem(player, item, fromPosition, target, toPosition, isHotkey)
end

I couldn't explain it easier, maybe it's known bug or not, let's see what scripters will say. I'm really curious why that happens.

#I'll edit soon to add video. It's in progress to be available.
 
I would have to assume it's to do with walls being inaccessible from one side. Imagine if you could access the item on the wall. If there was a trophy or tapestry there, you could take it. I believe it considers the item to be nil if accessing it from that side, and thus, target is not a thing, so isItem() cannot be called on it. If you do Item(target):isItem() it should stop erroring.
 
If i do:
Code:
if not target or not Item(target):isItem() then
it is erroring from every side.
Code:
Lua Script Error: [Action Interface]
data/actions/scripts/other/destroy.lua:onUse
data/actions/lib/actions.lua:89: attempt to index a nil value
stack traceback:
        [C]: in function '__index'
        data/actions/lib/actions.lua:89: in function <data/actions/lib/actions.lua:88>
I'm waiting for more ideas.
 
this is my actions.lua
Code:
function destroyItem(player, target, toPosition)
    if target == nil or not target:isItem() then
        return false
    end

    if target:hasAttribute(ITEM_ATTRIBUTE_UNIQUEID) or target:hasAttribute(ITEM_ATTRIBUTE_ACTIONID) then
        return false
    end

    if toPosition.x == CONTAINER_POSITION then
        player:sendCancelMessage(Game.getReturnMessage(RETURNVALUE_NOTPOSSIBLE))
        return true
    end

    local destroyId = ItemType(target.itemid):getDestroyId()
    if destroyId == 0 then
        return false
    end

    if math.random(7) == 1 then
        local item = Game.createItem(destroyId, 1, toPosition)
        if item ~= nil then
            item:decay()
        end

        -- Move items outside the container
        if target:isContainer() then
            for i = target:getSize() - 1, 0, -1 do
                  local containerItem = target:getItem(i)
                if containerItem then
                    containerItem:moveTo(toPosition)
                end
            end
        end

        target:remove(1)
    end

    toPosition:sendMagicEffect(CONST_ME_POFF)
    return true
end
 
You may wonder why target is unable to call the method isItem, and it's because target becomes an array when it's being targeted from an "inaccessable" position.

Edit:

You can make the error disappear by changing
Code:
if not target or not target:isItem() then
to
Code:
if not target or type(target) ~= "userdata" or not target:isItem() then
 
I don't believe it's an issue, as I posted, my actions.lua is different. As is the one on the github. I think yours is just outdated. Update and see if it works.
 
My lib/actions.lua has 670 lines and yours 41.
I have lastest files from github.

Btw. i tested your code and same error so please don't say its fault because of outdated files.
I downloaded it few days ago.
 
Well i don't like bumping old threads but i ran into the same problem and found out why, I'm working on a comletely custom ot where i cleaned all my sprites and items in item.otb and tibia.dat, and for those who also have this problem my problem was that i just needed to change the item to multi use in item.otb (was making a schythe that should destoy hay :>
 
Back
Top