• 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.2 return tile id

OperatorMopa

Member
Joined
Feb 10, 2014
Messages
127
Reaction score
6
Hello, i need a function telling me ground ID, that craeture is on.
I've tried creature:getTile(), but it returns empty string. Any ideas?
 
Code:
creature:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, creature:getPosition():getTile())
attempt to call method 'getTile' (a nil value)
 
Code:
function onStepIn(creature, item, position, fromPosition)
    creature:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, Position(creature:getPosition()):getTile():getThing(STACKPOS_GROUND):getId())
end

data/movements/scripts/test.lua:2: attempt to call method 'getTile' (a nil value)
stack traceback:
[C]: in function 'getTile'
data/movements/scripts/test.lua:2: in function <data/movements/scripts/test.lua:1>
 
Why even check player position or even the get the tile. When you are using onStepIn

Code:
 creature:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, item:getId())
 
Code:
creature:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, Tile(Position(creature:getPosition())):getThing(STACKPOS_GROUND):getId())
is what u wanna do
 
It works ! Thank you :)
Why are you using getThing?

I would done something like this:

Code:
local tile = Tile(position)
if tile then
    local ground = tile:getGround()
    if ground then
        print(ground:getId(), ground:getName())
    end
end
 
Why are you using getThing?

I would done something like this:

Code:
local tile = Tile(position)
if tile then
    local ground = tile:getGround()
    if ground then
        print(ground:getId(), ground:getName())
    end
end


I've added few modifications and it works like a charm

Code:
    local tile = Tile(Position(self:getPosition()))
    if tile then
        local ground = tile:getGround()
            if ground then
                self:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, ground:getId())
                self:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, ground:getName())
            end
    end
 
You dont need to construct player position to userdata, when it's already userdata:
enough with Tile(self:getPosition())
 
Code:
    local nextPosition = self:getPosition()
    nextPosition:getNextPosition(direction)

    local tile = Tile(nextPosition)
    if tile then
        local ground = tile:getGround()
        if ground then
            print(ground:getId(), ground:getName())
        end
    end
 
Code:
    local nextPosition = self:getPosition()
    nextPosition:getNextPosition(direction)

    local tile = Tile(nextPosition)
    if tile then
        local ground = tile:getGround()
        if ground then
            print(ground:getId(), ground:getName())
        end
    end

attempt to index local 'direction' (a number value)
 
replace direction with self:getDirection()
Dude, you're a lua GOD ;D

EDIT.

It still doesn't work properly

The thing is that it doesnt always return tile that i step in, sometimes its a tile that i step out.

It's something wrong with direction. When i walk only east on a different tiles it works good, but when i walk few sqm east, stop on sand and step north on cobble pavement it's gonna return sand, not cobble.

So there still is a problem when i change direction
 
Last edited:
Code:
function Player:onMove(direction)
    local nextPosition = self:getPosition()
    nextPosition:getNextPosition(self:getDirection())

    local tile = Tile(nextPosition)
    if tile then
        local ground = tile:getGround()
        if ground then
            self:sendTextMessage(MESSAGE_INFO_DESCR, "NAME: " .. ground:getName())
        end
    end
    return true
end


Look at previous EDIT, i've tried to explain the problem
 
Back
Top