• 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!

isPosition - is the position valid?

Colandus

Advanced OT User
Senator
Joined
Jun 6, 2007
Messages
2,434
Solutions
19
Reaction score
218
Location
Sweden
Use this function to check whether a position is valid or not.

TFS 0.3+ put in data/lib/functions.lua
TFS 0.2 or other put in data/global.lua
Code:
do
    -- Function by Colandus!
    local validPositionKeys = {"x", "y", "z", "stackpos"}
    function isPosition(pos)
        local keyAmount = 0
        if (type(pos) == "table") then
            for key, val in pairs(pos) do
                if isInTable(validPositionKeys, key) == FALSE or isNumber(val) == FALSE then
                    return FALSE
                end
                keyAmount = keyAmount + 1
            end
            if (keyAmount ~= 3 and keyAmount ~= 4) then
                return FALSE
            end
            return TRUE
        end
        return FALSE
    end
end
 
correct me if im wrong but doesnt querytileaddthing, or whatever, dont feel like looking it up, do the same thing? if i get the gist of this function, its the check if the position is a walkable tile?
 
No it just check if the position table format is valid :p

But doing as you say you'd use "getTileThingByPos" with a position of stackpos 0 and check uid...

Example:
Code:
function positionExists(pos)
    if isPosition(pos) == FALSE then
        error("luaPositionExists: Invalid position format!", 2)
    end

    pos.stackpos = 0
    return getTileThingByPos(pos).uid > 0 and TRUE or FALSE
end

That'd check if a position exist (using this function to check if position is valid) :p
 
Back
Top