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

MAx item per tile tfs 1.5

jareczekjsp

Member
Joined
Jan 30, 2023
Messages
188
Reaction score
9
GitHub
Jarek123
Hello guys I try make max items per tile and I have error

Lua:
Lua Script Error: [Event Interface]
data/events/scripts/player.lua:Player@onMoveItem
/home/ots/data/scripts/maxtile.lua:8: attempt to call method 'getTile' (a nil value)
stack traceback:
        [C]: in function 'getTile'
        /home/ots/data/scripts/maxtile.lua:8: in function 'callback'
        /home/ots/data/scripts/lib/event_callbacks.lua:131: in function </home/ots/data/scripts/lib/event_callbacks.lua:124>


Script
Code:
local tileLimit = 0
local protectionTileLimit = 0
local houseTileLimit = 0

local ec = EventCallback

function ec.onMoveItem(player, item, count, fromPosition, toPosition, fromCylinder, toCylinder)
    local tile = toPosition:getTile()
    if tile then
        local itemLimit = tile:getHouse() and houseTileLimit or tile:hasFlag(TILESTATE_PROTECTIONZONE) and protectionTileLimit or tileLimit
        if itemLimit > 0 and tile:getThingCount() > itemLimit and item:getType():getType() ~= ITEM_TYPE_MAGICFIELD then
            player:sendCancelMessage("You can not add more items on this tile.")
            return false
        end
    end
    return true
end

ec:register(-1)
 
The getTile() method only works for item or creature classes. There isn't a method to extract a tile from a position.
Might be also confusing it with Tile():getPosition(), but cant do the other way around :p

So as the above said, just need to use the Tile constructor instead.
 
Back
Top