• 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!

Lua how to add the weight of all items

volcomfaria

New Member
Joined
Dec 30, 2008
Messages
4
Reaction score
1
Hey guys!
I would like to know how to add the weight of all items. Can someone help me?



In case I'm trying to do in this script:
Lua:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local items = {}

    if player:getVocation():getId() == 1 then
        items = {2190,8820,8819}
    end
    
    for i= 1, #items do
        player:addItem(items)
    end
    items = nil
    return true
end
 
Solution
Hey guys!
I would like to know how to add the weight of all items. Can someone help me?



In case I'm trying to do in this script:
Lua:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local items = {}

    if player:getVocation():getId() == 1 then
        items = {2190,8820,8819}
    end
   
    for i= 1, #items do
        player:addItem(items)
    end
    items = nil
    return true
end
Lua:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local items = {}
    local weight = 0

    if player:getVocation():getId() == 1 then
        items = {2190,8820,8819}
    end
    
    for i = 1, #items do
        player:addItem(items[i])
        weight = weight +...
Hey guys!
I would like to know how to add the weight of all items. Can someone help me?



In case I'm trying to do in this script:
Lua:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local items = {}

    if player:getVocation():getId() == 1 then
        items = {2190,8820,8819}
    end
   
    for i= 1, #items do
        player:addItem(items)
    end
    items = nil
    return true
end
Lua:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local items = {}
    local weight = 0

    if player:getVocation():getId() == 1 then
        items = {2190,8820,8819}
    end
    
    for i = 1, #items do
        player:addItem(items[i])
        weight = weight + ItemType(items[i]):getWeight()
    end
    
    print(weight)
    items = nil
    return true
end
 
Solution
Lua:
local vocations = {
    [1] = {2190, 8820, 8819}, -- Sorcerer
    [2] = {2190}, -- Druid
    [3] = {2190}, -- Paladin
    [4] = {2190} -- Knight
}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
  
 
    local VOC = vocations[player:getVocation():getId()]
 
    if not VOC then return true end
 
    local weight = 0

    for i = 1, #VOC do
        weight = weight + ItemType(VOC[i]):getWeight()
    end
 
    if player:getCapacity() < weight then
        return player:sendCancelMessage("The items are too heavy for you to carry.")
    end
 
    for i = 1, #VOC do
        player:addItem(VOC[i], 1)
    end

    return true
end
[/I][/I]
 
Last edited:
Back
Top