• 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 Advanced script help

d4rkbl0od

Member
Joined
Mar 21, 2008
Messages
160
Reaction score
7
Hello,

I'm trying to make a script that changes the borders and ground from an area, the idea is to check the border id, and change for the border I want.

It should check in an area (fromPos - toPos)

For example:
Borders to check
6695 -> transform to -> xxx
6696 -> transform to -> yyy
6697 -> transform to -> zzz
6698 -> transform to -> www
and so on.

I know it should be a loop, with "for", but I can't make it to check the borderid and change for the respective one.

EDIT:
I've started something.. But I wanted to make an array like script, not border by border make a "IF"

Code:
local fromPos = {x=33433, y=31523, z=11}
local toPos = {x=33448, y=31554, z=11}

local config = {

[11775] = 6695,
[11776] = 6698,
[11777] = 6697,
[11778] = 6696,
[11785] = 6699,
[11786] = 6700,
[11787] = 6702,
[11788] = 6701,
[11789] = 6703,
[11790] = 6704,
[11791] = 6706,
[11792] = 6705

}

    for x = fromPos.x, toPos.x do
        for y = fromPos.y, toPos.y do
            for z = fromPos.z, toPos.z do
                local border1 = Tile(Position(x,y,z)):getItemById(11777)
                if  border1 then
                    border1:transform(6697)
                end
            end
        end
    end
 
Last edited:
Solution
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...
Why do you need that? If you're going to use this to change borders on startup in a big area you should do it in C++
 
It's a small area, like 15 x 15 sqms.

This script will run only in a specific day, one time.

bad script :( but its working.. but I need more borders

Code:
local config = {
[11775] = 6695,
[11776] = 6698,
[11777] = 6697,
[11778] = 6696,
[11785] = 6699,
[11786] = 6700,
[11787] = 6702,
[11788] = 6701,
[11789] = 6703,
[11790] = 6704,
[11791] = 6706,
[11792] = 6705

}

local function halfMoon()
    for x = fromPos.x, toPos.x do
        for y = fromPos.y, toPos.y do
            for z = fromPos.z, toPos.z do
                local border1 = Tile(Position(x,y,z)):getItemById(11775)
                local border2 = Tile(Position(x,y,z)):getItemById(11776)
                local border3 = Tile(Position(x,y,z)):getItemById(11777)
                local border4 = Tile(Position(x,y,z)):getItemById(11778)
                local border5 = Tile(Position(x,y,z)):getItemById(11785)
                local border6 = Tile(Position(x,y,z)):getItemById(11786)
                local border7 = Tile(Position(x,y,z)):getItemById(11787)
                local border8 = Tile(Position(x,y,z)):getItemById(11788)
                local border9 = Tile(Position(x,y,z)):getItemById(11789)
                local border10 = Tile(Position(x,y,z)):getItemById(11790)
                local border11 = Tile(Position(x,y,z)):getItemById(11791)
                local border12 = Tile(Position(x,y,z)):getItemById(11792)
                if border1 then
                    border1:transform(6695)
                elseif border2 then
                    border1:transform(6698)
                elseif border3 then
                    border1:transform(6697)
                elseif border4 then
                    border1:transform(6696)
                elseif border5 then
                    border1:transform(6699)
                elseif border6 then
                    border1:transform(6700)
                elseif border7 then
                    border1:transform(6702)
                elseif border8 then
                    border1:transform(6701)
                elseif border9 then
                    border1:transform(6703)
                elseif border10 then
                    border1:transform(6704)
                elseif border11 then
                    border1:transform(6706)
                elseif border12 then
                    border1:transform(6705)
                end
            end
        end
    end                  
end
 
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)
too lazy to optimize the script but it works
though like mkalo said you shouldn't do this for huge areas
 
Solution
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)
too lazy to optimize the script but it works
though like mkalo said you shouldn't do this for huge areas

Wow! Thanks. A question, it should replace ground tiles too?
 
For example, there are some SQMS that has 2 or more borders on that specific SQM. I checked that this function only changes one of them. I shoud execute this function 2 or more times to get all transformed?

Edit:
Maybe you could make the function execute until it don't find nothing more to remove/transform?
 
Last edited:
For example, there are some SQMS that has 2 or more borders on that specific SQM. I checked that this function only changes one of them. I shoud execute this function 2 or more times to get all transformed?

Edit:
Maybe you could make the function execute until it don't find nothing more to remove/transform?
you can edit it to check the second index of the items instead of the first(which is what i used for border)
 
Back
Top