• 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 Help to return various random positions

Syl4s

Member
Joined
Apr 8, 2021
Messages
4
Reaction score
13
I would like help to return several positions below this function currently it only returns 1

Lua:
function randomSquare2x2(pos)
    local position = {
        -- 9, 10, 11, 12, 13
        -- 14, 01, 02 03, 15
        -- 16, 04, 00, 05, 17 -- 00 is player
        -- 18, 06, 07, 08, 19
        -- 20, 21, 22, 23, 24
    Position(pos.x - 1, pos.y - 1, pos.z), -- 1       
    Position(pos.x, pos.y - 1, pos.z), -- 2
    Position(pos.x + 1, pos.y - 1, pos.z), -- 3
    Position(pos.x - 1, pos.y, pos.z), -- 4       
    Position(pos.x + 1, pos.y, pos.z), -- 5       
    Position(pos.x - 1, pos.y + 1, pos.z), -- 6 
    Position(pos.x, pos.y + 1, pos.z), -- 7         
    Position(pos.x + 1, pos.y + 1, pos.z), -- 8       
    Position(pos.x - 2, pos.y - 2, pos.z), -- 9
    Position(pos.x - 1, pos.y - 2, pos.z), -- 10       
    Position(pos.x, pos.y - 2, pos.z), -- 11       
    Position(pos.x + 1, pos.y - 2, pos.z), -- 12       
    Position(pos.x + 2, pos.y - 2, pos.z), -- 13       
    Position(pos.x - 2, pos.y - 1, pos.z), -- 14
    Position(pos.x + 2, pos.y - 1, pos.z), -- 15       
    Position(pos.x - 2, pos.y, pos.z), -- 16       
    Position(pos.x + 2, pos.y, pos.z), -- 17
    Position(pos.x - 2, pos.y + 1, pos.z), -- 18
    Position(pos.x + 2, pos.y + 1, pos.z), -- 19
    Position(pos.x - 2, pos.y + 2, pos.z), -- 20
    Position(pos.x - 1, pos.y + 2, pos.z), -- 21
    Position(pos.x, pos.y + 2, pos.z), -- 22                           
    Position(pos.x + 1, pos.y + 2, pos.z), -- 23
    Position(pos.x + 2, pos.y + 2, pos.z) -- 24
    } 

    return position[math.random(1,24)]
end
 
Back
Top