• 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?
 
I've tried it before.
Function execute always 2 times so direction returns 2 numbers.
First: current direction (when i walk east its 1)
Second: previous direction
So when I keep moving east its 1,1.

And now the problematic situation.
Walk south ( 2,2 )
First step east ( 1,2 )
Next east steps ( 1,1 )
 
Well i do not recommend to use my commit for the event onMove. Since it was not accepted due to it had bugs and etc..
 
That's not good then xD

Do you have any other solution for my problem ?

I need event tracking every step i make returning tile id that i step in.
 
I've tried it , and it doesn't work for me or i have incorrectly added the creaturescript

Code:
<event type="move" name="CreatureMove" script="test.lua" />
test.lua
Code:
function onMove(creature, newPos, oldPos)
creature:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "TEST")
end
Nothing happens :/

I've also tried to clog some cpp functions and:
1. bool CreatureEvent::executeOnMove in creatureevent.cpp doesn't execute

2. And now the weird part :D
When i add clog at the top of Game::internalMoveCreature in game.cpp it work's fine, but when i add it into "for" loop in the same function (added in gugahoa onMove creature event commit) it doesn't show.
It looks like Game::internalMoveCreature ignore this loop - why ?
 
It is because, onStepIn and onStepOut enchancements has not been done yet.

But here is a hacky way todo it.

Code:
    bool disableMovement = false;
    for (CreatureEvent* moveEvent : creature->getCreatureEvents(CREATURE_EVENT_MOVE)) {
        if (!moveEvent->executeOnMove(creature, destPos, currentPos)) {
            disableMovement = true;
        }
    }

    if (disableMovement) {
        return RETURNVALUE_NOTPOSSIBLE;
    }
 
Then you can do like this:

Code:
function onMove(creature, newPosition, lastPosition)
    local tile = Tile(newPosition)
    if tile then
        local ground = tile:getGround()
        if ground then
            print(creature:getName(), ground:getId(), ground:getName())
        end
    end
   
    return true
end
 
Then you can do like this:

Code:
function onMove(creature, newPosition, lastPosition)
    local tile = Tile(newPosition)
    if tile then
        local ground = tile:getGround()
        if ground then
            print(creature:getName(), ground:getId(), ground:getName())
        end
    end
 
    return true
end
Code:
<event type="move" name="CheckTile" script="test.lua" />

I've changed everything like you said and this function doesn't even execute.
Tried clog on the top of CreatureEvent::executeOnMove - no result
clog on the top of Game::internalMoveCreature - works, but its normall
clog in
Code:
    for (CreatureEvent* moveEvent : creature->getCreatureEvents(CREATURE_EVENT_MOVE)) {
        std::clog << "for moveEvent: " << __FUNCTION__ << std::endl;
        if (!moveEvent->executeOnMove(creature, destPos, currentPos)) {
            disableMovement = true;
        }
    }
- no result
 
Ok :/
Can You explain to me how does this loop work ? I haven't seen "for" like this before
Code:
 for (CreatureEvent* moveEvent : creature->getCreatureEvents(CREATURE_EVENT_MOVE))

Anyway thanks for your help and sorry for wasting your time
 
Ok :/
Can You explain to me how does this loop work ? I haven't seen "for" like this before
Code:
 for (CreatureEvent* moveEvent : creature->getCreatureEvents(CREATURE_EVENT_MOVE))

Anyway thanks for your help and sorry for wasting your time
To explain the functionality for this type of for loop requires you have an understanding of a datatype, return values, pointers & objects.

If you know all that listed above you don't need us to explain what it is / how it works, but then again if we did explain it, you wouldn't understand what we were talking about anyway. :(

It is a catch 22...
 
Back
Top