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

Possibility of movement

Caio Cesar

Member
Joined
Nov 23, 2014
Messages
60
Reaction score
6
Location
Brazil - Goiânia
TFS1.1, Tibia 10.41
There's a way to i make a same object allow/restrict movement to different directions?


I've been trying make a fence allow me move through it, only from directions i want:

a.jpg

Thats just a example, won't solve my problem just put a flag 'unpassable', cause it will restrict movement trough the object in any direction.

https://imgur.com/yqv8jVG
 
Last edited:
I got help from @forgee , the script is working , i'm only able to walk in the designed directions, but the monsters are trying to walk in the item :(


https://imgur.com/7YT5y8S

Here the item in the editor: http://1.ii.gl/o7i6hACRK.png


Block pathfinder dont work with monsters? When i click to walk my char walk around , avoiding the item.

TFS1.1, Tibia 10.41
Here the script:
Code:
local allow = {
    [NORTH] = {106}, -- allow walking from north
    [EAST] = {106, 107}, -- allow walking from east
    [SOUTH] = {}, -- allow walking from south
    [WEST] = {106} -- allow walking from west
}


function getDirection(pos, posEx)
    if pos.x < posEx.x then
        if pos.y < posEx.y then
            return SHOUTHEAST
        elseif pos.y > posEx.y then
            return NORTHEAST
        else
            return EAST
        end
    elseif pos.x > posEx.x then
        if pos.y < posEx.y then
            return SHOUTHWEST
        elseif pos.y > posEx.y then
            return NORTHWEST
        else
            return WEST
        end
    elseif pos.y > posEx.y then
        if pos.x < posEx.x then
            return NORTHEAST
        elseif pos.x > posEx.x then
            return NORTHWEST
        else
            return NORTH
        end
    elseif pos.y < posEx.y then
        if pos.x > posEx.x then
            return SHOUTHWEST
        elseif pos.x < posEx.x then
            return SOUTHEAST
        else
            return SOUTH
        end
    end
end

function onStepIn(creature, item, position, fromPosition)
    local dir = getDirection(position, fromPosition)
    if not table.find(allow[dir], item.itemid) then
        creature:teleportTo(fromPosition, false)
    end
end
 
Last edited:
Edit: Yes, its TFS 1.1, 10.41.

I dont got, what you tried show me in Printer script, as there is a GOD command to walk trough everything, different from what i've been trying (allow/restrict walk trough items from determined directions) :\

Well i got it already as you can see here: https://imgur.com/7YT5y8S
I only can pass trough the item from < \/ > when i try walk /\ it not possible.

But the problem is make the monster recognize that he can walk < \/ > and not /\
 
Last edited:
Edit: Yes, its TFS 1.1, 10.41.

I dont got, what you tried show me in Printer script, as there is a GOD command to walk trough everything, different from what i've been trying (allow/restrict walk trough items from determined directions) :\

Well i got it already as you can see here: https://imgur.com/7YT5y8S
I only can pass trough the item from < \/ > when i try walk /\ it not possible.

But the problem is make the monster recognize that he can walk < \/ > and not /\

Oh, I'm sorry bro... As far as I know, there isn't anything you can do for that without a source edit. I could be mistaken, maybe you can use onThink. I don't know for sure, but for him to be able to recognize that he can walk one way and not another, I imagine would take a lot of code in lua anyways. I would think for him to even recognize that he can walk there the object first must not block path, which means you have to change the .dat, then use lua script to block instead of vice-a-versa as you have done here....
 
I made this for player.lua
Works 100% for players maybe you can use it for the monsters, by changing Player to Monster?
It's just an idea :)
Code:
function Player:onMove(allow, fromPosition, position)
    if allow then
        self:teleportTo(position, true)
        return true
    else
        self:teleportTo(fromPosition, false)
        return false
    end
end
Code:
function onStepIn(cid, item, position, fromPosition)
    Player(cid):onMove(false, fromPosition, position)
end
 
He has the code working how he wants it to, it's the monsters aren't behaving as if they know they can go in one way but not the other, rather they still treat the barrier as if it's a barrier no matter which side they are on.
 
What if you edit your .dat file and set the fence to passable then use the script above to deny movements?
I would think for him to even recognize that he can walk there the object first must not block path, which means you have to change the .dat, then use lua script to block instead of vice-a-versa as you have done here....
 
Actually the fence are with the flag passable in the .dat, i only can pass trough it by East and West, if i try pass trough it by any other direction (diagonal too) it dont let pass :)

The problem is if i logout on top of the fence my server crash (wont work just make that place not able to logout, if player close the client there, will crash same way)

If i keep loging in/out on top of the fence thats what happens:

a.pngc.jpg b.jpg

It makes a image clone of my character "Testes" and if i walk or logout, client crash, and as you can see it gives no error.



Actual script:
Code:
local allow = {
    [NORTH] = {106, 109}, -- allow walking from north
    [EAST] = {106, 109}, -- allow walking from east
    [SOUTH] = {}, -- allow walking from south
    [WEST] = {106, 109}, -- allow walking from west
    [SOUTHEAST] = {}, -- allow walking from southeast
    [NORTHEAST] = {106, 109}, -- allow walking from northeast
    [SOUTHWEST] = {}, -- allow walking from southwest
    [NORTHWEST] = {106, 109}, -- allow walking from northwest
}

local allowOut = {
    [106] = {EAST, WEST, SOUTH, SOUTHEAST, SOUTHWEST}, -- allow walkout to
    [109] = {EAST, WEST, SOUTH, SOUTHEAST, SOUTHWEST}, -- allow walkout to
}

function getDirection(pos, posEx)
    if pos.x < posEx.x then
        if pos.y < posEx.y then
            return SOUTHEAST
        elseif pos.y > posEx.y then
            return NORTHEAST
        else
            return EAST
        end
    elseif pos.x > posEx.x then
        if pos.y < posEx.y then
            return SOUTHWEST
        elseif pos.y > posEx.y then
            return NORTHWEST
        else
            return WEST
        end
    elseif pos.y > posEx.y then
        if pos.x < posEx.x then
            return NORTHEAST
        elseif pos.x > posEx.x then
            return NORTHWEST
        else
            return NORTH
        end
    elseif pos.y < posEx.y then
        if pos.x > posEx.x then
            return SOUTHWEST
        elseif pos.x < posEx.x then
            return SOUTHEAST
        else
            return SOUTH
        end
    end
end

function onStepIn(creature, item, position, fromPosition)
    if position.x == fromPosition.x and position.y == fromPosition.y then
        return true
    end
    local dir = getDirection(position, fromPosition)
    if not table.find(allow[dir], item.itemid) then
        creature:teleportTo(fromPosition, false)
        creature:sendCancelMessage(RETURNVALUE_NOTENOUGHROOM)
    end
    return true
end

function onStepOut(creature, item, position, fromPosition)
    position = creature:getPosition()
    if position.x == fromPosition.x and position.y == fromPosition.y then
        return true
    end
    local dir = getDirection(position, fromPosition)
    if not table.find(allowOut[item.itemid], dir) then
        creature:teleportTo(fromPosition, false)
        creature:sendCancelMessage(RETURNVALUE_NOTENOUGHROOM)
    end
    return true
end


Fence in dat editor:
a.jpg
 
Last edited:
Requires source edit, There are a few ways to do it.

I planned on adding this functionality into my 0.3.6 server, but I haven't gotten around to it.

Basically, when the server does "getPathMatching" when it is checking each node it will need to check if it is possible to get to that node from the previous node.

It is a bit complicated. I plan to do it for my server but i'm running tfs 0.3.6 because I am one of those old men stuck in the past, too used to his old ways to upgrade.
 
He told you, you need a source edit. If you can't do the source edit yourself, then please start a new thread in support section with prefix C++ and make sure to include your server version. Request in the new thread the source edit you need done. Please be specific as well...
 
You don't need a source edit, gosh don't you people have any imagination, since this isn't the request board I don't have to post the code, so I will let you think about how this could be done..
 
Last edited:
In onStepIn add:
print(string.format('%i %i %i', fromPosition.x, fromPosition.y, fromPosition.z))
before:
creature:teleportTo(fromPosition, false)

and see what it prints if you login on a fence.
If you login there fromPosition will not store a proper value.
 
Back
Top