• 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.2 -> player:addItem()

roriscrave

Advanced OT User
Joined
Dec 7, 2011
Messages
1,188
Solutions
34
Reaction score
200
why it dont work?

Lua:
function onUse(player, item, fromPosition, target, toPosition, isHotkey) 
    if item.itemid == 2567 then
        local bag = player:addItem(1988, 1)
        local quant = math.random(1, 5)
        bag:addItem(8300, quant)
        player:sendTextMessage(17, "You received "..quant.." stones!")
        item:remove()
    end
    return true
end
i receive the msg:
Code:
17:19 You received 5 stones!
but in bag have only 1 stone.
Obs: a stone inst a stackable item! how can i add 5 stones into a bag?
 
Last edited:
Solution
Lua:
local bag = player:addItem(1988, 1)
local q = math.random(1, 5)
      
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if item.itemid == 2567 then
        if q == 1 then
            bag:addItem(8300, 1)
        elseif q == 2 then
            bag:addItem(8300, 1)
            bag:addItem(8300, 1)
        elseif q == 3 then
            bag:addItem(8300, 1)
            bag:addItem(8300, 1)
            bag:addItem(8300, 1)
        elseif q == 4 then
            bag:addItem(8300, 1)
            bag:addItem(8300, 1)
            bag:addItem(8300, 1)
            bag:addItem(8300, 1)
        elseif q == 5 then
            bag:addItem(8300, 1)
            bag:addItem(8300, 1)
            bag:addItem(8300, 1)...
i think is possible not using stackable item.
You cant stack an unstackable item <.<

Lua:
local bag = player:addItem(1988, 1)
local q = math.random(1, 5)
        
function onUse(player, item, fromPosition, target, toPosition, isHotkey) 
    if item.itemid == 2567 then
        if q == 1 then
            bag:addItem(8300, 1)
        elseif q == 2 then
            bag:addItem(8300, 1)
            bag:addItem(8300, 1)
        elseif q == 3 then
            bag:addItem(8300, 1)
            bag:addItem(8300, 1)
            bag:addItem(8300, 1)
        elseif q == 4 then
            bag:addItem(8300, 1)
            bag:addItem(8300, 1)
            bag:addItem(8300, 1)
            bag:addItem(8300, 1)
        elseif q == 5 then
            bag:addItem(8300, 1)
            bag:addItem(8300, 1)
            bag:addItem(8300, 1)
            bag:addItem(8300, 1)
            bag:addItem(8300, 1)
        end
        player:sendTextMessage(17, "You received "..q.." stones!")
        item:remove()
    end
    return true
end
Is this what you mean?
 
Lua:
local bag = player:addItem(1988, 1)
local q = math.random(1, 5)
      
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if item.itemid == 2567 then
        if q == 1 then
            bag:addItem(8300, 1)
        elseif q == 2 then
            bag:addItem(8300, 1)
            bag:addItem(8300, 1)
        elseif q == 3 then
            bag:addItem(8300, 1)
            bag:addItem(8300, 1)
            bag:addItem(8300, 1)
        elseif q == 4 then
            bag:addItem(8300, 1)
            bag:addItem(8300, 1)
            bag:addItem(8300, 1)
            bag:addItem(8300, 1)
        elseif q == 5 then
            bag:addItem(8300, 1)
            bag:addItem(8300, 1)
            bag:addItem(8300, 1)
            bag:addItem(8300, 1)
            bag:addItem(8300, 1)
        end
        player:sendTextMessage(17, "You received "..q.." stones!")
        item:remove()
    end
    return true
end
Is this what you mean?

Can be shortened a bit:
Lua:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if item.itemid == 2567 then
        local bag = player:addItem(1988, 1)
        local quant = math.random(1, 5)
        for i = 1, quant do
            bag:addItem(8300, 1)
        end
        player:sendTextMessage(17, "You received "..quant.." stones!")
        item:remove()
    end
    return true
end
 
Solution
Back
Top