• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

OTCv8 bug creature direction

anyeor

Member
Joined
Jan 6, 2010
Messages
132
Solutions
2
Reaction score
20
Hey,
I'm having trouble with the player's direction when moving up and down stairs. As a spectator, I see the correct direction, but as a player, I see the wrong direction. Does anyone know where I should look to fix this? Thanks.

Nagrywanie_2024-10-22_193049_1_-_Trim.gif
 
Its not just with stairs the same thing happens if you use /c playername. I think it tries to predict where the player was looking, because the spectator client doesnt know the players original direction, so when they appear, it just makes a prediction. At least thats what i assume
 
Its not just with stairs the same thing happens if you use /c playername. I think it tries to predict where the player was looking, because the spectator client doesnt know the players original direction, so when they appear, it just makes a prediction. At least thats what i assume

It's a client side bug I think

if u use player:setDirection(EAST) it won't update it for your view but for others it does
My experience with c++ is to bad to fix that
 
It's a client side bug I think

if u use player:setDirection(EAST) it won't update it for your view but for others it does
My experience with c++ is to bad to fix that
are you using 1.5+ or 1.4 ?

Its not just with stairs the same thing happens if you use /c playername. I think it tries to predict where the player was looking, because the spectator client doesnt know the players original direction, so when they appear, it just makes a prediction. At least thats what i assume
same question :D u using 1.5+ ?
 
From what I recall this works well with TFS, but not with RealOTS. You'll see yourself facing the correct direction, but other players won't see it that way.
This is TFS based 1.4.2 let me check from other view
Nope it faces the stairs direction, for my char and different chars i tried with MC
 
From what I recall this works well with TFS, but not with RealOTS. You'll see yourself facing the correct direction, but other players won't see it that way.

It's the other way

Your view is wrong, from people view it's right

god marko view
1753471192308.webp

Knight view
1753471213411.webp
 
It's the other way

Your view is wrong, from people view it's right

god marko view
View attachment 93917

Knight view
View attachment 93918
Thats what i understood from his message.

I believe its easy for a beginner coder with basic knowledge to add a simple check on the stairs direction in position.z - 1 and set player direction based on it.

 
Thats what i understood from his message.

I believe its easy for a beginner coder with basic knowledge to add a simple check on the stairs direction in position.z - 1 and set player direction based on it.

If it was easy everyone would be pro programmer, hard part comes when you have to write it in smart way and consider all out comes like proper check for nil values before using objects like the player, the tile, position or any item or thing retrieved from the map, because after a while you will be scrathing your head and thinking why is my server crashing sometimes
 
Im on tfs 1.2 :D

In game.cpp, when handling floor changes (around line 769+) , the setDirection(direction); line is completely missing for both going up and down and I guess this the problem .

C++:
if (!tmpTile->hasFlag(TILESTATE_FLOORCHANGE)) {
    creature->setDirection(direction);  // Add this line
    destPos.z--;
}

Around line 779 (going down stairs): same as it should be fixed add the same line in the pervious code .

I guess this should fix the problem .. with tfs 1.5 i think it's really client issue if im mistaken it would be from protocolgame 100%
 
In game.cpp, when handling floor changes (around line 769+) , the setDirection(direction); line is completely missing for both going up and down and I guess this the problem .

C++:
if (!tmpTile->hasFlag(TILESTATE_FLOORCHANGE)) {
    creature->setDirection(direction);  // Add this line
    destPos.z--;
}

Around line 779 (going down stairs): same as it should be fixed add the same line in the pervious code .

I guess this should fix the problem .. with tfs 1.5 i think it's really client issue if im mistaken it would be from protocolgame 100%

This is already done here using internalCreatureTurn the issue is the creature is standing correctly but for the user that is currently online on the char that used stairs can see incorrect direction meanwhile if any other player passes by him he will see him in the expected direction (Thats TFS 1.4.2 + OTCv8)
Post automatically merged:

Here is the solution i went with when i had this solved.

yourClientPath/modules/game_walking/walking.lua

in init() you must make sure you add if not existing
Code:
connect(LocalPlayer, {onPositionChange = onPositionChange})
and in terminate
Code:
disconnect(LocalPlayer, {onPositionChange = onPositionChange})

if onPositionChange have other code in your walking.lua just put the code at the end of onPositionChange and keep 1 callback only to merge them.
LUA:
function getDirectionTo(from, to)
    if from.x == to.x and from.y == to.y then
        return InvalidDirection
    end

    local dir
    local x_offset = to.x - from.x
    if x_offset < 0 then
        dir = 3
        x_offset = -x_offset
    else
        dir = 1
    end

    local y_offset = to.y - from.y
    if y_offset >= 0 then
        if y_offset > x_offset then
            dir = 2
        elseif y_offset == x_offset then
            if dir == 3 then
                dir = 6
            else
                dir = 5
            end
        end
    else
        y_offset = -y_offset
        if y_offset > x_offset then
            dir = 0
        elseif y_offset == x_offset then
            if dir == 3 then
                dir = 7
            else
                dir = 4
            end
        end
    end

    return dir
end

function onPositionChange(player, newPos, oldPos)
    if (oldPos.z ~= newPos.z and (oldPos.x ~= newPos.x or oldPos.y ~= newPos.y)) then
        local dir = getDirectionTo(oldPos, newPos);
        if(dir ~= 8) then
            player:setDirection(dir);
        end
    end
end
basically this code snippet won't have any effect on serverSide nor clientSide since it just change the direction internally in the client without notifying the server so its a work around that is effective because the client was not notified that the server changed the direction so it fills the loop perfectly
 
Last edited:

This is already done here using internalCreatureTurn the issue is the creature is standing correctly but for the user that is currently online on the char that used stairs can see incorrect direction meanwhile if any other player passes by him he will see him in the expected direction (Thats TFS 1.4.2 + OTCv8)
Post automatically merged:

Here is the solution i went with when i had this solved.

yourClientPath/modules/game_walking/walking.lua

in init() you must make sure you add if not existing
Code:
connect(LocalPlayer, {onPositionChange = onPositionChange})
and in terminate
Code:
disconnect(LocalPlayer, {onPositionChange = onPositionChange})

if onPositionChange have other code in your walking.lua just put the code at the end of onPositionChange and keep 1 callback only to merge them.
LUA:
function getDirectionTo(from, to)
    if from.x == to.x and from.y == to.y then
        return InvalidDirection
    end

    local dir
    local x_offset = to.x - from.x
    if x_offset < 0 then
        dir = 3
        x_offset = -x_offset
    else
        dir = 1
    end

    local y_offset = to.y - from.y
    if y_offset >= 0 then
        if y_offset > x_offset then
            dir = 2
        elseif y_offset == x_offset then
            if dir == 3 then
                dir = 6
            else
                dir = 5
            end
        end
    else
        y_offset = -y_offset
        if y_offset > x_offset then
            dir = 0
        elseif y_offset == x_offset then
            if dir == 3 then
                dir = 7
            else
                dir = 4
            end
        end
    end

    return dir
end

function onPositionChange(player, newPos, oldPos)
    if (oldPos.z ~= newPos.z and (oldPos.x ~= newPos.x or oldPos.y ~= newPos.y)) then
        local dir = getDirectionTo(oldPos, newPos);
        if(dir ~= 8) then
            player:setDirection(dir);
        end
    end
end

Yeah that solved the problem nice thanks you appreciate it
Only left to check why player:setDirection doesnt set the direction from your view
 
Yeah that solved the problem nice thanks you appreciate it
Only left to check why player:setDirection doesnt set the direction from your view
It is because setDirection just fills the variable direction inside Player class with the value it doesn't tell the client of the new direction when using player:setDirection in lua or c++ because you didn't call sendCreatureTurn from c++ so the client won't be notified of the change and since you can't use sendCreatureTurn on self it is pointless, (Self is the player that is on the client of the otherside connection in this instance which is LocalPlayer on OTCv8) so this localPlayer will never be notified of its new direction neither the players around it BUT if players around him left the location and came back they will see the new direction that was added with set because this will trigger the client to update the player direction when sendAddCreature triggers addCreature that send protocolMessage on a header that triggers getCreature in clientSide and finally setDirection in clientSide thats why you can't see that your direction is changed but others can
 
Back
Top