• 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 /a don't work

Kemixe

New Member
Joined
Jul 18, 2014
Messages
4
Reaction score
0
Distro:
Code:
Lua Script Error: [TalkAction Interface]
data/talkactions/scripts/teleport_ntiles.lua:onSay
data/global.lua:339: attempt to call method 'getTile' (a nil value)
stack traceback:
        [C]: in function 'getTile'
        data/global.lua:339: in function 'getClosestFreePosition'
        data/talkactions/scripts/teleport_ntiles.lua:15: in function <data/talka
ctions/scripts/teleport_ntiles.lua:1>

Lua:
Code:
<talkaction words="/a" separator=" " script="teleport_ntiles.lua" />
Code:
function onSay(cid, words, param)
    local player = Player(cid)
    if not player:getGroup():getAccess() then
        return true
    end

    local steps = tonumber(param)
    if not steps then
        return false
    end

    local position = player:getPosition()
    position:getNextPosition(player:getDirection(), steps)

    position = player:getClosestFreePosition(position, false)
    if position.x == 0 then
        player:sendCancelMessage("You cannot teleport there.")
        return false
    end

    player:teleportTo(position)
    return false
end

Global.lua
Code:
function Player.getClosestFreePosition(self, position, extended)
    if self:getAccountType() >= ACCOUNT_TYPE_GOD then
        return position
    end
    return Creature.getClosestFreePosition(self, position, extended)
end

function Creature.getClosestFreePosition(self, position, extended)
    local usePosition = Position(position)
    local tiles = { usePosition:getTile() }
    local length = extended and 2 or 1
   
    local tile
    for y = -length, length do
        for x = -length, length do
            if x ~= 0 or y ~= 0 then
                usePosition.x = position.x + x
                usePosition.y = position.y + y
               
                tile = usePosition:getTile()
                if tile then
                    tiles[#tiles + 1] = tile
                end
            end
        end
    end
   
    for i = 1, #tiles do
        tile = tiles[i]
        if tile:getCreatureCount() == 0 and not tile:hasProperty(CONST_PROP_BLOCKINGANDNOTMOVEABLE) then
            return tile:getPosition()
        end
    end
    return Position()
end

Help me plz!
 
Back
Top