• 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+ Remove items frompos topos

Caduceus

Unknown Member
Joined
May 10, 2010
Messages
321
Solutions
2
Reaction score
24
I am looking for a way to remove the items frompos - toPos of the 'area' before the next match of checkers can began.

Code:
local config = {
    items = {2624, 2625, 2631,2637},
    centerCheckerBoardPosition = Position(1028, 1078, 15),
    playerPositions = {
        --Position(1027, 1071, 15),
        Position(1029, 1071, 15)
    },
    newPositions = {
        --Position(1027, 1079, 15),
        Position(1028, 1079, 15)
    },
   
    area = {
    frompos = {x = 1020, y = 1070, z = 15},
    topos = {x = 1033, y = 1086, z = 15}
    },
   
    whitePos = {
            Position(1024, 1080, 15),
            Position(1026, 1080, 15),
            Position(1028, 1080, 15),
            Position(1030, 1080, 15),
            Position(1025, 1081, 15),
            Position(1027, 1081, 15),
            Position(1029, 1081, 15),
            Position(1031, 1081, 15),
            Position(1024, 1081, 15),
            Position(1024, 1082, 15),
            Position(1026, 1082, 15),
            Position(1028, 1082, 15),
            Position(1030, 1082, 15)
    },
       
    blackPos = {
           
            Position(1025, 1075, 15),
            Position(1027, 1075, 15),
            Position(1029, 1075, 15),
            Position(1031, 1075, 15),
            Position(1024, 1076, 15),
            Position(1026, 1076, 15),
            Position(1028, 1076, 15),
            Position(1030, 1076, 15),
            Position(1025, 1077, 15),
            Position(1027, 1077, 15),
            Position(1029, 1077, 15),
            Position(1031, 1077, 15)
    },
       
    whiteKingPos = {
            Position(1025, 1072, 15),
            Position(1026, 1072, 15),
            Position(1027, 1072, 15),
            Position(1028, 1072, 15),
            Position(1029, 1072, 15),
            Position(1030, 1072, 15),
            Position(1025, 1073, 15),
            Position(1026, 1073, 15),
            Position(1027, 1073, 15),
            Position(1028, 1073, 15),
            Position(1029, 1073, 15),
            Position(1030, 1073, 15)
        },
       
    blackKingPos = {
            Position(1025, 1084, 15),
            Position(1026, 1084, 15),
            Position(1027, 1084, 15),
            Position(1028, 1084, 15),
            Position(1029, 1084, 15),
            Position(1030, 1084, 15),
            Position(1025, 1085, 15),
            Position(1026, 1085, 15),
            Position(1027, 1085, 15),
            Position(1028, 1085, 15),
            Position(1029, 1085, 15),
            Position(1030, 1085, 15)
        }
    }

function onUse(player, item, fromPosition, target, toPosition, isHotkey)

    if item.itemid == 1945 then
        local storePlayers, playerTile = {}

        for i = 1, #config.playerPositions do
            playerTile = Tile(config.playerPositions[i]):getTopCreature()
           
            if not playerTile or not playerTile:isPlayer() then
                player:sendTextMessage(MESSAGE_STATUS_SMALL, "You need 2 players.")
                return true
            end

            storePlayers[#storePlayers + 1] = playerTile
        end

        --Game.getSpectators(position[, multifloor = false[, onlyPlayer = false[, minRangeX = 0[, maxRangeX = 0[, minRangeY = 0[, maxRangeY = 0]]]]]])
        local specs, spec = Game.getSpectators(config.centerCheckerBoardPosition, false, true, 6, 6, 6, 6)
        for i = 1, #specs do
            spec = specs[i]
            if spec:isPlayer() then
                player:sendTextMessage(MESSAGE_STATUS_SMALL, "A match is already in progress. Please try again later.")
                return true
            end

            spec:remove()
        end

        for i = 1, #config.whitePos do
            Game.createItem(2625, 1, config.whitePos[i])
        end
       
        for i = 1, #config.blackPos do
            Game.createItem(2624, 1, config.blackPos[i])
        end
       
        for i = 1, #config.whiteKingPos do
            Game.createItem(2631, 1, config.whiteKingPos[i])
        end
       
        for i = 1, #config.blackKingPos do
            Game.createItem(2637, 1, config.blackKingPos[i])
        end

        local players
        for i = 1, #storePlayers do
            players = storePlayers[i]
            config.playerPositions[i]:sendMagicEffect(CONST_ME_POFF)
            players:teleportTo(config.newPositions[i])
            config.newPositions[i]:sendMagicEffect(CONST_ME_POFF)
            players:setDirection(DIRECTION_WEST)
        end
       
    elseif item.itemid == 1946 then
    local x = config.area.frompos.x
    local y = config.area.frompos.y
    local z = 15

    while x ~= config.area.topos.x do
        while y ~= config.area.topos.y do
            if x == config.area.topos.x then
                x = config.area.frompos.x
                y = y + 1
            end
           
            local pos = {x = x, y = y, z = z}
            local tile = Tile(pos)
            local item = Tile(pos):getItemById(config.items)
           
            if tile then
                for item in ipairs(tile:getItems()) do
                --if isInArray({config.items}, item:getId()) then
                    item:remove()
                --end
            end
        end
           
            x = x + 1
        end
    end
end

    item:transform(item.itemid == 1946 and 1945 or 1946)
    return true
end
 
Last edited:
Solution
  1. Lua:
    local config = {
        items = {2624, 2625, 2631,2637},
        centerCheckerBoardPosition = Position(1028, 1078, 15),
        playerPositions = {
            --Position(1027, 1071, 15),
            Position(1029, 1071, 15)
        },
        newPositions = {
            --Position(1027, 1079, 15),
            Position(1028, 1079, 15)
        },
        area = {
        frompos = {x = 1020, y = 1070, z = 15},
        topos = {x = 1033, y = 1086, z = 15}
        },
        whitePos = {
                Position(1024, 1080, 15),
                Position(1026, 1080, 15),
                Position(1028, 1080, 15),
                Position(1030, 1080, 15),
                Position(1025, 1081, 15),
                Position(1027, 1081, 15),
                Position(1029, 1081, 15),
                Position(1031, 1081, 15)...
Lua:
local tile = Tile(some position)

for item in ipairs(tile:getItems()) do
    -- check some shit for each item on tile
end
 
Sorry, I should have been more specific. I want to clear the entire area, not just a single tile.

Code:
area = {
    frompos = {x = 1020, y = 1070, z = 15}, top left map
    topos = {x = 1033, y = 1086, z = 15} bottom right map
    },

something along these lines?

Code:
elseif item.itemid == 1945 then
        for a = config.area.frompos.x, config.area.topos.x do
        for b = config.area.frompos.y, config.arena.topos.y do
        pos = {x=a,y=b,z=15,stackpos = 255}
            if(isItem(getThingFromPos(pos).uid)) then
       item:remove()
        end
    end
 
Last edited:
Lua:
local x = area.frompos.x
local y = area.frompos.y
local z = 15

while x ~= area.topos.x do
    while y ~= area.topos.y do
        if x == area.topos.x then
            x = area.frompos.x
            y = y + 1
        end
       
        local pos = {x = x, y = y, z = z}
        local tile = Tile(pos)
       
        if tile then
            for item in ipairs(tile:getItems()) do
                item:remove()
            end
        end
       
        x = x + 1
    end
end
 
I keep getting this error with script posted on on original post. item:remove()

Code:
Lua Script Error: [Action Interface]
data/actions/scripts/custom/checkers.lua:onUse
data/actions/scripts/custom/checkers.lua:153: attempt to index local 'item' (a number value)
stack traceback:
        [C]: in function '__index'
        data/actions/scripts/custom/checkers.lua:153: in function <data/actions/
scripts/custom/checkers.lua:81>
 
Atm you give item the reference of the table key and not the table value. Thats what the error says.
Code:
for _,item in pairs ....
will give you the right reference
 
for _,item in pairs ....

I have also tried "for _, item in pairs(tile:getItems()) do" and it crashes the server.

Code:
Lua Script Error: [Action Interface]
data/actions/scripts/custom/checkers.lua:onUse
data/actions/scripts/custom/checkers.lua:152: bad argument #1 to 'ipairs' (table expected, got number)
stack traceback:
        [C]: at 0x013f67abd0
        [C]: in function 'ipairs'
        data/actions/scripts/custom/checkers.lua:152: in function <data/actions/
scripts/custom/checkers.lua:81>


Code:
 elseif item.itemid == 1946 then
    local x = config.area.frompos.x
    local y = config.area.frompos.y
    local z = 15
    while x ~= config.area.topos.x do
        while y ~= config.area.topos.y do
            if x == config.area.topos.x then
                x = config.area.frompos.x
                y = y + 1
            end
     
            local pos = {x = x, y = y, z = z}
            local tile = Tile(pos)
            local item = Tile(pos):getItemById(config.items)
     
            if tile then
            for i = 1, #config.items do
               for i, item in ipairs(config.items[i]) do
                    item:remove(getTileThingByPos(pos).uid)
                end
            end
        end
     
            x = x + 1
        end
    end
end
 
Last edited:
Lua:
    iterateArea(function(position)
        local tile = Tile(position)
        if not tile then
            return
        end
        local items = tile:getItems()
        if items then
            for i = 1, #items do
                local item = items[i]
                item:remove()
            end
        end
    end, Position(fromPos.x, fromPos.y, fromPos. z), Position(toPosition.x, toPosition.y, toPosition.z))
 
Code:
Lua Script Error: [Action Interface]
data/actions/scripts/custom/checkers.lua:onUse
data/actions/scripts//checkers.lua:139: attempt to call global 'iterateArea' (a nil value)
stack traceback:
        [C]: in function 'iterateArea'
        data/actions/scripts//checkers.lua:139: in function <data/actions/
scripts/custom/checkers.lua:83>


Code:
local config = {
    tokens = {2624, 2625, 2631,2637},
   
    centerCheckerBoardPosition = Position(1028, 1078, 15),
   
    playerPositions = {
            --Position(1027, 1071, 15),
            Position(1029, 1071, 15)
    },
    newPositions = {
            --Position(1027, 1079, 15),
            Position(1028, 1079, 15)
    },
   
    area = {
            fromPos = {x = 1020, y = 1070, z = 15},
            toPos = {x = 1033, y = 1086, z = 15}
    },
   
    whitePos = {
            Position(1024, 1080, 15),
            Position(1026, 1080, 15),
            Position(1028, 1080, 15),
            Position(1030, 1080, 15),
            Position(1025, 1081, 15),
            Position(1027, 1081, 15),
            Position(1029, 1081, 15),
            Position(1031, 1081, 15),
            Position(1024, 1081, 15),
            Position(1024, 1082, 15),
            Position(1026, 1082, 15),
            Position(1028, 1082, 15),
            Position(1030, 1082, 15)
    },
       
    blackPos = {
           
            Position(1025, 1075, 15),
            Position(1027, 1075, 15),
            Position(1029, 1075, 15),
            Position(1031, 1075, 15),
            Position(1024, 1076, 15),
            Position(1026, 1076, 15),
            Position(1028, 1076, 15),
            Position(1030, 1076, 15),
            Position(1025, 1077, 15),
            Position(1027, 1077, 15),
            Position(1029, 1077, 15),
            Position(1031, 1077, 15)
    },
       
    whiteKingPos = {
            Position(1025, 1072, 15),
            Position(1026, 1072, 15),
            Position(1027, 1072, 15),
            Position(1028, 1072, 15),
            Position(1029, 1072, 15),
            Position(1030, 1072, 15),
            Position(1025, 1073, 15),
            Position(1026, 1073, 15),
            Position(1027, 1073, 15),
            Position(1028, 1073, 15),
            Position(1029, 1073, 15),
            Position(1030, 1073, 15)
        },
       
    blackKingPos = {
            Position(1025, 1084, 15),
            Position(1026, 1084, 15),
            Position(1027, 1084, 15),
            Position(1028, 1084, 15),
            Position(1029, 1084, 15),
            Position(1030, 1084, 15),
            Position(1025, 1085, 15),
            Position(1026, 1085, 15),
            Position(1027, 1085, 15),
            Position(1028, 1085, 15),
            Position(1029, 1085, 15),
            Position(1030, 1085, 15)
        }
    }

function onUse(player, item, fromPosition, target, toPosition, isHotkey)

    if item.itemid == 1945 then
        local storePlayers, playerTile = {}

        for i = 1, #config.playerPositions do
            playerTile = Tile(config.playerPositions[i]):getTopCreature()
           
            if not playerTile or not playerTile:isPlayer() then
                player:sendTextMessage(MESSAGE_STATUS_SMALL, "You need 2 players.")
                return true
            end

            storePlayers[#storePlayers + 1] = playerTile
        end

        --Game.getSpectators(position[, multifloor = false[, onlyPlayer = false[, minRangeX = 0[, maxRangeX = 0[, minRangeY = 0[, maxRangeY = 0]]]]]])
        local specs, spec = Game.getSpectators(config.centerCheckerBoardPosition, false, true, 6, 6, 6, 6)
        for i = 1, #specs do
            spec = specs[i]
            if spec:isPlayer() then
                player:sendTextMessage(MESSAGE_STATUS_SMALL, "A match is already in progress. Please try again later.")
                return true
            end

            spec:remove()
        end

        for i = 1, #config.whitePos do
            Game.createItem(2625, 1, config.whitePos[i])
        end
       
        for i = 1, #config.blackPos do
            Game.createItem(2624, 1, config.blackPos[i])
        end
       
        for i = 1, #config.whiteKingPos do
            Game.createItem(2631, 1, config.whiteKingPos[i])
        end
       
        for i = 1, #config.blackKingPos do
            Game.createItem(2637, 1, config.blackKingPos[i])
        end

        local players
        for i = 1, #storePlayers do
            players = storePlayers[i]
            config.playerPositions[i]:sendMagicEffect(CONST_ME_POFF)
            players:teleportTo(config.newPositions[i])
            config.newPositions[i]:sendMagicEffect(CONST_ME_POFF)
            players:setDirection(DIRECTION_WEST)
            item:transform(1946)
        end
       
    elseif item.itemid == 1946 then
             
    iterateArea(function(position)
        local tile = Tile(position)
        if not tile then
            return
        end
        local items = tile:getItems(config.tokens)
        if items then
            for i = 1, #items do
                local item = items[i]
                item:remove()
            end
        end
    end, Position(config.area.fromPos.x, config.area.fromPos.y, config.area.fromPos.z), Position(config.area.toPos.x, config.area.toPos.y, config.area.toPos.z))

    item:transform(item.itemid == 1946 and 1945 or 1946)
    return true
    end
end
 
Last edited:
Add this function in lib/miscellaneous/functions.lua

Lua:
function iterateArea(func, from, to)
    for z = from.z, to.z do
        for y = from.y, to.y do
            for x = from.x, to.x do
                func(Position(x, y, z))
            end
        end
    end
end
 
that helped, but how do I remove just tokens. That ripped all the items that were not tiles off map.
 
  1. Lua:
    local config = {
        items = {2624, 2625, 2631,2637},
        centerCheckerBoardPosition = Position(1028, 1078, 15),
        playerPositions = {
            --Position(1027, 1071, 15),
            Position(1029, 1071, 15)
        },
        newPositions = {
            --Position(1027, 1079, 15),
            Position(1028, 1079, 15)
        },
        area = {
        frompos = {x = 1020, y = 1070, z = 15},
        topos = {x = 1033, y = 1086, z = 15}
        },
        whitePos = {
                Position(1024, 1080, 15),
                Position(1026, 1080, 15),
                Position(1028, 1080, 15),
                Position(1030, 1080, 15),
                Position(1025, 1081, 15),
                Position(1027, 1081, 15),
                Position(1029, 1081, 15),
                Position(1031, 1081, 15),
                Position(1024, 1081, 15),
                Position(1024, 1082, 15),
                Position(1026, 1082, 15),
                Position(1028, 1082, 15),
                Position(1030, 1082, 15)
        },
        blackPos = {
      
                Position(1025, 1075, 15),
                Position(1027, 1075, 15),
                Position(1029, 1075, 15),
                Position(1031, 1075, 15),
                Position(1024, 1076, 15),
                Position(1026, 1076, 15),
                Position(1028, 1076, 15),
                Position(1030, 1076, 15),
                Position(1025, 1077, 15),
                Position(1027, 1077, 15),
                Position(1029, 1077, 15),
                Position(1031, 1077, 15)
        },
        whiteKingPos = {
                Position(1025, 1072, 15),
                Position(1026, 1072, 15),
                Position(1027, 1072, 15),
                Position(1028, 1072, 15),
                Position(1029, 1072, 15),
                Position(1030, 1072, 15),
                Position(1025, 1073, 15),
                Position(1026, 1073, 15),
                Position(1027, 1073, 15),
                Position(1028, 1073, 15),
                Position(1029, 1073, 15),
                Position(1030, 1073, 15)
            },
        blackKingPos = {
                Position(1025, 1084, 15),
                Position(1026, 1084, 15),
                Position(1027, 1084, 15),
                Position(1028, 1084, 15),
                Position(1029, 1084, 15),
                Position(1030, 1084, 15),
                Position(1025, 1085, 15),
                Position(1026, 1085, 15),
                Position(1027, 1085, 15),
                Position(1028, 1085, 15),
                Position(1029, 1085, 15),
                Position(1030, 1085, 15)
            }
        }
    function clearRoom()
        iterateArea(function(position)
            local tile = Tile(position)
            if not tile then
                return
            end
            local items = tile:getItems()
            if items then
                for i = 1, #items do
                    local item = items[i]
                    if isInArray(config.items, item:getId()) then
                    item:remove()
                    end
                end
            end
        end,
            Position(1020, 1070, 15),
            Position(1033, 1086, 15))
        end
    function onUse(player, item, fromPosition, target, toPosition, isHotkey)
        if item.itemid == 1945 then
            local storePlayers, playerTile = {}
            for i = 1, #config.playerPositions do
                playerTile = Tile(config.playerPositions[i]):getTopCreature()
      
                if not playerTile or not playerTile:isPlayer() then
                    player:sendTextMessage(MESSAGE_STATUS_SMALL, "You need 2 players.")
                    return true
                end
                storePlayers[#storePlayers + 1] = playerTile
            end
            local specs, spec = Game.getSpectators(config.centerCheckerBoardPosition, false, true, 6, 6, 6, 6)
            for i = 1, #specs do
                spec = specs[i]
                if spec:isPlayer() then
                    player:sendTextMessage(MESSAGE_STATUS_SMALL, "A match is already in progress. Please try again later.")
                    return true
                end
                spec:remove()
            end
          
            clearRoom()
            for i = 1, #config.whitePos do
                Game.createItem(2625, 1, config.whitePos[i])
            end
            for i = 1, #config.blackPos do
                Game.createItem(2624, 1, config.blackPos[i])
            end
            for i = 1, #config.whiteKingPos do
                Game.createItem(2631, 1, config.whiteKingPos[i])
            end
            for i = 1, #config.blackKingPos do
                Game.createItem(2637, 1, config.blackKingPos[i])
            end
            local players
            for i = 1, #storePlayers do
                players = storePlayers[i]
                config.playerPositions[i]:sendMagicEffect(CONST_ME_POFF)
                players:teleportTo(config.newPositions[i])
                config.newPositions[i]:sendMagicEffect(CONST_ME_POFF)
                players:setDirection(DIRECTION_WEST)
            end
        elseif item.itemid == 1946 then
            return true
        end
    end
 
Last edited:
Solution
Back
Top