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

[REQUEST] Path Finder - TFS 1.0

lord vortexx

New Member
Joined
Dec 14, 2008
Messages
92
Reaction score
3
I'm trying to develop a Path Finder for some monsters but I'm not having much success, will be that someone help me?

I'm putting a picture to illustrate:



I know that natively they already do that to get some target, but I can not reproduce this in LUA.
Needed some way that returns a table (array) with all the free paths until that particular Position.


Many Thanks
 
Code:
creature:getPathTo(pos[, minTargetDist = 0[, maxTargetDist = 1[, fullPathSearch = true[, clearSight = true[, maxSearchDist = 0]]]]])
 
Sorry but i have not tried it out:

Code:
local finalPos = Position(100, 100, 7)
creature:getPathTo(finalPos, 0, 1, true, true, 100)
 
It returns an array of directions. Use an for loop and Position.getNextPosition together with creature:teleportTo.
 
Answering my own question, here's what I did and this functional

Code:
function moveCreaturewalk(cid, directs, index)
    if directs[index] ~= nil then
        doMoveCreature(cid, directs[index])
        index = index+1
        addEvent(moveCreaturewalk, 1000, cid, directs, index)
    end
end

    local pos = Position(89, 120, 7)
    local retorno = monster:getPathTo( pos, 0, 1, true, true, 100 )
    if retorno ~= nil then
        moveCreaturewalk(monster, retorno, 1)
    end
 
GOD DAMIT!!
i wrote keyword "path" to luascripts.cpp
and i did not find creature:getPathTo
...
So past 2 hours i have been making lot of functions to global.lua
Finally my script was ready.
I ran into problem.
monster always started looking path from "right" side of compass, he made huge circles, instead of just passing object from left xD

Then i was thinking i need to dynamical tables where are list of all possible paths and final return will be the table what holds the least amount of positions.
I was like, "oboy, this is going to generate ~ 100 tables each time i use this function." and just incase checked forum, has anyone else done it before.

I find this thread and you guys use creature:getPathTo function.
i recheck luascripts.cpp and now i find it... Good job me, that was a nice waste of time making global.lua scripts..

EDIT: nvm it does not return the positions, but some useless numbers.
Seems i still gotta make the huge grazy table system to get the path positions.

EDIT2: finished custom path finding system, causes no lags. Function returns positions what is the monster using from point A to B.
Also extra paramaters can be used like: table(holds items what cant be steppe on), item attribute(can move, can pass, etc).
 
Last edited:
Back
Top