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

Lua GET CLOSEST FREE TILE

Unvincible

Member
Joined
Sep 1, 2015
Messages
44
Reaction score
10
Hello,

My /goto teleport to closest free tile, players or monster. working perfect, but if i use ghost mode im teleporting to SAME SQM as player. sometimes i debug my players with command. can anyone help me?

Code:
function onSay(cid, words, param, channel)
    if(param == '') then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Command requires param.")
        return true
    end

    local creature = getCreatureByName(param)
    local player = getPlayerByNameWildcard(param)
    local waypoint = getWaypointPosition(param)
    local tile = string.explode(param, ",")
    local pos = {x = 0, y = 0, z = 0}

    if(player ~= nil and (not isPlayerGhost(player) or getPlayerGhostAccess(player) <= getPlayerGhostAccess(cid))) then
        pos = getCreaturePosition(player)
    elseif(creature ~= nil and (not isPlayer(creature) or (not isPlayerGhost(creature) or getPlayerGhostAccess(creature) <= getPlayerGhostAccess(cid)))) then
        pos = getCreaturePosition(creature)


    elseif(type(waypoint) == 'table' and waypoint.x ~= 0 and waypoint.y ~= 0) then
        pos = waypoint
    elseif(tile[2] and tile[3]) then
        pos = {x = tile[1], y = tile[2], z = tile[3]}
    else
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Invalid param specified.")
        return true
    end

    if(not pos or isInArray({pos.x, pos.y}, 0)) then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Destination not reachable.")
        return true
    end

    pos = getClosestFreeTile(cid, pos, true, false)
    if(not pos or isInArray({pos.x, pos.y}, 0)) then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Cannot perform action.")
        return true
    end

    local tmp = getCreaturePosition(cid)
    if(doTeleportThing(cid, pos, true) and not isPlayerGhost(cid)) then
        doSendMagicEffect(tmp, CONST_ME_POFF)
        doSendMagicEffect(pos, CONST_ME_TELEPORT)
    end

    return true
end
 
Well on TFS 1.x
https://github.com/otland/forgottenserver/blob/master/data/lib/core/player.lua#L25

Other versions, pretty sure they are hardcoded in the sources and i have no desire to look through older sources. Try something like this

Code:
function onSay(cid, words, param, channel)
    local target = getCreatureByName(param)
    if target == nil then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Creature not found.")
        return true
    end

    local position = getClosestFreeTile(cid, getCreaturePosition(target), true, false)
    if position.x == 0 then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Destination not reachable.")
        return true
    end

    if isPlayerGhost(cid) then
        position.x = position.x + 1
    else
        doSendMagicEffect(getCreaturePosition(cid), CONST_ME_POFF)
        doSendMagicEffect(position, CONST_ME_TELEPORT)
    end

    doTeleportThing(position)
    return true
end
 
Back
Top