• 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+ tfs 1.3 add item in a bag inside a backpack possible?

roriscrave

Advanced OT User
Joined
Dec 7, 2011
Messages
1,210
Solutions
35
Reaction score
206
Hi, i'm tring to create a code that player will use a lever, and will receive:
A bag with 4 backpack inside it.
LUA:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local bag = player:addItem(1992, 1) -- a bag
    bag:addItem(1999, 1) -- backpack 1
    bag:addItem(1999, 1) -- backpack 2
    bag:addItem(1999, 1) -- backpack 3
    bag:addItem(1999, 1) -- backpack 4
    return true
end

Now I need to add items inside the backpacks, how can I do it?
Code:
backpack items = {11991, 1000}, {5880,30}, {5891,25}, {10558,10}
each backpack needs to receive these items
 
Last edited:
Solution
LUA:
local reward = {
    {id = 1992, items = {
            {id = 1999, items = {{id = 11991, count = 1000}}},
            {id = 1999, items = {{id = 5880, count = 30}}},
            {id = 1999, items = {{id = 5891, count = 25}}},
            {id = 1999, items = {{id = 10558, count = 10}}}
        }
    }
}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    for _, rewardItem in ipairs(reward) do
        local parent = player:addItem(rewardItem.id, 1)
        for _, v in ipairs(rewardItem.items) do
            local bag = parent:addItem(v.id)
            for _, childReward in ipairs(v.items) do
                local count = childReward.count
                while count > 0 do
                    local tmpCount =...
LUA:
local reward = {
    {id = 1992, items = {
            {id = 1999, items = {{id = 11991, count = 1000}}},
            {id = 1999, items = {{id = 5880, count = 30}}},
            {id = 1999, items = {{id = 5891, count = 25}}},
            {id = 1999, items = {{id = 10558, count = 10}}}
        }
    }
}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    for _, rewardItem in ipairs(reward) do
        local parent = player:addItem(rewardItem.id, 1)
        for _, v in ipairs(rewardItem.items) do
            local bag = parent:addItem(v.id)
            for _, childReward in ipairs(v.items) do
                local count = childReward.count
                while count > 0 do
                    local tmpCount = math.min(100, count)
                    bag:addItem(childReward.id, tmpCount)
                    count = count - tmpCount
                end
            end
        end
    end
    return true
end
 
Solution

Similar threads

Back
Top