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

Spell Monster spell, teleport to player.

Nekiro

Legendary OT User
TFS Developer
Joined
Sep 7, 2015
Messages
2,684
Solutions
127
Reaction score
2,130
I wrote this for my server, but I won't use it so I thought I'm gonna share it here.

What this spell do? It teleport monster to player also it's checking for free tile near player if there is not free tile he will not teleport.

Probably can be written better, but yeah that's what I could script :D

If you have any suggestions to the code share them.

Code:
local playerPositions = {}

function onCastSpell(cid, variant)
    local monster = Creature(cid)
   
    local closeSpec = Game.getSpectators(monster:getPosition(), false, true, 2, 2, 2, 2)
    for i = 1, #closeSpec do
        if closeSpec[i] ~= nil then
            return false
        end
    end
   
    local specs = Game.getSpectators(Position(monster:getPosition()), false, true, 20, 20, 20, 20)
    for i = 1, #specs do
        local spectator = specs[i]
        playerPositions[#playerPositions + 1] = spectator:getPosition()
    end
   
    local randomPos = playerPositions[math.random(#playerPositions)]
    local freePos = getFreeTile(randomPos)
   
    if freePos then
        monster:getPosition():sendMagicEffect(CONST_ME_POFF)
        monster:teleportTo(freePos)
        monster:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
        monster:say('BUU!!', TALKTYPE_MONSTER_SAY)
    end
   
    return false
end

function getFreeTile(positions)
    local checkTiles = {
        -- 1, 2, 3
        -- 4, 0, 5 -- 0 is player
        -- 6, 7, 8
        Position(positions.x + 1, positions.y, positions.z), -- 5
        Position(positions.x - 1, positions.y, positions.z), -- 4
        Position(positions.x, positions.y + 1, positions.z), -- 7
        Position(positions.x, positions.y - 1, positions.z), -- 2
        Position(positions.x + 1, positions.y - 1, positions.z), -- 3
        Position(positions.x + 1, positions.y + 1, positions.z), -- 8
        Position(positions.x - 1, positions.y - 1, positions.z), -- 1
        Position(positions.x - 1, positions.y + 1, positions.z) -- 6
    }
   
    local freePosition
    for i = 1, #checkTiles do
        if Tile(checkTiles[i]):getGround() and not Tile(checkTiles[i]):getItemById(1387) and not Tile(checkTiles[i]):getItemById(5070) then
            freePosition = checkTiles[i]
            return freePosition
        else
            return false
        end
    end
end
 
Last edited by a moderator:
Anyone has any idea why it jumps to PZ zone if there is a player? It jumped from outside temple to inside temple because of god char in area and got stuck there xD
1667198282944.png
 
Anyone has any idea why it jumps to PZ zone if there is a player? It jumped from outside temple to inside temple because of god char in area and got stuck there xD
View attachment 71448

You should add some PZ check in this line:
if Tile(checkTiles):getGround() and not Tile(checkTiles):getItemById(1387) and not Tile(checkTiles):getItemById(5070) then
 
Back
Top