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

TFS 1.X+ My server freeze when create item

richardestro

New Member
Joined
Oct 23, 2023
Messages
18
Reaction score
3
Hello!
Latelly I having a problem when I create any item that cannot be carried (doors, floors, teleports, etc..) with the talkaction "/i".
Using TFS 1.3.

I was reading this thread: Solved - freeze when create item (https://otland.net/threads/freeze-when-create-item.248145/)

The guy had the same problem, but tried that and didn't worked.

This is my LUA of "/i"
LUA:
local talk = TalkAction("/i")

function talk.onSay(player, words, param)

local invalidIds = {
    1, 2, 3, 4, 5, 6, 7, 10, 11, 13, 14, 15, 19, 21, 26, 27, 28, 35, 43
}

    if not player:getGroup():getAccess() or player:getAccountType() < ACCOUNT_TYPE_GOD then
        return true
    end

    local split = param:split(",")

    local itemType = ItemType(split[1])
    if itemType:getId() == 0 then
        itemType = ItemType(tonumber(split[1]))
        if not tonumber(split[1]) or itemType:getId() == 0 then
            player:sendCancelMessage("There is no item with that id or name.")
            return false
        end
    end

    if table.contains(invalidIds, itemType:getId()) then
        return false
    end

    local count = tonumber(split[2])
    if count then
        if itemType:isStackable() then
            count = math.min(10000, math.max(1, count))
        elseif not itemType:isFluidContainer() then
            count = math.min(100, math.max(1, count))
        else
            count = math.max(0, count)
        end
    else
        if not itemType:isFluidContainer() then
            count = 1
        else
            count = 0
        end
    end

    local result = player:addItem(itemType:getId(), count)
    if result then
        if not itemType:isStackable() then
            if type(result) == "table" then
                for _, item in ipairs(result) do
                    item:decay()
                end
            else
                result:decay()
            end
        end
        player:getPosition():sendMagicEffect(CONST_ME_MAGIC_GREEN)
    end
    return false
end

talk:separator(" ")
talk:register()

If more info is required, ill be alert on answers
Thank you all in advance :D
 
LUA:
local talk = TalkAction("/i")

function talk.onSay(player, words, param)

    local invalidIds = {
        1, 2, 3, 4, 5, 6, 7, 10, 11, 13, 14, 15, 19, 21, 26, 27, 28, 35, 43
    }

    if not player:getGroup():getAccess() or player:getAccountType() < ACCOUNT_TYPE_GOD then
        return true
    end

    local split = param:split(",")

    local itemType = ItemType(split[1])
    if itemType:getId() == 0 then
        itemType = ItemType(tonumber(split[1]))
        if not tonumber(split[1]) or itemType:getId() == 0 then
            player:sendCancelMessage("There is no item with that id or name.")
            return false
        end
    end

    if table.contains(invalidIds, itemType:getId()) then
        return false
    end

    local count = tonumber(split[2])
    if count then
        if itemType:isStackable() then
            count = math.min(10000, math.max(1, count))
        elseif not itemType:isFluidContainer() then
            count = math.min(100, math.max(1, count))
        else
            count = math.max(0, count)
        end
    else
        if not itemType:isFluidContainer() then
            count = 1
        else
            count = 0
        end
    end


    if itemType:isMovable() then
        local result = player:addItem(itemType:getId(), count)
        if result then
            if not itemType:isStackable() then
                if type(result) == "table" then
                    for _, item in ipairs(result) do
                        item:decay()
                    end
                else
                    result:decay()
                end
            end
            player:getPosition():sendMagicEffect(CONST_ME_MAGIC_GREEN)
        end
    else
        local tile = Tile(player:getPosition())
        if tile then
            local newItem = Game.createItem(itemType:getId(), count, player:getPosition())
            if newItem then
                player:getPosition():sendMagicEffect(CONST_ME_MAGIC_GREEN)
            else
                player:sendCancelMessage("Failed to create the item.")
            end
        else
            player:sendCancelMessage("Invalid tile to place the item.")
        end
    end

    return false
end

talk:separator(" ")
talk:register()
 
LUA:
local invalidIds = {
    1, 2, 3, 4, 5, 6, 7, 10, 11, 13, 14, 15, 19, 21, 26, 27, 28, 35, 43
}

function onSay(player, words, param)
    if not player:getGroup():getAccess() then
        return true
    end

    if player:getAccountType() < ACCOUNT_TYPE_GOD then
        return false
    end

    local split = param:splitTrimmed(",")

    local itemType = ItemType(split[1])
    if itemType:getId() == 0 then
        itemType = ItemType(tonumber(split[1]))
        if not tonumber(split[1]) or itemType:getId() == 0 then
            player:sendCancelMessage("There is no item with that id or name.")
            return false
        end
    end

    if table.contains(invalidIds, itemType:getId()) then
        return false
    end

    local keyNumber = 0
    local count = tonumber(split[2])
    if count then
        if itemType:isStackable() then
            count = math.min(10000, math.max(1, count))
        elseif itemType:isKey() then
            keyNumber = count
            count = 1
        elseif not itemType:isFluidContainer() then
            count = math.min(100, math.max(1, count))
        else
            count = math.max(0, count)
        end
    else
        if not itemType:isFluidContainer() then
            count = 1
        else
            count = 0
        end
    end

    local result = player:addItem(itemType:getId(), count)
    if result then
        if not itemType:isStackable() then
            if type(result) == "table" then
                for _, item in ipairs(result) do
                    item:decay()
                end
            else
                if itemType:isKey() then
                    result:setAttribute(ITEM_ATTRIBUTE_ACTIONID, keyNumber)
                end
                result:decay()
            end
        end
        player:getPosition():sendMagicEffect(CONST_ME_MAGIC_GREEN)
    end
    return false
end
 
LUA:
local talk = TalkAction("/i")

function talk.onSay(player, words, param)

    local invalidIds = {
        1, 2, 3, 4, 5, 6, 7, 10, 11, 13, 14, 15, 19, 21, 26, 27, 28, 35, 43
    }

    if not player:getGroup():getAccess() or player:getAccountType() < ACCOUNT_TYPE_GOD then
        return true
    end

    local split = param:split(",")

    local itemType = ItemType(split[1])
    if itemType:getId() == 0 then
        itemType = ItemType(tonumber(split[1]))
        if not tonumber(split[1]) or itemType:getId() == 0 then
            player:sendCancelMessage("There is no item with that id or name.")
            return false
        end
    end

    if table.contains(invalidIds, itemType:getId()) then
        return false
    end

    local count = tonumber(split[2])
    if count then
        if itemType:isStackable() then
            count = math.min(10000, math.max(1, count))
        elseif not itemType:isFluidContainer() then
            count = math.min(100, math.max(1, count))
        else
            count = math.max(0, count)
        end
    else
        if not itemType:isFluidContainer() then
            count = 1
        else
            count = 0
        end
    end


    if itemType:isMovable() then
        local result = player:addItem(itemType:getId(), count)
        if result then
            if not itemType:isStackable() then
                if type(result) == "table" then
                    for _, item in ipairs(result) do
                        item:decay()
                    end
                else
                    result:decay()
                end
            end
            player:getPosition():sendMagicEffect(CONST_ME_MAGIC_GREEN)
        end
    else
        local tile = Tile(player:getPosition())
        if tile then
            local newItem = Game.createItem(itemType:getId(), count, player:getPosition())
            if newItem then
                player:getPosition():sendMagicEffect(CONST_ME_MAGIC_GREEN)
            else
                player:sendCancelMessage("Failed to create the item.")
            end
        else
            player:sendCancelMessage("Invalid tile to place the item.")
        end
    end

    return false
end

talk:separator(" ")
talk:register()
It worked well.

Just having the same problem with items that cannot be carried but can be moved (house's decorations, for example)

But for any other items, theres no problem, thanks mate :)
 

Similar threads

  • Question Question
RevScripts droplist show
Replies
2
Views
144
Back
Top