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

[TFS 1.5] Max items per tile

FuturoAspira

New Member
Joined
Dec 14, 2021
Messages
5
Reaction score
1
Location
Brazil
GitHub
luanluciano93
Hello, could someone help me in a way to limit the amount of items in a tile?

I've tried with the onMoveItem event ... but it only checks items that "go to the player" and not the ones that go to the tile.

I've also tried with onItemMoved ... it checks the Tile(toPosition):getDownItemCount(), but it doesn't cancel or send the item with the return false


Lua:
local ec = EventCallback

ec.onItemMoved = function(self, item, count, fromPosition, toPosition, fromCylinder, toCylinder)

    -- No move if item count > 10 items
    local tile = Tile(toPosition)
    if tile and tile:getDownItemCount() > 10 then
        self:sendCancelMessage(RETURNVALUE_NOTPOSSIBLE)
        return false
    end

    return true
end

ec:register()
 
Solution
Here a example, and it is with the onMoveItem event

data/scripts/limits.lua
Lua:
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...
Here a example, and it is with the onMoveItem event

data/scripts/limits.lua
Lua:
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)
 
Solution
Here a example, and it is with the onMoveItem event

data/scripts/limits.lua
Lua:
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)
I use TFS 1.5 NEKIRO
When I install it I get the error:
Lua:
max_tile.lua:7: attempt to index local 'ec' (a nil value)
stack traceback:
        [C]: in function '__newindex'
        ...Pictures\Baiak-Fonticak\data\scripts\custom\max_tile.lua:7: in main chunk
> max_tile.lua [error]
^
 
I use TFS 1.5 NEKIRO
When I install it I get the error:
Lua:
max_tile.lua:7: attempt to index local 'ec' (a nil value)
stack traceback:
        [C]: in function '__newindex'
        ...Pictures\Baiak-Fonticak\data\scripts\custom\max_tile.lua:7: in main chunk
> max_tile.lua [error]
^
If you use the official datapack of TFS Nekiro Downgrade 860 this should work fine.

If you are up to date enough to have the eventcallback system, then make sure of the following:
* What you can try is to check that you are not placing the file outside of the data/scripts/ folder.
 
Here a example, and it is with the onMoveItem event

data/scripts/limits.lua
Lua:
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)
TFS 1.5 7.72 Downgrade Nekiro


Code:
Lua Script Error: [Event Interface]
data/events/scripts/player.lua:Player@onMoveItem
/home/otserv/data/scripts/others/limitTile.lua:8: attempt to call method 'getTile' (a nil value)
stack traceback:
        [C]: in function 'getTile'
        /home/otserv/data/scripts/others/limitTile.lua:8: in function 'callback'
        /home/otserv/data/scripts/lib/event_callbacks.lua:131: in function </home/otserv/data/scripts/lib/event_callbacks.lua:124>
 
Last edited:
TFS 1.5 7.72 Downgrade Nekiro


Code:
Lua Script Error: [Event Interface]
data/events/scripts/player.lua:Player@onMoveItem
/home/otserv/data/scripts/others/limitTile.lua:8: attempt to call method 'getTile' (a nil value)
stack traceback:
        [C]: in function 'getTile'
        /home/otserv/data/scripts/others/limitTile.lua:8: in function 'callback'
        /home/otserv/data/scripts/lib/event_callbacks.lua:131: in function </home/otserv/data/scripts/lib/event_callbacks.lua:124>
change:
Lua:
local tile = toPosition:getTile()
for
Code:
local tile = Tile(toPosition)
 
change:
Lua:
local tile = toPosition:getTile()
for
Code:
local tile = Tile(toPosition)
Working Bro! Thankss

I have a question regarding the message when the limit is reached, instead of the message ""You can not add more items on this tile."". appears, the message "Sorry, not possible".

Is it a scripting problem?


Lua:
local tileLimit = 10
local protectionTileLimit = 10
local houseTileLimit = 10

local ec = EventCallback

function ec.onMoveItem(player, item, count, fromPosition, toPosition, fromCylinder, toCylinder)
    local tile = Tile(toPosition)
    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)
 
Working Bro! Thankss

I have a question regarding the message when the limit is reached, instead of the message ""You can not add more items on this tile."". appears, the message "Sorry, not possible".

Is it a scripting problem?


Lua:
local tileLimit = 10
local protectionTileLimit = 10
local houseTileLimit = 10

local ec = EventCallback

function ec.onMoveItem(player, item, count, fromPosition, toPosition, fromCylinder, toCylinder)
    local tile = Tile(toPosition)
    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)
I don't have an explanation for that, since it is in return false, which is why it launches Sorry, not possible.

Meanwhile
you can use this:
Lua:
addEvent(function()player:sendCancelMessage("You can not add more items on this tile.") end, 100)
 
Não tenho explicação para isso, pois é em retorno false , por isso lança Desculpe, não é possível.

Enquanto isso
você pode usar isso:
Lua:
addEvent(function()player:sendCancelMessage("Você não pode adicionar mais itens neste bloco.") end, 100)
Now both messages appear

Thanks for trying to help me!
 
Back
Top