• 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.X+ getDirection() of target - TFS1.3

GOD Half

Member
Joined
May 9, 2010
Messages
179
Reaction score
15
Hi guys, how do I print the direction the target is looking?
The model below prints the direction the player is looking, but I need the direction that the target of the player is looking to be printed:
Lua:
function onThink(interval, lastExecution, thinkInterval)
    for _, player in ipairs(Game.getPlayers()) do
        local dirPlayer = player:getDirection() -- or getPlayerLookDir(player)        -- 0: n | 1: e | 2: s | 3: w
        print("Your direction: "..dirPlayer)
    end
return true
end
I'm trying but from error below:
Lua:
function onThink(interval, lastExecution, thinkInterval)
    for _, player in ipairs(Game.getPlayers()) do
        local target = getCreatureTarget(player)
        if isPlayer(target) or isMonster(target) then
            local dirTarget = target:getDirection() -- ERROR
            print("Target direction: "..dirTarget)
        end
    end
return true
end
 
Solution
Lua:
function onThink(interval, lastExecution, thinkInterval)
    for _, player in ipairs(Game.getPlayers()) do
        local target = player:getTarget()
        if target then
            if target:isPlayer() or target:isMonster() then
                local dirTarget = target:getDirection()
                print("Target direction: "..dirTarget)
            end
        end
    end
    return true
end
Lua:
function onThink(interval, lastExecution, thinkInterval)
    for _, player in ipairs(Game.getPlayers()) do
        local target = player:getTarget()
        if target then
            if target:isPlayer() or target:isMonster() then
                local dirTarget = target:getDirection()
                print("Target direction: "..dirTarget)
            end
        end
    end
    return true
end
 
Solution
Lua:
function onThink(interval, lastExecution, thinkInterval)
    for _, player in ipairs(Game.getPlayers()) do
        local target = player:getTarget()
        if target then
            if target:isPlayer() or target:isMonster() then
                local dirTarget = target:getDirection()
                print("Target direction: "..dirTarget)
            end
        end
    end
    return true
end

Thank you!
 
Back
Top