• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

Lua Push target spell not push into PZ [TFS 1.2]

Siegh

Thronar Developer
Joined
Mar 12, 2011
Messages
1,278
Solutions
1
Reaction score
635
Location
Brazil
Hello!

I'm implementing this function to a couple spells I've got but I'm facing a problem with monsters being pushed inside PZ! I can't find a way to check if a tile is pz or not, I did search considerably.

Is there a practical way to simply check whether a targeted tile is a PZ one?

LUA:
function onTargetCreature1(creature, target)                                       
    local tPos = target:getPosition()
    if pos.x > tPos.x and pos.y > tPos.y then
        pushX = -1
        pushY = -1
    elseif pos.x > tPos.x and pos.y == tPos.y then
        pushX = -1
        pushY = 0
    elseif pos.x == tPos.x and pos.y > tPos.y then
        pushX = 0
        pushY = -1
    elseif pos.x > tPos.x and pos.y < tPos.y then
        pushX = -1
        pushY = 1
    elseif pos.x < tPos.x and pos.y < tPos.y then
        pushX = 1
        pushY = 1
    elseif pos.x < tPos.x and pos.y == tPos.y then
        pushX = 1
        pushY = 0
    elseif pos.x == tPos.x and pos.y < tPos.y then
        pushX = 0
        pushY = 1
    elseif pos.x < tPos.x and pos.y > tPos.y then
        pushX = 1
        pushY = -1
    end
    tPos.x = tPos.x + pushX
    tPos.y = tPos.y + pushY
    local isWalkable = function (position)
        local tile = Tile(position)
        if not tile then
            return false
        end
        local ground = tile:getGround()
        if not ground or ground:hasProperty(CONST_PROP_BLOCKSOLID) then
            return false
        end
        local items = tile:getItems()
        for i = 1, tile:getItemCount() do
            local item = items[i]
            local itemType = item:getType()
            if itemType:getType() ~= ITEM_TYPE_MAGICFIELD and not itemType:isMovable() and item:hasProperty(CONST_PROP_BLOCKSOLID) then
                return false
            end
        end
        return true
    end
    if isWalkable(tPos) and target:getSpeed() ~= 0 then
        target:teleportTo(tPos, 1)
    end
    return true
end
 
local isWalkable = function (position)
local tile = Tile(position)
if not tile then
return false
end

-- Block PZ tiles
if tile:hasFlag(TILESTATE_PROTECTIONZONE) then
return false
end

local ground = tile:getGround()
if not ground or ground:hasProperty(CONST_PROP_BLOCKSOLID) then
return false
end

local items = tile:getItems()
for i = 1, tile:getItemCount() do
local item = items
local itemType = item:getType()
if itemType:getType() ~= ITEM_TYPE_MAGICFIELD
and not itemType:isMovable()
and item:hasProperty(CONST_PROP_BLOCKSOLID) then
return false
end
end

return true
end
 
Back
Top