• 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 Depot items error

Raggaer

Godly Member
Joined
Jul 25, 2012
Messages
1,557
Solutions
8
Reaction score
957
Location
Spain
Im using TFS 1.0 Compiled like 3 days ago, the error output is

Code:
Lua Script Error: [MoveEvents Interface]
data/movements/scripts/tiles.lua:onStepIn
data/movements/scripts/tiles.lua:63: attempt to call method 'getDepotItems' (a nil value)
stack traceback:
    [C]: in function 'getDepotItems'
    data/movements/scripts/tiles.lua:63: in function 'getDepotItems'
    data/movements/scripts/tiles.lua:10: in function <data/movements/scripts/tiles.lua:4>

And my tiles.lua is the one from forgottenserver git

Code:
local increasingItemID = {416, 446, 3216, 11062}
local decreasingItemID = {417, 447, 3217, 11063}

function onStepIn(cid, item, position, fromPosition)
    if isInArray(increasingItemID, item.itemid) then
        doTransformItem(item.uid, item.itemid + 1)
        if item.actionid > 1000 then
            getLevelTile(cid, item, position)
        elseif getTilePzInfo(position) then
            getDepotItems(cid, position)
        end
    elseif item.itemid == 426 then
        doTransformItem(item.uid, 425)
        if item.actionid > 1000 then
            getLevelTile(cid, item, position)
        elseif getTilePzInfo(position) then
            getDepotItems(cid, position)
        end
    end
    return true
end

function onStepOut(cid, item, position, fromPosition)
    if isInArray(decreasingItemID, item.itemid) then
        doTransformItem(item.uid, item.itemid - 1)
    elseif item.itemid == 425 then
        doTransformItem(item.uid, item.itemid + 1)
    end
    return true
end

function getLevelTile(cid, item, position)
    local player = Player(cid)
    if player == nil then
        return
    end

    if player:getLevel() < item.actionid - 1000 then
        local playerPosition = player:getPosition()
        doTeleportThing(cid, {x = playerPosition.x, y = playerPosition.y, z = playerPosition.z + 1})
        playerPosition:sendMagicEffect(CONST_ME_MAGIC_BLUE)
    end
end

function getDepotItems(cid, position)
    local player = Player(cid)
    if player == nil then
        return
    end

    local possiblePositions = {
        {x = position.x - 1, y = position.y, z = position.z},
        {x = position.x + 1, y = position.y, z = position.z},
        {x = position.x, y = position.y - 1, z = position.z},
        {x = position.x, y = position.y + 1, z = position.z},
    }

    for i = 1, #possiblePositions do
        local tile = Tile(possiblePositions[i])
        if tile ~= nil then
            local item = tile:getItemByType(ITEM_TYPE_DEPOT)
            if item ~= nil then
                local depotItems = player:getDepotItems(getDepotId(item:getUniqueId()))
                if depotItems == 1 then
                    player:sendTextMessage(MESSAGE_EVENT_DEFAULT, 'Your depot contains 1 item.')
                else
                    player:sendTextMessage(MESSAGE_EVENT_DEFAULT, 'Your depot contains '  .. depotItems .. ' items.')
                end
                break
            end
        end
    end
end
 
replace function getDepotItems and test
Code:
function getDepotItems(cid, position)
    local player = Player(cid)
    if player == nil then
        return
    end
    if position:getTile():hasFlag(TILESTATE_PROTECTIONZONE) then
        local lookPos = player:getPosition()
        lookPos:getNextPosition(player:getDirection())
        local depotItem = lookPos:getTile():getItemByType(ITEM_TYPE_DEPOT)
        if depotItem ~= nil then
            local depotItems = player:getDepotChest(getDepotId(depotItem:getUniqueId()), true):getItemHoldingCount()
            local depotMails = player:getInbox():getItemHoldingCount()
            player:sendTextMessage(MESSAGE_STATUS_DEFAULT, ("Your depot contains %s item%s, and %s news%s."):format(depotItems, (depotItems > 1 and "s" or ""), depotMails, (depotMails > 1 and " or parcels" or "")))
            return true
        end
    end
end
 
Good, now is working, if someone needs the script here it is

Code:
local increasingItemID = {416, 446, 3216, 11062}
local decreasingItemID = {417, 447, 3217, 11063}

function onStepIn(cid, item, position, fromPosition)
    if isInArray(increasingItemID, item.itemid) then
        doTransformItem(item.uid, item.itemid + 1)
        if item.actionid > 1000 then
            getLevelTile(cid, item, position)
        elseif getTilePzInfo(position) then
            getDepotItems(cid, position)
        end
    elseif item.itemid == 426 then
        doTransformItem(item.uid, 425)
        if item.actionid > 1000 then
            getLevelTile(cid, item, position)
        elseif getTilePzInfo(position) then
            getDepotItems(cid, position)
        end
    end
    return true
end

function onStepOut(cid, item, position, fromPosition)
    if isInArray(decreasingItemID, item.itemid) then
        doTransformItem(item.uid, item.itemid - 1)
    elseif item.itemid == 425 then
        doTransformItem(item.uid, item.itemid + 1)
    end
    return true
end

function getLevelTile(cid, item, position)
    local player = Player(cid)
    if player == nil then
        return
    end

    if player:getLevel() < item.actionid - 1000 then
        local playerPosition = player:getPosition()
        doTeleportThing(cid, {x = playerPosition.x, y = playerPosition.y, z = playerPosition.z + 1})
        playerPosition:sendMagicEffect(CONST_ME_MAGIC_BLUE)
    end
end

function getDepotItems(cid, position)
    local player = Player(cid)
    if player == nil then
        return
    end
    if position:getTile():hasFlag(TILESTATE_PROTECTIONZONE) then
        local lookPos = player:getPosition()
        lookPos:getNextPosition(player:getDirection())
        local depotItem = lookPos:getTile():getItemByType(ITEM_TYPE_DEPOT)
        if depotItem ~= nil then
            local depotItems = player:getDepotChest(getDepotId(depotItem:getUniqueId()), true):getItemHoldingCount()
            local depotMails = player:getInbox():getItemHoldingCount()
            player:sendTextMessage(MESSAGE_STATUS_DEFAULT, ("Your depot contains %s item%s, and %s news%s."):format(depotItems, (depotItems > 1 and "s" or ""), depotMails, (depotMails > 1 and " or parcels" or "")))
            return true
        end
    end
end
 

Similar threads

Back
Top