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

Solved Spell crashing server [TFS 1.2]

Aeronx

Intermediate OT User
Joined
Dec 17, 2015
Messages
735
Solutions
9
Reaction score
119
Hello guys! im testing new things and i've created simple script, but for some reason I dont know it crashes the server.

Code:
function onCastSpell(creature, var)

   local pos = creature:getPosition()

   local item = Game.createItem(2579, 1, pos)
    if item then
        item:setActionId(8764)
        local items = Tile(pos):getItems()
        
        for i = 1, #items do
            addEvent(function() items[i]:remove() end, 10000)
        end
    end
   
    return true
end

Any help would be welcome!

Thanks for your time.
 
Solution
You should never pull stunts like that with items. In this scenario, it most likely crashes the server due to one (or more) item(s) are no longer available in the game.

I have prepared a snippet that should take care of the issue you're currently facing:
Lua:
function onCastSpell(creature, var)
    local position = creature:getPosition()
    local item = Game.createItem(2579, 1, position)
    if not item then
        return false
    end

    item:setActionId(8764)

    addEvent(function(position)
        local tile = Tile(position)
        if not tile then
            return
        end

        local items = tile:getItems()
        if items then
            for _, item in ipairs(items) do
                item:remove()...
I think problem is item is created first and then item is created with actionid.
item:setActionId(8764)

correct me if i'm wrong.
 
Nah, the problem is related to this part:
Code:
  local items = Tile(pos):getItems()
      
        for i = 1, #items do
            addEvent(function() items[i]:remove() end, 10000)
        end
 
You should never pull stunts like that with items. In this scenario, it most likely crashes the server due to one (or more) item(s) are no longer available in the game.

I have prepared a snippet that should take care of the issue you're currently facing:
Lua:
function onCastSpell(creature, var)
    local position = creature:getPosition()
    local item = Game.createItem(2579, 1, position)
    if not item then
        return false
    end

    item:setActionId(8764)

    addEvent(function(position)
        local tile = Tile(position)
        if not tile then
            return
        end

        local items = tile:getItems()
        if items then
            for _, item in ipairs(items) do
                item:remove()
            end
        end
    end, 10000, position)

    return true
end
 
Solution
Ohh..! I see it now! I knew it was something related to the item missing on the tile, but didnt really know how to solve the issue.

Thank you very much @Ninja !
 
Back
Top