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

Solved check tile edit

shivaria

Active Member
Joined
Sep 2, 2009
Messages
158
Reaction score
36
When I'm im floor 7, trying to go to floor 0, nothing happens, but when I go up higher to floor 6 or 5, it works. Tried changing '7 do' to '8 do' nothing happens

Code:
function onCastSpell(creature, var)
local position = creature:getPosition()
for i = 1, 7 do
position.z = position.z - i
local tile = Tile(position)
if tile then
local tileId = tile:getItemById(460)
if tileId then
creature:teleportTo(position)
return true
end
end
end

return false
end
 
Last edited:
This code hurts my brain. Just tell us what you are trying todo.
cast the spell, and if invisible floor (460) is above you, then teleport up to that floor. If its 3 floors above you and 4 floors, it will teleport to the 3rd first, and if you cast again then the next available floor tile 460.
 
Try:

Code:
function onCastSpell(creature, var)
    local position = creature:getPosition()
    for i = 1, 7 do
        position.z = position.z - i
        local tile = Tile(position)
        if tile then
            local tileId = tile:getItemById(460)
            if tileId then
                 creature:teleportTo(position)
                 return true
            end
        end
    end

    return false
end
 
Last edited:
Try:

Code:
function onCastSpell(creature, var)
    local position = creature:getPosition()
    for i = 1, 7 do
        position.z = position.z - i
        local tile = Tile(position)
        if tile then
            local tileId = tile:getItemById(460)
            if tileId then
                 creature:teleportTo(position)
                 return true
            end
        end
    end

    return false
end
TowAU_qiF.png

nothing happens, beautiful code though

edit: When I'm im floor 7, trying to go to floor 0, nothing happens, but when I go up higher to floor 6 or 5, it works. Tried changing '7 do' to '8 do' nothing happens
 
Last edited:
Code:
function onCastSpell(creature, var)
    local pos = creature:getPosition()
    pos = {x = pos.x, y = pos.y, z = 0, stackpos = 0}
    local tile = Tile(pos)
    if tile then
        if tile:getItemById(460) then
            creature:teleportTo({x = pos.x, y = pos.y, z = 0})
            return true
        end
    end
    return false
end
 
Last edited:
Code:
function onCastSpell(creature, var)
    local pos = creature:getPosition()
    pos = {x = pos.x, y = pos.y, z = 0, stackpos = 0}
    local tile = Tile(pos)
    if tile then
        if tile:getItemById(460) then
            creature:teleportTo({x = pos.x, y = pos.y, z = 0})
            return true
        end
    end
    return false
end
Wouldn't this skip straight to floor 0? Printer has the right idea about performing a check on each floor above me one at a time, it just doesnt work for some reason when trying to go from floor 7 to floor 0.
I need it to check floor 6,5,4,3,2,1, and then 0. The first tile 460 it finds it teleports to. If i read your code wrong i apologize just let me know

I modified your code and it makes a half working code. This code will fly up to the nearest 6,5,4,3,2,1,0 but doesnt work when going from floor 2 to 0 for some reason.

Code:
function onCastSpell(creature, var)
    local pos0 = creature:getPosition()
    pos0 = {x = pos0.x, y = pos0.y, z = 0, stackpos = 0}
    local pos1 = creature:getPosition()
    pos1 = {x = pos1.x, y = pos1.y, z = 1, stackpos = 0}
    local pos2 = creature:getPosition()
    pos2 = {x = pos2.x, y = pos2.y, z = 2, stackpos = 0}
    local pos3 = creature:getPosition()
    pos3 = {x = pos3.x, y = pos3.y, z = 3, stackpos = 0}
    local pos4 = creature:getPosition()
    pos4 = {x = pos4.x, y = pos4.y, z = 4, stackpos = 0}
    local pos5 = creature:getPosition()
    pos5 = {x = pos5.x, y = pos5.y, z = 5, stackpos = 0}
    local pos6 = creature:getPosition()
    pos6 = {x = pos6.x, y = pos6.y, z = 6, stackpos = 0}

    local tile0 = Tile(pos0)
    local tile1 = Tile(pos1)
    local tile2 = Tile(pos2)
    local tile3 = Tile(pos3)
    local tile4 = Tile(pos4)
    local tile5 = Tile(pos5)
    local tile6 = Tile(pos6)

    if tile6 then
        if tile6:getItemById(460) then
            creature:teleportTo({x = pos6.x, y = pos6.y, z = 6})
            return true
        end
    elseif tile5 then
        if tile5:getItemById(460) then
            creature:teleportTo({x = pos5.x, y = pos5.y, z = 5})
            return true
        end   
    elseif tile4 then
        if tile4:getItemById(460) then
            creature:teleportTo({x = pos4.x, y = pos4.y, z = 4})
            return true
        end
    elseif tile3 then
        if tile3:getItemById(460) then
            creature:teleportTo({x = pos3.x, y = pos3.y, z = 3})
            return true
        end
    elseif tile2 then
        if tile2:getItemById(460) then
            creature:teleportTo({x = pos2.x, y = pos2.y, z = 2})
            return true
        end
    elseif tile1 then
        if tile1:getItemById(460) then
            creature:teleportTo({x = pos1.x, y = pos1.y, z = 1})
            return true
        end
    elseif tile0 then
        if tile0:getItemById(460) then
            creature:teleportTo({x = pos0.x, y = pos0.y, z = 0})
            return true
        end       
   
   
    end
    return false
end

Edit: I need to modify it to always check the floor above so a z + 1 instead of z = 0 for it to work while standing on a floor that has tile 460.

Also working on the reverse script using printers method (since its easier to modify for me)
Code:
function onCastSpell(creature, var)
    local position = creature:getPosition()
    for i = 1, 7 do
        position.z = position.z + i

        grassTiles = {4526,4527,4528,4529,4530,4531,4532,4533,4534,4535,4536,4537,4538,4539,4540,4541}
                for k = 0, #grassTiles do
                local tile = Tile(position):getItemById(grassTiles[k])
               
        if tile then
            creature:teleportTo(position)
                end
        end
    end
return true
end

Any help would be appreciated! :)
 
Last edited:
Simplified.
Code:
function onCastSpell(creature, var)
    local cp = creature:getPosition()
    local pos = {}
    local tilePos = {}
    local max = 6
    for i = 0, max do
        pos[#pos + 1] =  {x = cp.x, y = cp.y, z = i, stackpos = 0}
        tilePos[#tilePos + 1] = Tile(pos[#pos])
        if tilePos[#tilePos] then
            if tilePos[#tilePos]:getItemById(460) then
                creature:teleportTo({x = cp.x, y = cp.y, z = (max - i)})
                return true
            end
        end
    end
    return false
end

Code:
local grassTiles = {4526, 4527, 4528, 4529, 4530, 4531, 4532, 4533, 4534, 4535, 4536, 4537, 4538, 4539, 4540, 4541}

function onCastSpell(creature, var)
    local cp = creature:getPosition()
    local pos = {}
    local tilePos = {}
    local max = 7
    for i = 0, max do
        pos[#pos + 1] =  {x = cp.x, y = cp.y, z = (max - i)}
        tilePos[#tilePos + 1] = Tile(pos[#pos])
        if tilePos[#tilePos] then
            if isInArray(grassTiles, tilePos[#tilePos]:getGround():getId()) then
                creature:teleportTo({x = cp.x, y = cp.y, z = i})
                return true
            end
        end
    end
    return false
end

I would play around with the stackpos whether to include it or not. You could always use getGround():getId() in the 1st script as well and run a comparison.

A fragment of the code is taken from the magic rope script.
https://github.com/otland/forgotten...data/spells/scripts/support/magic rope.lua#L6
 
Last edited:
Wouldn't this skip straight to floor 0? Printer has the right idea about performing a check on each floor above me one at a time, it just doesnt work for some reason when trying to go from floor 7 to floor 0.
I need it to check floor 6,5,4,3,2,1, and then 0. The first tile 460 it finds it teleports to. If i read your code wrong i apologize just let me know

I modified your code and it makes a half working code. This code will fly up to the nearest 6,5,4,3,2,1,0 but doesnt work when going from floor 2 to 0 for some reason.

Code:
function onCastSpell(creature, var)
    local pos0 = creature:getPosition()
    pos0 = {x = pos0.x, y = pos0.y, z = 0, stackpos = 0}
    local pos1 = creature:getPosition()
    pos1 = {x = pos1.x, y = pos1.y, z = 1, stackpos = 0}
    local pos2 = creature:getPosition()
    pos2 = {x = pos2.x, y = pos2.y, z = 2, stackpos = 0}
    local pos3 = creature:getPosition()
    pos3 = {x = pos3.x, y = pos3.y, z = 3, stackpos = 0}
    local pos4 = creature:getPosition()
    pos4 = {x = pos4.x, y = pos4.y, z = 4, stackpos = 0}
    local pos5 = creature:getPosition()
    pos5 = {x = pos5.x, y = pos5.y, z = 5, stackpos = 0}
    local pos6 = creature:getPosition()
    pos6 = {x = pos6.x, y = pos6.y, z = 6, stackpos = 0}

    local tile0 = Tile(pos0)
    local tile1 = Tile(pos1)
    local tile2 = Tile(pos2)
    local tile3 = Tile(pos3)
    local tile4 = Tile(pos4)
    local tile5 = Tile(pos5)
    local tile6 = Tile(pos6)

    if tile6 then
        if tile6:getItemById(460) then
            creature:teleportTo({x = pos6.x, y = pos6.y, z = 6})
            return true
        end
    elseif tile5 then
        if tile5:getItemById(460) then
            creature:teleportTo({x = pos5.x, y = pos5.y, z = 5})
            return true
        end 
    elseif tile4 then
        if tile4:getItemById(460) then
            creature:teleportTo({x = pos4.x, y = pos4.y, z = 4})
            return true
        end
    elseif tile3 then
        if tile3:getItemById(460) then
            creature:teleportTo({x = pos3.x, y = pos3.y, z = 3})
            return true
        end
    elseif tile2 then
        if tile2:getItemById(460) then
            creature:teleportTo({x = pos2.x, y = pos2.y, z = 2})
            return true
        end
    elseif tile1 then
        if tile1:getItemById(460) then
            creature:teleportTo({x = pos1.x, y = pos1.y, z = 1})
            return true
        end
    elseif tile0 then
        if tile0:getItemById(460) then
            creature:teleportTo({x = pos0.x, y = pos0.y, z = 0})
            return true
        end     
 
 
    end
    return false
end

Edit: I need to modify it to always check the floor above so a z + 1 instead of z = 0 for it to work while standing on a floor that has tile 460.

Also working on the reverse script using printers method (since its easier to modify for me)
Code:
function onCastSpell(creature, var)
    local position = creature:getPosition()
    for i = 1, 7 do
        position.z = position.z + i

        grassTiles = {4526,4527,4528,4529,4530,4531,4532,4533,4534,4535,4536,4537,4538,4539,4540,4541}
                for k = 0, #grassTiles do
                local tile = Tile(position):getItemById(grassTiles[k])
             
        if tile then
            creature:teleportTo(position)
                end
        end
    end
return true
end

Any help would be appreciated! :)

You should be more specific about what you want. Do you want separate codes, one to go up and other to go down? Or do you want to do both in the same spell.

If you want to do both in the same spell there is a problem with your idea of teleporting to the closest available tile with the id, because for example. If you are in a tile 460 at z=7 and there is a tile 460 under you at z=6 and another tile at z=4, the code is going to teleport you to the z=6 when you use it for the first time and in the second time it will teleport you back to the z=7 because its the closest tile with the id 460. You would never get to the z=4

Simplified.
Code:
function onCastSpell(creature, var)
    local cp = creature:getPosition()
    local pos = {}
    local tilePos = {}
    local max = 6
    for i = 0, max do
        pos[#pos + 1] =  {x = cp.x, y = cp.y, z = i, stackpos = 0}
        tilePos[#tilePos + 1] = Tile(pos[#pos])
        if tilePos[#tilePos] then
            if tilePos[#tilePos]:getItemById(460) then
                creature:teleportTo({x = cp.x, y = cp.y, z = (max - i)})
                return true
            end
        end
    end
    return false
end

Code:
local grassTiles = {4526, 4527, 4528, 4529, 4530, 4531, 4532, 4533, 4534, 4535, 4536, 4537, 4538, 4539, 4540, 4541}

function onCastSpell(creature, var)
    local cp = creature:getPosition()
    local pos = {}
    local tilePos = {}
    local max = 7
    for i = 0, max do
        pos[#pos + 1] =  {x = cp.x, y = cp.y, z = (max - i)}
        tilePos[#tilePos + 1] = Tile(pos[#pos])
        if tilePos[#tilePos] then
            if isInArray(grassTiles, tilePos[#tilePos]:getGround():getId()) then
                creature:teleportTo({x = cp.x, y = cp.y, z = i})
                return true
            end
        end
    end
    return false
end

I would play around with the stackpos whether to include it or not. You could always use getGround():getId() in the 1st script as well and run a comparison.

A fragment of the code is taken from the magic rope script.
https://github.com/otland/forgottenserver/blob/26f3e3731915fe5e2984d4b997f82d10769f205c/data/spells/scripts/support/magic rope.lua#L6

I don't think your code is going to do what he asked, and why the hell are you storing the position and the tile in the table if you are not even going to use it?

"pos[#pos + 1] = {x = cp.x, y = cp.y, z = i, stackpos = 0}"
"creature:teleportTo({x = cp.x, y = cp.y, z = (max - i)})"

As your loop starts from 0, if it finds a tile on z = 0 its going to teleport the player to z = max-0 that would be 7. Thats not what he asked.
 
You should be more specific about what you want. Do you want separate codes, one to go up and other to go down? Or do you want to do both in the same spell.

If you want to do both in the same spell there is a problem with your idea of teleporting to the closest available tile with the id, because for example. If you are in a tile 460 at z=7 and there is a tile 460 under you at z=6 and another tile at z=4, the code is going to teleport you to the z=6 when you use it for the first time and in the second time it will teleport you back to the z=7 because its the closest tile with the id 460. You would never get to the z=4



I don't think your code is going to do what he asked, and why the hell are you storing the position and the tile in the table if you are not even going to use it?

"pos[#pos + 1] = {x = cp.x, y = cp.y, z = i, stackpos = 0}"
"creature:teleportTo({x = cp.x, y = cp.y, z = (max - i)})"

As your loop starts from 0, if it finds a tile on z = 0 its going to teleport the player to z = max-0 that would be 7. Thats not what he asked.
Wow, that was such a dick headed reply...
I did use the stored position or do I need to explain my code step by step?
Do you feel good about yourself?
Instead of just trolling my post, provide the intended solution as well..
 
Try it with your code but just replacing i for 1.

Code:
function onCastSpell(creature, var)
    local position = creature:getPosition()
    for i = 1, 7 do
        position.z = position.z - 1

        local tile = Tile(position)
        if tile then
            local tileId = tile:getItemById(460)
            if tileId then
                creature:teleportTo(position)
                return true
            end
        end
    end

    return false
end
 
Try it with your code but just replacing i for 1.

Code:
function onCastSpell(creature, var)
    local position = creature:getPosition()
    for i = 1, 7 do
        position.z = position.z - 1

        local tile = Tile(position)
        if tile then
            local tileId = tile:getItemById(460)
            if tileId then
                creature:teleportTo(position)
                return true
            end
        end
    end

    return false
end
xD
if creature z pos is 7 then it jsut loops it 7 times and every time z pos is 6

EDIT:
btw what does you tile 460 do?
maybe player falls trough there? (teleporTo() executes onStepIn function for the teleported tile)

Also check is the tile 460 in correct place. because every floor upwards the x and y value increases by 1 in RME. (so its visually a little tilted)
 
Last edited:
xD
if creature z pos is 7 then it jsut loops it 7 times and every time z pos is 6

EDIT:
btw what does you tile 460 do?
maybe player falls trough there? (teleporTo() executes onStepIn function for the teleported tile)

Also check is the tile 460 in correct place. because every floor upwards the x and y value increases by 1 in RME. (so its visually a little tilted)

No.. it won't. That is a very basic loop.
https://repl.it/B9mc
 
Try it with your code but just replacing i for 1.

Code:
function onCastSpell(creature, var)
    local position = creature:getPosition()
    for i = 1, 7 do
        position.z = position.z - 1

        local tile = Tile(position)
        if tile then
            local tileId = tile:getItemById(460)
            if tileId then
                creature:teleportTo(position)
                return true
            end
        end
    end

    return false
end
Works Perfectly!
now working on reverse code, Im not good with calling from arrays though
Code:
local grassTiles = {4526, 4527, 4528, 4529, 4530, 4531, 4532, 4533, 4534, 4535, 4536, 4537, 4538, 4539, 4540, 4541}


function onCastSpell(creature, var)
    local position = creature:getPosition()
    for i = 1, 7 do
        position.z = position.z + 1

        local tile = Tile(position)
        if tile then
            local tileId = tile:getItemById(grassTiles)
            if tileId then
                creature:teleportTo(position)
                return true
            end
        end
    end

    return false
end

Edit: Solved it, thanks everyone! Heres working reverse code
Code:
local grassTiles = {4526, 4527, 4528, 4529, 4530, 4531, 4532, 4533, 4534, 4535, 4536, 4537, 4538, 4539, 4540, 4541}


function onCastSpell(creature, var)
    local position = creature:getPosition()
    for i = 1, 7 do
        position.z = position.z + 1

        local tile = Tile(position)
        if tile then
            if isInArray(grassTiles, tile:getGround():getId())  then
                creature:teleportTo(position)
                return true
            end
        end
    end

    return false
end
 
Last edited:
Back
Top