• 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 Index item a nil value

fironfox

New Member
Joined
Dec 14, 2012
Messages
42
Reaction score
1
Hello, good, this error is showing up straight in my distro and so far I could not identify what the cause of it ... Does anyone have any solution? My tfs is 1.2
This is error:
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>
        (...tail calls...)

This is onDestroyItem function on actions.lua:
Code:
function onDestroyItem(player, item, fromPosition, target, toPosition, isHotkey)
    if not target 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 targetId = target.itemid
    local destroyId = ItemType(targetId):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

        -- Against The Spider Cult (Spider Eggs)
        if targetId == 7585 then
            local eggStorage = player:getStorageValue(Storage.TibiaTales.AgainstTheSpiderCult)
            if eggStorage >= 1 and eggStorage < 5 then
                player:setStorageValue(Storage.TibiaTales.AgainstTheSpiderCult, math.max(1, eggStorage) + 1)
            end

            Game.createMonster("Giant Spider", Position(33181, 31869, 12))
        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
and this is the destroy.lua:
Code:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    return onDestroyItem(player, item, fromPosition, target, toPosition, isHotkey)
end

If anyone can help me I thank you !
 
Code:
    if not target or not target:isItem() then
        return false
    end

Can't call a method on a nil value.
Code:
function onDestroyItem(player, item, fromPosition, target, toPosition, isHotkey)
    -- if there is no target
    if not target then
        return false
    end
    -- if there is a target but it isn't an item
    if 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 targetId = target.itemid
    local destroyId = ItemType(targetId):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

        -- Against The Spider Cult (Spider Eggs)
        if targetId == 7585 then
            local eggStorage = player:getStorageValue(Storage.TibiaTales.AgainstTheSpiderCult)
            if eggStorage >= 1 and eggStorage < 5 then
                player:setStorageValue(Storage.TibiaTales.AgainstTheSpiderCult, math.max(1, eggStorage) + 1)
            end

            Game.createMonster("Giant Spider", Position(33181, 31869, 12))
        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
 
Back
Top