• 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 Converting functions to TFS 1.3

Nottinghster

Tibia World RPG Developer
Joined
Oct 24, 2007
Messages
1,570
Solutions
6
Reaction score
437
Location
Brazil - Rio de Janeiro
GitHub
Nottinghster
Hello OTLanders!

I need a little help, since I'm not so familiar with TFS 1.x (first time using) and I always used OTServ_SVN 0.6.4.

Can someone help me converting those functions to TFS 1.3? @Nekiro @Evil Puncker @celohere @M0ustafa @Znote

Thanks a lot!
Lua:
function isInRange(position, fromPosition, toPosition)
    return (position.x >= fromPosition.x and position.y >= fromPosition.y and position.z >= fromPosition.z and position.x <= toPosition.x and position.y <= toPosition.y and position.z <= toPosition.z)
end

Lua:
function isPosition(pos)
    local validPositionKeys = {"x", "y", "z", "stackpos"}
    local keyAmount = 0
    if (type(pos) == "table") then
        for key, val in pairs(pos) do
            if(not table.find(validPositionKeys, key) or not isNumber(val)) then
            return false
            end
        keyAmount = keyAmount + 1
    end
        if (keyAmount ~= 3 and keyAmount ~= 4) then
            return false
        end
        return true
    end
    return false
end

Lua:
function doTeleportPlayersFromArea(fromPos, toPos, newPos)
    if(not (isPosition(fromPos) and isPosition(toPos))) then
        return false, error("luaDoTeleportPlayersFromArea: Invalid position!", 2)
    end

    for _, cid in ipairs(getOnlinePlayers()) do
        local pos = getCreaturePosition(cid)
        if(isInRange(pos, fromPos, toPos)) then
            doTeleportThing(cid, newPos)
            doSendMagicEffect(getCreaturePosition(cid), CONST_ME_TELEPORT)
        end
    end
    return true
end

Lua:
function tileArea(fromPos, toPos, stack)
    local pos = {x=fromPos.x, y=fromPos.y-1, z=fromPos.z}
    return function()
        if (pos.y < toPos.y) then
            pos.y = pos.y+1
        elseif (pos.x <= toPos.x) then
            pos.y = fromPos.y
            pos.x = pos.x+1
        else
            pos.x = fromPos.x
            pos.y = fromPos.y
            pos.z = pos.z+1
        end
        if (pos.x <= toPos.x and pos.y <= toPos.y or pos.z < toPos.z) then
            if (stack == nil) then
                return pos
            else
                pos.stackpos = stack
                return pos, getTileThingByPos(pos)
            end
        end
    end
end

Lua:
function doCleanFields(frompos, topos)
    for pos, thing in tileArea(frompos, topos, 0) do
        if thing.uid ~= 0 then
            pos.stackpos = STACKPOS_TOP_FIELD
            while getThingfromPos(pos).itemid > 0 do
                doSendMagicEffect(pos, CONST_ME_MAGIC_RED)
                doRemoveItem(getThingfromPos(pos).uid, 1)
            end
        end
    end
end
 
Last edited:
there is a isInRange in data/lib/core/position.lua:

Lua:
function Position:isInRange(from, to)
    -- No matter what corner from and to is, we want to make
    -- life easier by calculating north-west and south-east
    local zone = {
        nW = {
            x = (from.x < to.x and from.x or to.x),
            y = (from.y < to.y and from.y or to.y),
            z = (from.z < to.z and from.z or to.z)
        },
        sE = {
            x = (to.x > from.x and to.x or from.x),
            y = (to.y > from.y and to.y or from.y),
            z = (to.z > from.z and to.z or from.z)
        }
    }

    if  self.x >= zone.nW.x and self.x <= zone.sE.x
    and self.y >= zone.nW.y and self.y <= zone.sE.y
    and self.z >= zone.nW.z and self.z <= zone.sE.z then
        return true
    end
    return false
end
 
Last edited by a moderator:
Back
Top