• 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 function] getAreaForDir(area, dir)

Shiko Erye

LUA - Scripter
Joined
Dec 7, 2010
Messages
106
Reaction score
12
Lua:
function getAreaForDir(area, dir)
if area == nil then
return false
end

local newarea = {}
local size = #area
if size < #area[1] then
size = #area[1]
end
if math.floor(size/2) == size/2 then
size = size + 1
end
for a = 1, size do
table.insert(newarea, {})
end
for b = 1, size do
table.insert(newarea, {})
end
for q = 1, size do
    if area[q] == nil then
        table.insert(area, {})
    end
end
for w = 1, size do
    for e = 1, size do
        if area[w][e] == nil then
            area[w][e] = 0
        end
    end
end
for y = 1, size do
    for x = 1, size do
        if area[y][x] ~= nil then
            if dir == 0 then
                newarea[y][x] = area[y][x]
            elseif dir == 1 then
                newarea[y][x] = area[size+1-x][y]
            elseif dir == 2 then
                newarea[y][x] = area[size+1-y][x]
            elseif dir == 3 then
                newarea[y][x] = area[x][y]
            end
        end
    end
end
    return newarea
end
example:
Code:
area = {
{1, 1, 1, 1, 1},
{0, 1, 1, 1, 0},
{0, 1, 1, 1, 0},
{0, 0, 1, 0, 0},
{0, 0, 2, 0, 0},
}
if dir = 0 then return
Code:
area = {
{1, 1, 1, 1, 1},
{0, 1, 1, 1, 0},
{0, 1, 1, 1, 0},
{0, 0, 1, 0, 0},
{0, 0, 2, 0, 0},
}
if dir = 1 then return
Code:
area = {
{0, 0, 0, 0, 1},
{0, 0, 1, 1, 1},
{2, 1, 1, 1, 1},
{0, 0, 1, 1, 1},
{0, 0, 0, 0, 1},
}
if dir = 2 then return
Code:
area = {
{0, 0, 2, 0, 0},
{0, 0, 1, 0, 0},
{0, 1, 1, 1, 0},
{0, 1, 1, 1, 0},
{1, 1, 1, 1, 1},
}
if dir = 3 then return
Code:
area = {
{1, 0, 0, 0, 0},
{1, 1, 1, 0, 0},
{1, 1, 1, 1, 2},
{1, 1, 1, 0, 0},
{1, 0, 0, 0, 0},
}

Like me if you think that helpful
 
Last edited:
Back
Top