• 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 freeze when create item

silveralol

Advanced OT User
Joined
Mar 16, 2010
Messages
1,480
Solutions
9
Reaction score
211
hello folks, I'm using an old tfs 1.2 and when I try create items that I cannot carry e.g. teleports, tiles etc..
the server freeze, no errors in log, then 1 min later I can enter and the item is there
LOL
from where I can start to find the error and fix it ?
also, the function Game.createItem() is the same from tfs 1.3.
 
Solution
im not exactly sure where the problem is but im sure it has something to do inside of player:addItem
might not be inside of the function in luascript.cpp but internalAddItem in game.cpp might be bugged
anyways you could just check for itemtype:isMovable() and use Game.createItem if it returns false like this
Code:
    if not itemType:isMovable() then
        Game.createItem(itemType:getId(), count, player:getPosition())
    else
        local result = player:addItem(itemType:getId(), count)
        if result ~= nil then
            if not itemType:isStackable() then
                if type(result) == "table" then
                    for _, item in ipairs(result) do
                        item:decay()
                    end...
I'm using /i
the function Game.createItem() is working fine...
the talkaction /i is the same from the tfs 1.3 repository
then player:addItem must be different in your sources since that's what it uses
why not just upgrade to latest version?
 
I have some features to put in the latest version and I am feeling lazy to do it...
then, are you sure that "player:addItem() is the problem ?
the freeze happen when I try create a ground, teleport, items that the players can't carry :(
my functions player:addItem() and player:addItemEx() is the same from the tfs 1.3 repo...
 
Last edited:
im not exactly sure where the problem is but im sure it has something to do inside of player:addItem
might not be inside of the function in luascript.cpp but internalAddItem in game.cpp might be bugged
anyways you could just check for itemtype:isMovable() and use Game.createItem if it returns false like this
Code:
    if not itemType:isMovable() then
        Game.createItem(itemType:getId(), count, player:getPosition())
    else
        local result = player:addItem(itemType:getId(), count)
        if result ~= nil 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
        end
        player:getPosition():sendMagicEffect(CONST_ME_MAGIC_GREEN)
    end
 
Solution
I try then the result is the same freeze
my current script
Code:
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:split(",")

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

    local count = tonumber(split[2])
    if count ~= nil 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 not itemType:isMovable() then
        Game.createItem(itemType:getId(), count, player:getPosition())
    else
        if result ~= nil 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
    end
    return false
end
almost sure that the problem is even in player:addItem()
 
I try then the result is the same freeze
my current script
Code:
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:split(",")

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

    local count = tonumber(split[2])
    if count ~= nil 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 not itemType:isMovable() then
        Game.createItem(itemType:getId(), count, player:getPosition())
    else
        if result ~= nil 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
    end
    return false
end
almost sure that the problem is even in player:addItem()
because you changed the code i gave you
ofc it still doesnt work because it's calling player:addItem anyways because it's not inside any if statements
 
sorry :oops: I'm too tired atm, I'll rewrite it.
edit: oh now it work, thanks alot for this quickly fix... later I'll see what happen with player:addItem()
 
Back
Top