• 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 Trainers Teleport

_M4G0_

Well-Known Member
Joined
Feb 6, 2016
Messages
504
Solutions
16
Reaction score
98
I don't know what is wrong, if someone can help
Lua:
local storage = 5845

local config = {
    first_room_pos = Position(33851, 28794, 8),
    distX= 8,
    distY= 3,
    distZ= 1,
    rX= 1,
    rY= 1,
    rZ= 2,
}

local function isBusyable(position)
    local tile = Tile(position)
    if not tile then
        return false
    end

    local ground = tile:getGround()
    if not ground or ground:hasProperty(CONST_PROP_BLOCKSOLID) then
        return false
    end

    local player = tile:getTopCreature()
    if player then
        if player:isPlayer() then
            return false
        end
    end

    local items = tile:getItems()
    for i = 1, tile:getItemCount() do
        local item = items[i]
        local itemType = item:getType()
        if itemType:getType() ~= ITEM_TYPE_MAGICFIELD and not itemType:isMovable() and item:hasProperty(CONST_PROP_BLOCKSOLID) then
            return false
        end
    end

    return true
end

local function addTrainers(position, arrayPos)
    if not isBusyable(position) then
        for places = 1, #arrayPos do
            local trainer = Tile(arrayPos[places]):getTopCreature()
            if not trainer then
                local monster = Game.createMonster("Target", arrayPos[places])
                monster:getPosition():sendMagicEffect(CONST_ME_MAGIC_BLUE)
            end
        end
    end
end

local function calculatingRoom(uid, position, coluna, linha, andar)
    local player = Player(uid)
    if coluna >= config.rX then
        coluna = 0
        linha = linha <= (config.rY) and linha + 1 or false
        if not linha then
            linha = 0
            andar = andar <= (config.rZ) and andar - 1 or false
        end
    end

    if andar then
        local room_pos = {x = position.x + (coluna * config.distX), y = position.y + (linha * config.distY), z = position.z + (andar * config.distZ)}
        if isBusyable(room_pos) then
            player:teleportTo(room_pos)
            player:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
            addTrainers(room_pos, {{x = room_pos.x - 1, y = room_pos.y + 1, z = room_pos.z}, {x = room_pos.x + 1 , y = room_pos.y + 1, z = room_pos.z}})
        else
            calculatingRoom(uid, position, coluna + 1, linha, andar)
        end
    else
        player:sendCancelMessage("Couldn't find any position for you right now.")
        player:teleportTo(Position(32369, 32241, 7))
    end
end

function onStepIn(creature, item, position, fromPosition)
    if not creature:isPlayer() then
        return false
    end
    print(tile)
    if creature:getStorageValue(storage) - os.time() > 0 then
        creature:sendTextMessage(MESSAGE_INFO_DESCR, "You gotta wait a few seconds before you can enter trainning room again")
        creature:teleportTo(fromPosition, true)
        return true
    end

    calculatingRoom(creature.uid, config.first_room_pos, 0, 0, 0)

    return true
end
when there is no more space (position) of this error
Code:
Lua Script Error: [MoveEvents Interface]
data/movements/scripts/Novos/trainer_entrar.lua:onStepIn
data/movements/scripts/Novos/trainer_entrar.lua:14: stack overflow
stack traceback:
        [C]: in function 'Tile'
        data/movements/scripts/Novos/trainer_entrar.lua:14: in function 'isBusyable'
        data/movements/scripts/Novos/trainer_entrar.lua:68: in function 'calculatingRoom'
        data/movements/scripts/Novos/trainer_entrar.lua:73: in function 'calculatingRoom'
        data/movements/scripts/Novos/trainer_entrar.lua:73: in function 'calculatingRoom'
        data/movements/scripts/Novos/trainer_entrar.lua:73: in function 'calculatingRoom'
        data/movements/scripts/Novos/trainer_entrar.lua:73: in function 'calculatingRoom'
        data/movements/scripts/Novos/trainer_entrar.lua:73: in function 'calculatingRoom'
        data/movements/scripts/Novos/trainer_entrar.lua:73: in function 'calculatingRoom'
        data/movements/scripts/Novos/trainer_entrar.lua:73: in function 'calculatingRoom'
        ...
        data/movements/scripts/Novos/trainer_entrar.lua:73: in function 'calculatingRoom'
        data/movements/scripts/Novos/trainer_entrar.lua:73: in function 'calculatingRoom'
        data/movements/scripts/Novos/trainer_entrar.lua:73: in function 'calculatingRoom'
        data/movements/scripts/Novos/trainer_entrar.lua:73: in function 'calculatingRoom'
        data/movements/scripts/Novos/trainer_entrar.lua:73: in function 'calculatingRoom'
        data/movements/scripts/Novos/trainer_entrar.lua:73: in function 'calculatingRoom'
        data/movements/scripts/Novos/trainer_entrar.lua:73: in function 'calculatingRoom'
        data/movements/scripts/Novos/trainer_entrar.lua:73: in function 'calculatingRoom'
        data/movements/scripts/Novos/trainer_entrar.lua:73: in function 'calculatingRoom'
        data/movements/scripts/Novos/trainer_entrar.lua:73: in function 'calculatingRoom'
        data/movements/scripts/Novos/trainer_entrar.lua:92: in function <data/movements/scripts/Novos/trainer_entrar.lua:81>
"Tile" returns like nil
tfs 1.2
 
Solution
Avoid bumps.
----------------

Try. Tested & It worked over here.
Lua:
local storage = 5845
local config = {
    temple_pos     = Position(32369, 32241, 7),
    first_room_pos = Position(33851, 28794, 8),
    distX = 8,
    distY = 4,
    distZ = 1,
    radiusX = 1,
    radiusY = 1,
    radiusZ = -2,
}

local function isBusyable(position)
    local tile = Tile(position)

    if not tile then
        return false
    end

    local ground = tile:getGround()
    if not ground or ground:hasProperty(CONST_PROP_BLOCKSOLID) then
        return false
    end

    local player = tile:getTopCreature()
    if player then
        if player:isPlayer() then
            return false
        end
    end

    local items =...
Avoid bumps.
----------------

Try. Tested & It worked over here.
Lua:
local storage = 5845
local config = {
    temple_pos     = Position(32369, 32241, 7),
    first_room_pos = Position(33851, 28794, 8),
    distX = 8,
    distY = 4,
    distZ = 1,
    radiusX = 1,
    radiusY = 1,
    radiusZ = -2,
}

local function isBusyable(position)
    local tile = Tile(position)

    if not tile then
        return false
    end

    local ground = tile:getGround()
    if not ground or ground:hasProperty(CONST_PROP_BLOCKSOLID) then
        return false
    end

    local player = tile:getTopCreature()
    if player then
        if player:isPlayer() then
            return false
        end
    end

    local items = tile:getItems()
    for i = 1, tile:getItemCount() do
        local item = items[i]
        local itemType = item:getType()
        if itemType:getType() ~= ITEM_TYPE_MAGICFIELD and not itemType:isMovable() and item:hasProperty(CONST_PROP_BLOCKSOLID) then
            return false
        end
    end
    return true
end

local function addTrainers(position, arrayPos)
    if not isBusyable(position) then
        for places = 1, #arrayPos do
            local trainer = Tile(arrayPos[places]):getTopCreature()
            if not trainer then
                local monster = Game.createMonster("Monk", arrayPos[places])
                monster:getPosition():sendMagicEffect(CONST_ME_MAGIC_BLUE)
            end
        end
    end
end

local function calculatingRoom(player, position, stepX, stepY, stepZ)
    if stepZ then
        local room_pos = {
            x = position.x + (stepX * config.distX),
            y = position.y + (stepY * config.distY),
            z = position.z + (stepZ * config.distZ)
        }
        print(room_pos.x, room_pos.y, room_pos.z)
        if isBusyable(room_pos) then
            player:teleportTo(room_pos)
            player:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
            addTrainers(room_pos, {
                {x = room_pos.x - 1, y = room_pos.y + 1, z = room_pos.z},
                {x = room_pos.x + 1 , y = room_pos.y + 1, z = room_pos.z}
            })
        else
            if stepX <= config.radiusX then
                stepX = stepX + 1
            else
                stepX = 0
                if stepY <= config.radiusY then
                    stepY = stepY + 1
                else
                    stepY = 0
                    if stepZ >= config.radiusZ then
                        stepZ  = stepZ - 1
                    else
                        stepZ  = false
                    end
                end
            end
            calculatingRoom(player, position, stepX, stepY, stepZ)
        end
    else
        player:sendCancelMessage("Couldn't find any position for you right now.")
        player:teleportTo(config.temple_pos)
    end
end

function onStepIn(creature, item, position, fromPosition)
    if not creature:isPlayer() then
        return false
    end
    if creature:getStorageValue(storage) - os.time() > 0 then
        creature:sendTextMessage(MESSAGE_INFO_DESCR, "You gotta wait a few seconds before you can enter trainning room again")
        creature:teleportTo(fromPosition, true)
        return true
    end
    calculatingRoom(creature, config.first_room_pos, 0, 0, 0)
    return true
end
 
Solution
Back
Top