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

TFS 1.X+ Error moving upstairs using stairs on position X,Y,Z

Marco Oliveira

Well-Known Member
Joined
Jan 5, 2019
Messages
78
Solutions
3
Reaction score
88
Location
Minas Gerais - Brazil
GitHub
omarcopires
Twitch
omarcopires
When going up a ladder on the server from position 1070, 1032, 5 to position 1070, 1031, 4, the console returns an error message regarding an out-of-range value for an unsigned short argument.

LUA:
Lua Script Error: [Scripts Interface]
D:\Repositorios Git\baiak-yurots\data\scripts\actions\others\teleport.lua:callback
LuaScriptInterface::getNumber(). Argument -1 has out-of-range value for unsigned short: -1
stack traceback:
        data/lib/core/position.lua:43: in function 'moveUpstairs'
        ...it\baiak-yurots\data\scripts\actions\others\teleport.lua:7: in function <...it\baiak-yurots\data\scripts\actions\others\teleport.lua:5>

teleport.lua
LUA:
local upFloorIds = {1386, 3678, 5543, 22845, 22846, 31312, 33785, 33786, 33918, 36899}

local teleport = Action()

function teleport.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if table.contains(upFloorIds, item.itemid) then
        fromPosition:moveUpstairs()
    else
        fromPosition.z = fromPosition.z + 1
    end

    if player:isPzLocked() and Tile(fromPosition):hasFlag(TILESTATE_PROTECTIONZONE) then
        player:sendCancelMessage(RETURNVALUE_PLAYERISPZLOCKED)
        return true
    end

    player:teleportTo(fromPosition, false)
    return true
end

teleport:id(1386, 3678, 5543, 22845, 22846, 31312, 33785, 33786, 33918, 36899)
teleport:register()

function Position:moveUpstairs
LUA:
function Position:moveUpstairs()
    local swap = function(lhs, rhs)
        lhs.x, rhs.x = rhs.x, lhs.x
        lhs.y, rhs.y = rhs.y, lhs.y
        lhs.z, rhs.z = rhs.z, lhs.z
    end

    self.z = self.z - 1

    local defaultPosition = self + Position.directionOffset[DIRECTION_SOUTH]
    local toTile = Tile(defaultPosition)
    if not toTile or not toTile:isWalkable() then
        for direction = DIRECTION_NORTH, DIRECTION_NORTHEAST do
            if direction == DIRECTION_SOUTH then
                direction = DIRECTION_WEST
            end

            local position = self + Position.directionOffset[direction]
            toTile = Tile(position)
            if toTile and toTile:isWalkable() then
                swap(self, position)
                return self
            end
        end
    end
    swap(self, defaultPosition)
    return self
end

Note: I tried some corrections but I didn't get success. My server is based on TFS (master) and the only change in this part of the code was to take the teleport.lua to revscript after adding some missing stairs, however the error already existed before when it was recorded in XML.
 
check this i think
Position.directionOffset[direction]
Position() cannot have -1 values so you will need to use different method on calculating that somehow...
i remember having similar problem in some older ots'es
 
its mostly
change
Position(-1,0,0)
to
{x=-1,y=0,z=0} and use .x .y or .z for computation it adds some of the garbage looking things but will most likely work without throwing errors
its simply uint that causing that somewhere and engine is freaking out
 
its mostly
change
Position(-1,0,0)
to
{x=-1,y=0,z=0} and use .x .y or .z for computation it adds some of the garbage looking things but will most likely work without throwing errors
its simply uint that causing that somewhere and engine is freaking out
Sorry, but still I have no idea how to fix the function.
Post automatically merged:

Fixed issue with: Fix issue with position calculation in move function by omarcopires · Pull Request #4323 · otland/forgottenserver (https://github.com/otland/forgottenserver/pull/4323)
 
Last edited:
Back
Top