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

problem function "GetTile" TFS 1.1

leozynho123

Member
Joined
Sep 14, 2014
Messages
128
Reaction score
8
Good evening, I'm having a problem with movements, could anyone help me with this problem with the getTile function

28im2o0.png



2q37r4z.png
 
Please provide code.

Lua:
function onStepIn(creature, item, position, fromPosition)
    item:transform(425)

    if item.actionid == 30049 then
        local new_position = Position(0, position.y, position.z)
        for i = 5, 0, -1 do
            new_position.x = position.x + 2 + i
            local tile = new_position:getTile()
            if i == 5 then
                new_position.x = position.x + 2
            else
                new_position.x = new_position.x + 1
            end

            local itemCount = tile:getDownItemCount()
            if itemCount > 0 then
                tile:getThing(tile:getTopItemCount() + tile:getCreatureCount() + itemCount):moveTo(new_position)
            end
        end
    elseif item.actionid == 30050 then
        local new_position = Position(position.x, 0, position.z)
        for i = 5, 0, -1 do
            new_position.y = position.y + 2 + i
            local tile = new_position:getTile()
            if i == 5 then
                new_position.y = position.y + 2
            else
                new_position.y = new_position.y + 1
            end

            local itemCount = tile:getDownItemCount()
            if itemCount > 0 then
                tile:getThing(tile:getTopItemCount() + tile:getCreatureCount() + itemCount):moveTo(new_position)
            end
        end
    end
    return true
end

function onStepOut(creature, item, position, fromPosition)
    item:transform(426)
    return true
end
 
Last edited by a moderator:
is
Code:
 local new_position = Position(0, position.y, position.z)
the proper way to define a position in lua?

Im not sure if you can getTile just from position, I can't see this lua function in unmodified tfs


@edit
a yeah, there are the constructors. As Xeraphus said use
Code:
    Tile(x, y, z)
    Tile(position)
 
is
Code:
 local new_position = Position(0, position.y, position.z)
the proper way to define a position in lua?

Im not sure if you can getTile just from position, I can't see this lua function in unmodified tfs


@edit
a yeah, there are the constructors. As Xeraphus said use
Code:
    Tile(x, y, z)
    Tile(position)


Sorry, but I could not understand, my friend.
 
new promen , help ?

el1y6q.png



Code:
local walls = {
    Position(32760, 32288, 14),
    Position(32761, 32288, 14),
    Position(32762, 32288, 14),
    Position(32763, 32288, 14),
    Position(32764, 32288, 14),
    Position(32764, 32289, 14),
    Position(32764, 32290, 14),
    Position(32764, 32291, 14),
    Position(32764, 32292, 14),
    Position(32763, 32292, 14),
    Position(32762, 32292, 14),
    Position(32761, 32292, 14),
    Position(32760, 32292, 14),
    Position(32760, 32291, 14),
    Position(32760, 32290, 14),
    Position(32760, 32289, 14)
}

function onStepIn(cid, item, position)
    local player = creature:getPlayer()
    if not player then
        return true
    end

    for i = 1, #walls do
        if Tile(walls[I]):hasFlag(TILESTATE_IMMOVABLEBLOCKSOLID) then
            player:teleportTo(Position(32762, 32305, 14))
            player:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
            return true
        end
    end

    player:teleportTo(Position(32852, 32287, 14))
    player:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
    return true
end
 
change
Lua:
function onStepIn(cid, item, position)
to
Lua:
function onStepIn(creature, item, position)
 
Last edited by a moderator:
also change:
Lua:
if Tile(walls[I]):hasFlag(TILESTATE_IMMOVABLEBLOCKSOLID) then
to
Lua:
if Tile(walls[i]):hasFlag(TILESTATE_IMMOVABLEBLOCKSOLID) then



Actually, if you use more scripts from the same data pack you may encounter more errors. It's possible position:getTile() is used in more places, considering their data pack includes this function which you apparently don't have:
Lua:
function Position.getTile(self)
    return Tile(self)
end

In such case you should probably include that function in your server.
 
Last edited:
also change:
Lua:
if Tile(walls[I]):hasFlag(TILESTATE_IMMOVABLEBLOCKSOLID) then
to
Lua:
if Tile(walls[i]):hasFlag(TILESTATE_IMMOVABLEBLOCKSOLID) then

The two tags are the same friend

change
Lua:
function onStepIn(cid, item, position)
to
Lua:
function onStepIn(creature, item, position)

Friend worked, thank you.
 
They are not same, there's I and there's i.

And read my updated post I added some comments.


Please do not double post!
 
also change:
Lua:
if Tile(walls[I]):hasFlag(TILESTATE_IMMOVABLEBLOCKSOLID) then
to
Lua:
if Tile(walls[i]):hasFlag(TILESTATE_IMMOVABLEBLOCKSOLID) then



Actually, if you use more scripts from the same data pack you may encounter more errors. It's possible position:getTile() is used in more places, considering their data pack includes this function which you apparently don't have:
Lua:
function Position.getTile(self)
    return Tile(self)
end

In such case you should probably include that function in your server.


Where do I add this function? In tfs 1.1 it's all so different
 
2rr6o3s.png



Code:
local config = {
    {position = Position(32845, 32264, 14), itemId = 2639},
    {position = Position(32843, 32266, 14), itemId = 2639},
    {position = Position(32843, 32268, 14), itemId = 2639},
    {position = Position(32845, 32268, 14), itemId = 2639},
    {position = Position(32844, 32267, 14), itemId = 2639},
    {position = Position(32840, 32269, 14), itemId = 2639},
    {position = Position(32841, 32269, 14), itemId = 2638},
    {position = Position(32840, 32268, 14), itemId = 2638},
    {position = Position(32842, 32267, 14), itemId = 2638}
}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    item:transform(item.itemid == 1945 and 1946 or 1945)

    if item.itemid == 1945 then
        local pillar
        for x = 32835, 32838 do
            pillar = Tile(Position(x, 32285, 14)):getItemById(1515)
            if pillar then
                pillar:remove()
            end
        end
    else
        local position
        for x = 32835, 32838 do
            position = Position(x, 32285, 14)
            if not Tile(position):getItemById(1515) then
                Game.createItem(1515, 1, position)
            end
        end
    end
   
    local tokens, ticTacToeItem = true
    for i = 1, #config do
        ticTacToeItem = Tile(config[i].position):getItemById(config[i].itemId)
        if not ticTacToeItem then
            tokens = false
            break
        end
    end

    if not tokens then
        return true
    end
   
    local position = Position(32836, 32288, 14)
    if item.itemid == 1945 then
        local crack = Tile(position):getItemById(6299)
        if crack then
            crack:transform(1387)
            crack:setAttribute(ITEM_ATTRIBUTE_UNIQUEID, 31245)
        end
    else
        local teleport = Tile(position):getItemById(1387)
        if teleport then
            teleport:transform(6299)
        end
    end
    return true
end

new error
 
Back
Top