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

Tiles Spell Tfs 1.2

lazarus321

Member
Joined
May 8, 2017
Messages
222
Reaction score
23
Guys,

How would I make a spell to create an item around the player without it being inside pz area, walls, monsters, players or obstacles?

I created a script but it does not respect the conditions as I said.

C++:
function onCastSpell(creature, variant)
local player = Player(creature)

    local nivel = player:getLevel()
    local ml = player:getMagicLevel()
    -- if ml >= 1 and nivel >= 3 then
   
    local player = Player(creature)
    local target = player:getTarget()
    local alvo = target:getDirection()
    local alvopos = target:getPosition()
    local playerdir = player:getDirection()
    local playerpos = player:getPosition()
   
   
    local nortepos = Position(target:getPosition().x, target:getPosition().y - 1, target:getPosition().z)
    local nortepos2 = Position(target:getPosition().x + 1, target:getPosition().y - 1, target:getPosition().z)
   
    local lestepos = Position(target:getPosition().x + 1, target:getPosition().y, target:getPosition().z)
    local lestepos2 = Position(target:getPosition().x + 1, target:getPosition().y +1, target:getPosition().z)
   
    local sulpos = Position(target:getPosition().x, target:getPosition().y + 1, target:getPosition().z)
    local sulpos2 = Position(target:getPosition().x - 1, target:getPosition().y + 1, target:getPosition().z)
   
    local oestepos = Position(target:getPosition().x - 1, target:getPosition().y, target:getPosition().z)
    local oestepos2 = Position(target:getPosition().x - 1, target:getPosition().y - 1, target:getPosition().z)
   
   
    Game.createItem(6972, 1, sulpos2)
    Game.createItem(6972, 1, sulpos)
    Game.createItem(6972, 1, lestepos2)
    Game.createItem(6972, 1, lestepos)
    Game.createItem(6972, 1, nortepos2)
    Game.createItem(6972, 1, nortepos)
    Game.createItem(6972, 1, oestepos2)
    Game.createItem(6972, 1, oestepos)

    sulpos2:sendMagicEffect(69)
    sulpos:sendMagicEffect(69)
    lestepos2:sendMagicEffect(69)
    lestepos:sendMagicEffect(69)
    nortepos2:sendMagicEffect(69)
    nortepos:sendMagicEffect(69)
    oestepos2:sendMagicEffect(69)
    oestepos:sendMagicEffect(69)
   
            item1 = Tile(sulpos2):getItemById(6972)
            item2 = Tile(sulpos):getItemById(6972)
            item3 = Tile(lestepos2):getItemById(6972)
            item4 = Tile(lestepos):getItemById(6972)
            item5 = Tile(nortepos2):getItemById(6972)
            item6 = Tile(nortepos):getItemById(6972)
            item7 = Tile(oestepos2):getItemById(6972)
            item8 = Tile(oestepos):getItemById(6972)
           
            if item1 and item2 and item3 and item4 and item5 and item6 and item7 and item8 then
                addEvent(function() item1:remove() end, 5000)
                addEvent(function() item2:remove() end, 5000)
                addEvent(function() item3:remove() end, 5000)
                addEvent(function() item4:remove() end, 5000)
                addEvent(function() item5:remove() end, 5000)
                addEvent(function() item6:remove() end, 5000)
                addEvent(function() item7:remove() end, 5000)
                addEvent(function() item8:remove() end, 5000)
               
                addEvent(function() sulpos2:sendMagicEffect(69) end, 3500)
                addEvent(function() sulpos:sendMagicEffect(69) end, 3500)
                addEvent(function() lestepos2:sendMagicEffect(69) end, 3500)
                addEvent(function() lestepos:sendMagicEffect(69) end, 3500)
                addEvent(function() nortepos2:sendMagicEffect(69) end, 3500)
                addEvent(function() nortepos:sendMagicEffect(69) end, 3500)
                addEvent(function() oestepos2:sendMagicEffect(69) end, 3500)
                addEvent(function() oestepos:sendMagicEffect(69) end, 3500)
            end
    return true

end
 
Solution
Probably because the pos table is a reference + reused.
Use this instead:
LUA:
function onCastSpell(creature, variant)
    local basePosition = creature:getPosition()
    -- get offsets for each direction from the player
    for dir, offset in pairs(Position.directionOffset) do
        local pos = Position(basePosition.x + offset.x, basePosition.y + offset.y, basePosition.z)
        local tile = Tile(pos)
        if tile and tile:isWalkable() then
            local item = Game.createItem(6972, 1, pos)
            pos:sendMagicEffect(CONST_ME_INSECTS)
            -- remove items in the future
            addEvent(function()
                local item = tile:getItemById(6972)
                if item then
                    item:remove()...
Try this?
This code should be MUCH faster as well in terms of performance.
LUA:
function onCastSpell(creature, variant)
    local basePosition = creature:getPosition()
    local pos = Position(0, 0, basePosition.z)
    -- get offsets for each direction from the player
    for dir, offset in pairs(Position.directionOffset) do
        pos.x = basePosition.x + offset.x
        pos.y = basePosition.y + offset.y
        local tile = Tile(pos)
        if tile and tile:isWalkable() then
            local item = Game.createItem(6972, 1, pos)
            pos:sendMagicEffect(CONST_ME_INSECTS)
            -- remove items in the future
            addEvent(function()
                local item = tile:getItemById(6972)
                if item then
                    item:remove()
                end
            end, 5000)
            addEvent(Position.sendMagicEffect, 3500, pos, CONST_ME_INSECTS)
        end
    end
    return true
end
 
Last edited:
i got this error

C++:
Lua Script Error: [Spell Interface]
data/spells/scripts/attack/prisao_ossos.lua:onCastSpell
data/spells/scripts/attack/prisao_ossos.lua:6: attempt to index local 'offset' (a number value)
stack traceback:
        [C]: in function '__index'
        data/spells/scripts/attack/prisao_ossos.lua:6: in function <data/spells/scripts/attack/prisao_ossos.lua:1>
 
i got this error

C++:
Lua Script Error: [Spell Interface]
data/spells/scripts/attack/prisao_ossos.lua:onCastSpell
data/spells/scripts/attack/prisao_ossos.lua:6: attempt to index local 'offset' (a number value)
stack traceback:
        [C]: in function '__index'
        data/spells/scripts/attack/prisao_ossos.lua:6: in function <data/spells/scripts/attack/prisao_ossos.lua:1>
Edited my post, recopy it.
 
now got,

C++:
Lua Script Error: [Spell Interface]
data/spells/scripts/attack/prisao_ossos.lua:onCastSpell
data/spells/scripts/attack/prisao_ossos.lua:9: attempt to call method 'isWalkable' (a nil value)
stack traceback:
        [C]: in function 'isWalkable'
        data/spells/scripts/attack/prisao_ossos.lua:9: in function <data/spells/scripts/attack/prisao_ossos.lua:1>
 
now got,

C++:
Lua Script Error: [Spell Interface]
data/spells/scripts/attack/prisao_ossos.lua:onCastSpell
data/spells/scripts/attack/prisao_ossos.lua:9: attempt to call method 'isWalkable' (a nil value)
stack traceback:
        [C]: in function 'isWalkable'
        data/spells/scripts/attack/prisao_ossos.lua:9: in function <data/spells/scripts/attack/prisao_ossos.lua:1>
Add this inside of data/lib/core/tile.lua
LUA:
function Tile.isWalkable(self)
    local ground = self:getGround()
    if not ground or ground:hasProperty(CONST_PROP_BLOCKSOLID) then
        return false
    end

    local items = self:getItems()
    for i = 1, self: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
 
very good it work,

have 2 Details,

1 - the spell is to target

2 - this part addEvent(Position.sendMagicEffect, 3500, pos, CONST_ME_INSECTS) are only one wall with effect.

36682
 
Probably because the pos table is a reference + reused.
Use this instead:
LUA:
function onCastSpell(creature, variant)
    local basePosition = creature:getPosition()
    -- get offsets for each direction from the player
    for dir, offset in pairs(Position.directionOffset) do
        local pos = Position(basePosition.x + offset.x, basePosition.y + offset.y, basePosition.z)
        local tile = Tile(pos)
        if tile and tile:isWalkable() then
            local item = Game.createItem(6972, 1, pos)
            pos:sendMagicEffect(CONST_ME_INSECTS)
            -- remove items in the future
            addEvent(function()
                local item = tile:getItemById(6972)
                if item then
                    item:remove()
                end
            end, 5000)
            addEvent(Position.sendMagicEffect, 3500, pos, CONST_ME_INSECTS)
        end
    end
    return true
end
 
Solution
Back
Top