Moody
Member
- Joined
- Feb 8, 2020
- Messages
- 60
- Reaction score
- 5
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
and this my core getclose function
this my script luaLua 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>
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()
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