• 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+ Chest system possible to add backpack with items?

Thorn

Spriting since 2013
Joined
Sep 24, 2012
Messages
2,203
Solutions
1
Reaction score
921
Location
Chile
Hello guys, i have been using this action for like forever now, and i like it, and i was wondering if with the same script i could give the player a backpack with items inside:
Lua:
function onUse(cid, item, frompos, item2, topos)
if item.uid == 28735 then
queststatus = getPlayerStorageValue(cid,28735)
if queststatus == -1 then
doPlayerSendTextMessage(cid,22,"You have found a health stone.")
doPlayerAddItem(cid,28788,1)
setPlayerStorageValue(cid,28735,1)
else
doPlayerSendTextMessage(cid,22,"It is empty.!")
end
else
return 0
end
return 1
end

i use tfs 1.3
 
Solution
Try:
Lua:
local config = {
    [28735] = {
        backpackId = 1988,
        rewards = {
            {id = 2398, amount = 1},
            {id = 2160, amount = 50}
        },
        storage = 28735
    }
}

function onUse(player, item, fromPosition, itemEx, toPosition)
    local cont = config[item.uid]
    if not cont then
        return false
    end

    if player:getStorageValue(cont.storage) > 0 then
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'It is empty.!')
        return true
    end

    local rewardMsg = "You have found:"
    local backpack = player:addItem(cont.backpackId)
    player:setStorageValue(cont.storage, 1)
    for i = 1, #cont.rewards do
        backpack:addItem(cont.rewards[i].id, cont.rewards[i].amount)...
Lua:
local config = {
    backpackId = 1988,
    itemsInside = {
        {id = 2398, amount = 1},
        {id = 2160, amount = 50}
    }
}


Lua:
local backpack = Container(doCreateItemEx(config.backpackId))
for i = 1, #config.itemsInside do
    backpack:addItem(config.itemsInside[i].id, config.itemsInside[i].amount)
end
player:addItemEx(backpack)
 
Lua:
local config = {
    backpackId = 1988,
    itemsInside = {
        {id = 2398, amount = 1},
        {id = 2160, amount = 50}
    }
}


Lua:
local backpack = Container(doCreateItemEx(config.backpackId))
for i = 1, #config.itemsInside do
    backpack:addItem(config.itemsInside[i].id, config.itemsInside[i].amount)
end
player:addItemEx(backpack)
cool!
so something like this? xD sorry if i made a mistake

Code:
function onUse(cid, item, frompos, item2, topos)
if item.uid == 28735 then
queststatus = getPlayerStorageValue(cid,28735)
if queststatus == -1 then
doPlayerSendTextMessage(cid,22,"You have found a health stone.")
local config = {
    backpackId = 1988,
    itemsInside = {
        {id = 2398, amount = 1},
        {id = 2160, amount = 50}
    }
}
setPlayerStorageValue(cid,28735,1)
else
doPlayerSendTextMessage(cid,22,"It is empty.!")
end
else
return 0
end
return 1
end
 
Lua:
local config = {
    backpackId = 1988,
    itemsInside = {
        {id = 2398, amount = 1},
        {id = 2160, amount = 50}
    }
}

function onUse(cid, item, frompos, item2, topos)
    if item.uid == 28735 then
        queststatus = getPlayerStorageValue(cid,28735)
        if queststatus == -1 then
            doPlayerSendTextMessage(cid,22,"You have found a health stone.")
            setPlayerStorageValue(cid,28735,1)
            local backpack = Container(doCreateItemEx(config.backpackId))
            for i = 1, #config.itemsInside do
                backpack:addItem(config.itemsInside[i].id, config.itemsInside[i].amount)
            end
            Player(cid):addItemEx(backpack)
        else
            doPlayerSendTextMessage(cid,22,"It is empty.!")
        end
    else
        return 0
    end
    return 1
end
 
Lua:
local config = {
    backpackId = 1988,
    itemsInside = {
        {id = 2398, amount = 1},
        {id = 2160, amount = 50}
    }
}

function onUse(cid, item, frompos, item2, topos)
    if item.uid == 28735 then
        queststatus = getPlayerStorageValue(cid,28735)
        if queststatus == -1 then
            doPlayerSendTextMessage(cid,22,"You have found a health stone.")
            setPlayerStorageValue(cid,28735,1)
            local backpack = Container(doCreateItemEx(config.backpackId))
            for i = 1, #config.itemsInside do
                backpack:addItem(config.itemsInside[i].id, config.itemsInside[i].amount)
            end
            Player(cid):addItemEx(backpack)
        else
            doPlayerSendTextMessage(cid,22,"It is empty.!")
        end
    else
        return 0
    end
    return 1
end
Thanks man!!

dude! is it possible to get item names and cuantity in this line??
Code:
doPlayerSendTextMessage(cid,22,"You have found a health stone.")
 
Last edited:
Lua:
local config = {
    [28735] = {
        backpackId = 1988,
        rewards = {
            {id = 2398, amount = 1},
            {id = 2160, amount = 50}
        },
        storage = 28735
    }
}
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local cont = config[item.uid]
    if not cont then
        return false
    end

    if player:getStorageValue(cont.storage) > 0 then
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'It is empty.!')
        return true
    end

    player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'You have found a health stone.')
    player:setStorageValue(cont.storage, 1)
    local backpack = player:addItem(cont.backpackId)
    for _, reward in ipairs(cont.rewards) do
        backpack:addItem(reward.id, reward.amount)
    end
    return true
end
 
Lua:
local config = {
    [28735] = {
        backpackId = 1988,
        rewards = {
            {id = 2398, amount = 1},
            {id = 2160, amount = 50}
        },
        storage = 28735
    }
}
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local cont = config[item.uid]
    if not cont then
        return false
    end

    if player:getStorageValue(cont.storage) > 0 then
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'It is empty.!')
        return true
    end

    player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'You have found a health stone.')
    player:setStorageValue(cont.storage, 1)
    local backpack = player:addItem(cont.backpackId)
    for _, reward in ipairs(cont.rewards) do
        backpack:addItem(reward.id, reward.amount)
    end
    return true
end
im sorry what did u do there? the line is the same, or did u fix something with the previous one?
 
Try:
Lua:
local config = {
    [28735] = {
        backpackId = 1988,
        rewards = {
            {id = 2398, amount = 1},
            {id = 2160, amount = 50}
        },
        storage = 28735
    }
}

function onUse(player, item, fromPosition, itemEx, toPosition)
    local cont = config[item.uid]
    if not cont then
        return false
    end

    if player:getStorageValue(cont.storage) > 0 then
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'It is empty.!')
        return true
    end

    local rewardMsg = "You have found:"
    local backpack = player:addItem(cont.backpackId)
    player:setStorageValue(cont.storage, 1)
    for i = 1, #cont.rewards do
        backpack:addItem(cont.rewards[i].id, cont.rewards[i].amount)
        rewardMsg = cont.rewards[i].amount > 1 and rewardMsg .. " ".. cont.rewards[i].amount .. "x " .. ItemType(cont.rewards[i].id):getName() or rewardMsg .. " " .. ItemType(cont.rewards[i].id):getName()
        rewardMsg = i == #cont.rewards and rewardMsg .. "." or rewardMsg .. ","
    end
    player:sendTextMessage(MESSAGE_EVENT_ADVANCE, rewardMsg)

    return true
end

Should probably create the bp first without any parent, add items to it and then set the parent to player. This way we can check required cap and give appropriate error or just drop the whole bp on the ground.
 
Solution
Try:
Lua:
local config = {
    [28735] = {
        backpackId = 1988,
        rewards = {
            {id = 2398, amount = 1},
            {id = 2160, amount = 50}
        },
        storage = 28735
    }
}

function onUse(player, item, fromPosition, itemEx, toPosition)
    local cont = config[item.uid]
    if not cont then
        return false
    end

    if player:getStorageValue(cont.storage) > 0 then
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'It is empty.!')
        return true
    end

    local rewardMsg = "You have found:"
    local backpack = player:addItem(cont.backpackId)
    player:setStorageValue(cont.storage, 1)
    for i = 1, #cont.rewards do
        backpack:addItem(cont.rewards[i].id, cont.rewards[i].amount)
        rewardMsg = cont.rewards[i].amount > 1 and rewardMsg .. " ".. cont.rewards[i].amount .. "x " .. ItemType(cont.rewards[i].id):getName() or rewardMsg .. " " .. ItemType(cont.rewards[i].id):getName()
        rewardMsg = i == #cont.rewards and rewardMsg .. "." or rewardMsg .. ","
    end
    player:sendTextMessage(MESSAGE_EVENT_ADVANCE, rewardMsg)

    return true
end

Should probably create the bp first without any parent, add items to it and then set the parent to player (also check for cap etc.).
Nice man ! Gg
 
The script wasnt working for me but now it does, my bad for sure xd

thank you both guys!! you have helped me a lot with this!!

oh btw, i had a non pickable item in the quest, and when i right clicked the chest, the item wasnt anywhere, not even in the ground
 
Last edited:
Back
Top