• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

Mass removing ground tiles or replacing them?

Nekiro

Legendary OT User
TFS Developer
Joined
Sep 7, 2015
Messages
2,758
Solutions
127
Reaction score
2,277
Is this possible? To mass remove ground tiles or replace them into any other id?

For example we have room with radius 20x20 from center pos x = 3445, y =3334, z= 7.
And I want to remove or replace all tiles within 20x20 radius from center position. Is possible to do that?

I tried :Game.LoadMap, but it isnt really replacing the map. It is overlaying it...

I managed to do that, but it required all positions to be defined it is too much work...

Thank you for any help!
 
Code:
function replaceTiles(fromPos, toPos, toId)
    local minX, maxX, minY, maxY, minZ, maxZ = math.min(fromPos.x, toPos.x), math.max(fromPos.x,toPos.x), math.min(fromPos.y, toPos.y), math.max(fromPos.y,toPos.y), math.min(fromPos.z, toPos.z), math.max(fromPos.z,toPos.z)
    for z = minZ, maxZ do
        for x = minX, maxX do
            for y = minY, maxY do
                local ground = Tile(x,y,z):getGround()
                if ground then
                    ground:transform(toId)
                end
            end
        end
    end
    return true
end
fromPos, toPos any positions, toId id you want to change all ground to
 
Code:
function replaceTiles(fromPos, toPos, toId)
    local minX, maxX, minY, maxY, minZ, maxZ = math.min(fromPos.x, toPos.x), math.max(fromPos.x,toPos.x), math.min(fromPos.y, toPos.y), math.max(fromPos.y,toPos.y), math.min(fromPos.z, toPos.z), math.max(fromPos.z,toPos.z)
    for z = minZ, maxZ do
        for x = minX, maxX do
            for y = minY, maxY do
                local ground = Tile(x,y,z):getGround()
                if ground then
                    ground:transform(toId)
                end
            end
        end
    end
    return true
end
fromPos, toPos any positions, toId id you want to change all ground to
Wow great work mate.
But it doesnt removing borders ;X
 
where to put it? im looking it to delete or replace some or all border ground from 7.6 to 7.4 graphics help and thanks :B
 
if you want to remove borders, just make the area 1 tile bigger in each direction

if you want to replace borders, you have to loop through
most north row, most east row, most west row, most south row, and all corners, and add an extra argument to the function like , borders) and use it as {north = id, south = id, east = id, west = id, corners = {id,id,id,id}}
 
if you want to remove borders, just make the area 1 tile bigger in each direction

if you want to replace borders, you have to loop through
most north row, most east row, most west row, most south row, and all corners, and add an extra argument to the function like , borders) and use it as {north = id, south = id, east = id, west = id, corners = {id,id,id,id}}

Well, what if borders are inside this area?
 
How to check ids like this:
Code:
local borders = {7067, 7068, 7069, 7070, 7071, 7072, 7073, 7074, 7075, 7076, 7077, 7078, 7079, 7080, 7081, 7082, 7083, 7084, 7085, 7086, 7087, 7088, 7089, 7090}
local border = Tile(x,y,z):getItemById(borders)
?
 
Code:
function replaceTiles(fromPos, toPos, idMap)
    local minX, maxX, minY, maxY, minZ, maxZ = math.min(fromPos.x, toPos.x), math.max(fromPos.x,toPos.x), math.min(fromPos.y, toPos.y), math.max(fromPos.y,toPos.y), math.min(fromPos.z, toPos.z), math.max(fromPos.z,toPos.z)
    for z = minZ, maxZ do
        for x = minX, maxX do
            for y = minY, maxY do
                local ground = Tile(Position(x,y,z)):getGround()
                local tmp = idMap[ground:getId()]
                if ground and tmp then
                    ground:transform(tmp)
                end
            end
        end
    end
    return true
end
use this, use idMap arguments as a table like
Code:
local ids = {
[groundId1] = toId,
[borderId] = toId,
}
etc
 
Code:
local borders = {7067, 7068, 7069, 7070, 7071, 7072, 7073, 7074, 7075, 7076, 7077, 7078, 7079, 7080, 7081, 7082, 7083, 7084, 7085, 7086, 7087, 7088, 7089, 7090}
function replaceTiles(fromPos, toPos, toId)
    local minX, maxX, minY, maxY, minZ, maxZ = math.min(fromPos.x, toPos.x), math.max(fromPos.x,toPos.x), math.min(fromPos.y, toPos.y), math.max(fromPos.y,toPos.y), math.min(fromPos.z, toPos.z), math.max(fromPos.z,toPos.z)
    for z = minZ, maxZ do
        for x = minX, maxX do
            for y = minY, maxY do
                local ground = Tile(x,y,z):getGround()
                for i, #borders do
                    local border = Tile(x,y,z):getItemById(i)
                    if border then
                        border:remove()
                    end
                end
                if ground then
                    ground:transform(toId)
                end
            end
        end
    end
    return true
end
not tested.
 
Code:
function replaceTiles(fromPos, toPos, idMap)
    local minX, maxX, minY, maxY, minZ, maxZ = math.min(fromPos.x, toPos.x), math.max(fromPos.x,toPos.x), math.min(fromPos.y, toPos.y), math.max(fromPos.y,toPos.y), math.min(fromPos.z, toPos.z), math.max(fromPos.z,toPos.z)
    for z = minZ, maxZ do
        for x = minX, maxX do
            for y = minY, maxY do
                local ground = Tile(Position(x,y,z))
                if ground and type(idMap) == 'table' then
                    local item1, item2 = ground:getThing(1), ground:getGround()
                    local remid, tid = item1 and item1:getId(), item2:getId()
                    local rem, toid = idMap[remid], idMap[tid]
                    if rem and rem == 0 then
                        item1:remove()
                    elseif rem and not(rem == 0) then
                        item1:transform(rem)
                    elseif toid and toid == 0 then
                        item2:remove()
                    elseif toid and not(toid == 0) then
                        item2:transform(toid)
                    end
                end
            end
        end
    end
    return true
end

idMap example:
Code:
    local ids = {
        [18002] = 11953,
        [5572]  = 0,
        [5573]  = 0,
        [5574]  = 0,
        [5575]  = 0,
        [5576]  = 0,
        [5577]  = 0,
    }
    replaceTiles(Position(1001, 1000, 7), Position(1006, 1005, 7), ids)
you can remove or replace the tiles/borders instead of only replacing them
edited: optimized it more and removed loop
 
Last edited:

Similar threads

Back
Top