- Joined
- Feb 14, 2015
- Messages
- 5,643
- Solutions
- 559
- Reaction score
- 3,949
inspired by @Xikini, his code for 0.x linked here
example, gives a backpack with 48 arbalests and 300cc:
If someone wants to convert the scant amount of actual functions for TFS 1.0+, please do so.
Lua:
function Player.giveItems(self, t)
local cap = (ItemType(1988):getWeight() / 100) * (math.floor(#t / 20) + 1)
for i = 1, #t do
local v = t[i]
cap = cap + ((ItemType(v[1]):getWeight() / 100) * v[2])
end
local resultCap = (self:getCapacity() / 100) - cap
if resultCap < 0 then
self:sendCancelMessage("You found a container weighing ".. cap .." oz. You require ".. math.abs(resultCap) .." more capacity in order to hold it.")
self:getPosition():sendMagicEffect(CONST_ME_POFF)
return false
end
local container = self:addItem(1988)
local size = 0
local slots = container:getCapacity()
for i = 1, #t do
local v = t[i]
local itemType = ItemType(v[1])
local n = itemType:isStackable() and 100 or 1
local count = v[2]
while count > 0 do
-- create a new container in place of the last slot in the container
if size + 1 == slots then
container = container:addItem(1988)
size = 0
end
container:addItem(v[1], n)
count = count - n
size = size + 1
end
end
return true
end
example, gives a backpack with 48 arbalests and 300cc:
Lua:
local items = {
{5803, 48},
{2160, 300}
}
player:giveItems(items)
Last edited by a moderator: