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

Lua how i can add time in antitrash script

_M4G0_

Well-Known Member
Joined
Feb 6, 2016
Messages
504
Solutions
16
Reaction score
98
this scripts for remove items on ground i need add time for remove in 30 seconds
if is possible msg for player Tfs 1.2
events player>onMoveItem
Lua:
    local cls = Tile(toPosition)
     if cls and not cls:getHouse() then
    if cls:hasFlag(TILESTATE_PROTECTIONZONE) then
    item:remove()
    return false
    end

or in movements
Lua:
local item_exceptions = {} -- exclude items for not clean

function onAddItem(item, tile, pos)
if not isInArray(item_exceptions, item.itemid) then
item:remove()
end
return true
end
 
Last edited:
Solution
Lua:
local item_exceptions = {}
local runningEvents = {}

local function removeItems(position)
    local tile = Tile(position)
    if not tile then
        return
    end
    local items = tile:getItems()
    for i = 1, tile:getItemCount() do
        tile:getThing(i):remove()
    end
    runningEvents[pos.x..pos.y..pos.z] = addEvent(removeItems, 30000, pos)
end

function onAddItem(item, tile, pos)
    if not isInArray(item_exceptions, item.itemid) then
        local index = pos.x..pos.y..pos.z
        if not runningEvents[index] then
            runningEvents[index] = addEvent(removeItems, 30000, pos)
        end
    end
    return true
end
Lua:
local item_exceptions = {}
local runningEvents = {}

local function removeItems(position)
    local tile = Tile(position)
    if not tile then
        return
    end
    local items = tile:getItems()
    for i = 1, tile:getItemCount() do
        tile:getThing(i):remove()
    end
    runningEvents[pos.x..pos.y..pos.z] = addEvent(removeItems, 30000, pos)
end

function onAddItem(item, tile, pos)
    if not isInArray(item_exceptions, item.itemid) then
        local index = pos.x..pos.y..pos.z
        if not runningEvents[index] then
            runningEvents[index] = addEvent(removeItems, 30000, pos)
        end
    end
    return true
end
 
Last edited:
Solution
Lua:
local item_exceptions = {}
local runningEvents = {}

local function removeItems(position)
    local tile = Tile(position)
    if not tile then
        return
    end
    local items = tile:getItems()
    for i = 1, tile:getItemCount() do
        tile:getThing(i):remove()
    end
    runningEvents[pos.x..pos.y..pos.z] = addEvent(removeItems, 30000, pos)
end

function onAddItem(item, tile, pos)
    if not isInArray(item_exceptions, item.itemid) then
        local index = pos.x..pos.y..pos.z
        if not runningEvents[index] then
            runningEvents[index] = addEvent(removeItems, 30000, pos)
        end
    end
    return true
end
what add msg pra o player?
 
the script work but have this error
Code:
Lua Script Error: [Main Interface]
in a timer event called from:
(Unknown scriptfile)
data/movements/scripts/trash_prevent3.lua:13: attempt to index global 'pos' (a n
il value)
stack traceback:
        [C]: in function '__index'
        data/movements/scripts/trash_prevent3.lua:13: in function <data/movement
s/scripts/trash_prevent3.lua:4>
 
Try this:
Lua:
local item_exceptions = {}
local runningEvents = {}
local function removeItems(pos)
    local tile = Tile(pos)
    if not tile then
        return
    end
    local items = tile:getItems()
    for i = 1, #items do
        if ItemType(items[i]):isMovable() then
            items[i]:remove()
        end
    end
    runningEvents[pos.x..pos.y..pos.z] = addEvent(removeItems, 30000, pos)
end
function onAddItem(item, tile, pos)
    if not isInArray(item_exceptions, item.itemid) then
        local index = pos.x..pos.y..pos.z
        if not runningEvents[index] then
            runningEvents[index] = addEvent(removeItems, 30000, pos)
        end
    end
    return true
end
The original script would remove counters/walls/creatures from that specific tile and would leave some items out(in case creature got removed). Not sure if checking if the item type is movable is enough to prevent griefing. Can't think of any possible movable items you wouldn't want to get deleted though.
 
the script work but have this error
Code:
Lua Script Error: [Main Interface]
in a timer event called from:
(Unknown scriptfile)
data/movements/scripts/trash_prevent3.lua:13: attempt to index global 'pos' (a n
il value)
stack traceback:
        [C]: in function '__index'
        data/movements/scripts/trash_prevent3.lua:13: in function <data/movement
s/scripts/trash_prevent3.lua:4>
i have the error tbm
 
Back
Top