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

RevScripts push creature tfs 1.3 revscripts

Moody

New Member
Joined
Feb 8, 2020
Messages
46
Reaction score
3
i have one bug in command /c revscripts i don't know when happen i see error random in tfs window but this what it say
Lua Script Error: [Scripts Interface]
forgottenserver/data/scripts/talkactions/god/push creature.lua:callback
data/lib/core/creature.lua:22: attempt to index local 'tile' (a nil value)
stack traceback:
[C]: in function '__index'
data/lib/core/creature.lua:22: in function 'getClosestFreePosition'
...tenserver/data/scripts/talkactions/god/push creature.lua:20: in function <...tenserver/data/scripts/talkactions/god/push creature.lua:3>
this my script lua
Lua:
local talk = TalkAction("/c")

function talk.onSay(player, words, param)
    if not player:getGroup():getAccess() or player:getAccountType() < ACCOUNT_TYPE_GOD then
        return true
    end

    if param == "" then
        player:sendCancelMessage("Command param required.")
        return false
    end

    local creature = Creature(param)
    if not creature then
        player:sendCancelMessage("A creature with that name could not be found.")
        return false
    end

    local oldPosition = creature:getPosition()
    local newPosition = creature:getClosestFreePosition(player:getPosition(), false)
    if newPosition.x == 0 then
        player:sendCancelMessage("You can not teleport " .. creature:getName() .. ".")
        return false
    elseif creature:teleportTo(newPosition) then
        if not creature:isInGhostMode() then
            oldPosition:sendMagicEffect(CONST_ME_POFF)
            newPosition:sendMagicEffect(CONST_ME_TELEPORT)
        end
    end
    return false
end

talk:separator(" ")
talk:register()
and this my core getclose function
Lua:
function Creature.getClosestFreePosition(self, position, maxRadius, mustBeReachable)
    maxRadius = maxRadius or 1

    -- backward compatability (extended)
    if maxRadius == true then
        maxRadius = 2
    end

    local checkPosition = Position(position)
    for radius = 0, maxRadius do
        checkPosition.x = checkPosition.x - math.min(1, radius)
        checkPosition.y = checkPosition.y + math.min(1, radius)

        local total = math.max(1, radius * 8)
        for i = 1, total do
            if radius > 0 then
                local direction = math.floor((i - 1) / (radius * 2))
                checkPosition:getNextPosition(direction)
            end

            local tile = Tile(checkPosition)
            if tile:getCreatureCount() == 0 and not tile:hasProperty(CONST_PROP_IMMOVABLEBLOCKSOLID) and
                (not mustBeReachable or self:getPathTo(checkPosition)) then
                return checkPosition
            end
        end
    end
    return Position()
end
 
Solution
change for this getclose function
Lua:
function Creature.getClosestFreePosition(self, position, maxRadius, mustBeReachable)
    maxRadius = maxRadius or 1

    -- backward compatability (extended)
    if maxRadius == true then
        maxRadius = 2
    end

    local checkPosition = Position(position)
    for radius = 0, maxRadius do
        checkPosition.x = checkPosition.x - math.min(1, radius)
        checkPosition.y = checkPosition.y + math.min(1, radius)

        local total = math.max(1, radius * 8)
        for i = 1, total do
            if radius > 0 then
                local direction = math.floor((i - 1) / (radius * 2))
                checkPosition:getNextPosition(direction)
            end

            local tile =...

roriscrave

Advanced OT User
Joined
Dec 7, 2011
Messages
1,095
Solutions
33
Reaction score
182
change for this getclose function
Lua:
function Creature.getClosestFreePosition(self, position, maxRadius, mustBeReachable)
    maxRadius = maxRadius or 1

    -- backward compatability (extended)
    if maxRadius == true then
        maxRadius = 2
    end

    local checkPosition = Position(position)
    for radius = 0, maxRadius do
        checkPosition.x = checkPosition.x - math.min(1, radius)
        checkPosition.y = checkPosition.y + math.min(1, radius)

        local total = math.max(1, radius * 8)
        for i = 1, total do
            if radius > 0 then
                local direction = math.floor((i - 1) / (radius * 2))
                checkPosition:getNextPosition(direction)
            end

            local tile = Tile(checkPosition)
            if tile and tile:getCreatureCount() == 0 and not tile:hasProperty(CONST_PROP_IMMOVABLEBLOCKSOLID) and
                (not mustBeReachable or self:getPathTo(checkPosition)) then
                return checkPosition
            end
        end
    end
    return Position()
end
 
Solution
OP
OP
M

Moody

New Member
Joined
Feb 8, 2020
Messages
46
Reaction score
3
cant test or be sure script work or no work because i no know when and why error come on console. i go add this and see after 3 or 4 day if error come in console i back here
 
Top