• 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.X+ Any function to check if item is thrown?

Mjmackan

Mapper ~ Writer
Premium User
Joined
Jul 18, 2009
Messages
1,424
Solutions
15
Reaction score
176
Location
Sweden
Waddap! Using TFS 1.3
Im creating a script which cleans a specific area, however it will also clean decorations etc, I dont want that.
I want it to remove items that players has throwed out. Is there any way to check if it has been throwed out, one idea i had was to add a hidden mark to every item a player moves, but it seems kinda too much just to clean a specific area. Is there any function or stuff you could check if its placed out by me in map editor or is a item a player throwed out?
 
Maybe add specific aid like "100" for decos/furniture and exclude items with this aid from removing.
It can also help to prevent people stealing/moving or destroying items like chairs and tables.
 
Waddap! Using TFS 1.3
Im creating a script which cleans a specific area, however it will also clean decorations etc, I dont want that.
I want it to remove items that players has throwed out. Is there any way to check if it has been throwed out, one idea i had was to add a hidden mark to every item a player moves, but it seems kinda too much just to clean a specific area. Is there any function or stuff you could check if its placed out by me in map editor or is a item a player throwed out?
Depends how you want to use it, there are plenty ways to achieve that, here's most common room cleaner function:

Lua:
local ROOMS = {
    [1] = {
        fromPos = {x = 1, y = 1, z = 7}, -- topLeft corner
        toPos = {x = 10, y = 10, z = 7}, -- bottomRight corner
    },
    [2] = {
        fromPos = {x = 1, y = 1, z = 7}, -- topLeft corner
        toPos = {x = 10, y = 10, z = 7}, -- bottomRight corner
    },
    -- add next areas analogically, (...)
}

--[[
You need to insert itemId of items which you want to be NOT removed, if you hate inserting IDs manually you can
do it in different way, for example set actionId in Map Editor and re-make this script or any custom item flag in items.xml
idk details so I done it in that way..
]]
local skipItemsIds = {1337, 7331, 2323, 2323}

function cleanRoom(roomId)
    if not ROOMS[roomId] then return end

    -- Loop through all tiles X , Y, Z
    for x = ROOMS[roomId].fromPos.x, ROOMS[roomId].toPos.x do
        for y = ROOMS[roomId].fromPos.y, ROOMS[roomId].toPos.y do
            for z = ROOMS[roomId].fromPos.z, ROOMS[roomId].toPos.z do
                local tile = Tile({x=x, y=y, z=z})
                if tile then
                    local movableItem = tile:getThing(255)
                    if movableItem and movableItem:isItem() then
                        -- if item found on tile, get its id from itemType
                        local itemType = ItemType(movableItem:getId())
                        -- remove only items that are movable and are NOT in array `skipItemsIds`
                        if itemType and itemType:isMovable() and not isInArray(skipItemsIds, movableItem:getId()) then
                            moveableItem:remove()
                        end

                        -- Remove creatures if are in room
                        local creature = tile:getTopCreature()
                        if creature and creature:isMonster() then
                            creature:remove()
                        end
                    end
                end
            end
        end
    end

    -- Usage : cleanRoom(1) where you want to use it -- ID is from table at beginning of script, don't forget to change X,Y,Z and read something :P
    return true
end

If you want to remove only throwed items by players, I suggest an cheap trick to make an script in movements in onItemMove callback where u will check if item was moved by player from his inventory, and when it's dropped on ground in certain room (fromPos, toPos) set it's actionId to any value and reference to it when you cleaning room or something.

There are plenty ways to do that, depends on your needs and imagination..
 
Last edited:
Maybe add specific aid like "100" for decos/furniture and exclude items with this aid from removing.
It can also help to prevent people stealing/moving or destroying items like chairs and tables.
So I've done, but then there's statues, depots etc.

I'd make the decorations not pickupable in .dat and just clean the pickupable ones.
That kinda makes it rough if I'd want several places to clean in the future and/or maybe want to keep some furnitures moveable for houses etc.

Depends how you want to use it, there are plenty ways to achieve that, here's most common room cleaner function:

Lua:
local ROOMS = {
    [1] = {
        fromPos = {x = 1, y = 1, z = 7}, -- topLeft corner
        toPos = {x = 10, y = 10, z = 7}, -- bottomRight corner
    },
    [2] = {
        fromPos = {x = 1, y = 1, z = 7}, -- topLeft corner
        toPos = {x = 10, y = 10, z = 7}, -- bottomRight corner
    },
    -- add next areas analogically, (...)
}

--[[
You need to insert itemId of items which you want to be NOT removed, if you hate inserting IDs manually you can
do it in different way, for example set actionId in Map Editor and re-make this script or any custom item flag in items.xml
idk details so I done it in that way..
]]
local skipItemsIds = {1337, 7331, 2323, 2323}

function cleanRoom(roomId)
    if not ROOMS[roomId] then return end

    -- Loop through all tiles X , Y, Z
    for x = ROOMS[roomId].fromPos.x, ROOMS[roomId].toPos.x do
        for y = ROOMS[roomId].fromPos.y, ROOMS[roomId].toPos.y do
            for z = ROOMS[roomId].fromPos.z, ROOMS[roomId].toPos.z do
                local tile = Tile({x=x, y=y, z=z})
                if tile then
                    local movableItem = tile:getThing(255)
                    if movableItem and movableItem:isItem() then
                        -- if item found on tile, get its id from itemType
                        local itemType = ItemType(movableItem:getId())
                        -- remove only items that are movable and are NOT in array `skipItemsIds`
                        if itemType and itemType:isMovable() and not isInArray(skipItemsIds, movableItem:getId()) then
                            moveableItem:remove()
                        end

                        -- Remove creatures if are in room
                        local creature = tile:getTopCreature()
                        if creature and creature:isMonster() then
                            creature:remove()
                        end
                    end
                end
            end
        end
    end

    -- Usage : cleanRoom(1) where you want to use it -- ID is from table at beginning of script, don't forget to change X,Y,Z and read something :P
    return true
end

If you want to remove only throwed items by players, I suggest an cheap trick to make an script in movements in onItemMove callback where u will check if item was moved by player from his inventory, and when it's dropped on ground in certain room (fromPos, toPos) set it's actionId to any value and reference to it when you cleaning room or something.

There are plenty ways to do that, depends on your needs and imagination..
I was thinking of using aid, but then I figured I'd rather use setCustomAttribute as it will 100% not interfere with anything ever.

data/events/scripts/player.lua
function:
Lua:
function Player:onMoveItem
Yeah Its not that I dont know where to put stuff. 🤔
 
Back
Top