• 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+ ChestsSystem problem with the weight*

Eduardo170

Well-Known Member
Joined
Jan 7, 2014
Messages
422
Solutions
3
Reaction score
66
Location
Caracas, Venezuela
I've been create a ChestSystem.
The only problem is
You have found a chest weighing 69636000 oz it's too heavy.
This happen in alls chests.

Code:
 <action uniqueid="28886" script="chestSystem.lua" />
    <action uniqueid="28888" script="chestSystem.lua" />
    <action uniqueid="28887" script="chestSystem.lua" />


Code:
local config = {
    [28886] = {rewards = 2326, count= 1, storage = 28501},
    [28888] = {rewards = 5803, count= 1, storage = 28500},
    [28887] = {rewards = 2160, count= 50, storage = 28502},
    }

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local chests = config[item.uid]
    local playerCap = player:getFreeCapacity()
    local itemType = ItemType(item.itemid)
    local itemWeight = itemType:getWeight()

    if player:getStorageValue(chests.storage) == -1 then

            if playerCap >= itemWeight then
                player:sendTextMessage(MESSAGE_INFO_DESCR, 'You have found a ' .. itemType:getName() .. '.')
                player:addItem(chests.rewards, chests.count)
                player:setStorageValue(chests.storage, 1)
            else
                player:sendTextMessage(MESSAGE_INFO_DESCR, 'You have found a ' .. itemType:getName() .. ' weighing ' .. itemWeight ..' oz it\'s too heavy.')
            end
        else
            player:sendTextMessage(MESSAGE_INFO_DESCR, "It is empty.")
    end
    return true
end
 
Last edited:
Solution
Did you not even think to do a search in a datapack for the keyword "weight"
First file i opened.

string.format('You have found %s weighing %.2f oz. You have no capacity.', text, (weight / 100))
local itemType = ItemType(item.itemid)

You just check chest xd
Code:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
local chests = config[item.uid]
local playerCap = player:getFreeCapacity()

if player:getStorageValue(chests.storage) < 1 then
local itemType = ItemType(chests.rewards)
local itemWeight = itemType:getWeight()

if playerCap >= itemWeight then
player:sendTextMessage(MESSAGE_INFO_DESCR, 'You have found a .')
player:addItem(chests.rewards, chests.count)
player:setStorageValue(chests.storage, 1)
else
player:sendTextMessage(MESSAGE_INFO_DESCR, 'You have found a weighing oz it\'s too heavy.')
end
else
player:sendTextMessage(MESSAGE_INFO_DESCR, "It is empty.")
end
return true
end
 
local itemType = ItemType(item.itemid)

You just check chest xd
Code:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
local chests = config[item.uid]
local playerCap = player:getFreeCapacity()

if player:getStorageValue(chests.storage) < 1 then
local itemType = ItemType(chests.rewards)
local itemWeight = itemType:getWeight()

if playerCap >= itemWeight then
player:sendTextMessage(MESSAGE_INFO_DESCR, 'You have found a .')
player:addItem(chests.rewards, chests.count)
player:setStorageValue(chests.storage, 1)
else
player:sendTextMessage(MESSAGE_INFO_DESCR, 'You have found a weighing oz it\'s too heavy.')
end
else
player:sendTextMessage(MESSAGE_INFO_DESCR, "It is empty.")
end
return true
end
Sorry I forget update my thread xD, check again, this is chestSystem and still bugg with the weight.
You have found a chest weighing 69636000 oz it's too heavy.
Code:
local config = {
    [28886] = {rewards = 2326, count= 1, storage = 28501},
    [28888] = {rewards = 5803, count= 1, storage = 28500},
    [28887] = {rewards = 2160, count= 50, storage = 28502},
    }

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local chests = config[item.uid]
    local playerCap = player:getFreeCapacity()
    local itemType = ItemType(item.itemid)
    local itemWeight = itemType:getWeight()

    if player:getStorageValue(chests.storage) == -1 then

            if playerCap >= itemWeight then
                player:sendTextMessage(MESSAGE_INFO_DESCR, 'You have found a ' .. itemType:getName() .. '.')
                player:addItem(chests.rewards, chests.count)
                player:setStorageValue(chests.storage, 1)
            else
                player:sendTextMessage(MESSAGE_INFO_DESCR, 'You have found a ' .. itemType:getName() .. ' weighing ' .. itemWeight ..' oz it\'s too heavy.')
            end
        else
            player:sendTextMessage(MESSAGE_INFO_DESCR, "It is empty.")
    end
    return true
end
 
i solved your problem in my last answer xd
This:

Code:
    local itemType = ItemType(item.itemid)
    local itemWeight = itemType:getWeight()

check chest, because you type "item" ... item that's what you click for... You want weight rewards from config... so.. you have to check id from rewards... SO....
THIS
Code:
    local itemType = ItemType(item.itemid) -->  local itemType = ItemType(chests.rewards) -- because you want rewards weight
    local itemWeight = itemType:getWeight()
behind:
Code:
if player:getStorageValue(chests.storage) == -1 then

final code:

Code:
local config = {
    [28886] = {rewards = 2326, count= 1, storage = 28501},
    [28888] = {rewards = 5803, count= 1, storage = 28500},
    [28887] = {rewards = 2160, count= 50, storage = 28502},
    }

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local chests = config[item.uid]
    local playerCap = player:getFreeCapacity()
    if player:getStorageValue(chests.storage) == -1 then
    local itemType = ItemType(chests.rewards)
    local itemWeight = itemType:getWeight()
            if playerCap >= itemWeight then
                player:sendTextMessage(MESSAGE_INFO_DESCR, 'You have found a ' .. itemType:getName() .. '.')
                player:addItem(chests.rewards, chests.count)
                player:setStorageValue(chests.storage, 1)
            else
                player:sendTextMessage(MESSAGE_INFO_DESCR, 'You have found a ' .. itemType:getName() .. ' weighing ' .. itemWeight ..' oz it\'s too heavy.')
            end
        else
            player:sendTextMessage(MESSAGE_INFO_DESCR, "It is empty.")
    end
    return true
end
 
i solved your problem in my last answer xd
This:

Code:
    local itemType = ItemType(item.itemid)
    local itemWeight = itemType:getWeight()

check chest, because you type "item" ... item that's what you click for... You want weight rewards from config... so.. you have to check id from rewards... SO....
THIS
Code:
    local itemType = ItemType(item.itemid) -->  local itemType = ItemType(chests.rewards) -- because you want rewards weight
    local itemWeight = itemType:getWeight()
behind:
Code:
if player:getStorageValue(chests.storage) == -1 then

final code:

Code:
local config = {
    [28886] = {rewards = 2326, count= 1, storage = 28501},
    [28888] = {rewards = 5803, count= 1, storage = 28500},
    [28887] = {rewards = 2160, count= 50, storage = 28502},
    }

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local chests = config[item.uid]
    local playerCap = player:getFreeCapacity()
    if player:getStorageValue(chests.storage) == -1 then
    local itemType = ItemType(chests.rewards)
    local itemWeight = itemType:getWeight()
            if playerCap >= itemWeight then
                player:sendTextMessage(MESSAGE_INFO_DESCR, 'You have found a ' .. itemType:getName() .. '.')
                player:addItem(chests.rewards, chests.count)
                player:setStorageValue(chests.storage, 1)
            else
                player:sendTextMessage(MESSAGE_INFO_DESCR, 'You have found a ' .. itemType:getName() .. ' weighing ' .. itemWeight ..' oz it\'s too heavy.')
            end
        else
            player:sendTextMessage(MESSAGE_INFO_DESCR, "It is empty.")
    end
    return true
end
work, but little problem in weight is send to players
95,00 no 9500 xD
08:22 You have found a arbalest weighing 9500 oz it's too heavy. 95,00 xD
 
Did you not even think to do a search in a datapack for the keyword "weight"
First file i opened.

string.format('You have found %s weighing %.2f oz. You have no capacity.', text, (weight / 100))
 
Solution
Did you not even think to do a search in a datapack for the keyword "weight"
First file i opened.

string.format('You have found %s weighing %.2f oz. You have no capacity.', text, (weight / 100))
thanks you.
Code:
local config = {
    [28886] = {rewards = 2510, count= 1, storage = 28509},
    [28888] = {rewards = 2505, count= 1, storage = 28514},
    [28887] = {rewards = 2508, count= 1, storage = 28513},
    }

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local chests = config[item.uid]
    local playerCap = player:getFreeCapacity()
    if player:getStorageValue(chests.storage) == -1 then
    local itemType = ItemType(chests.rewards)
    local itemWeight = itemType:getWeight()
            if playerCap >= itemWeight then
                player:sendTextMessage(MESSAGE_INFO_DESCR, 'You have found a ' .. itemType:getName() .. '.')
                player:addItem(chests.rewards, chests.count)
                player:setStorageValue(chests.storage, 1)
            else
                player:sendTextMessage(MESSAGE_INFO_DESCR, 'You have found a ' .. itemType:getName() .. ' weighing ' .. itemWeight /100 ..' oz it\'s too heavy.')
            end
        else
            player:sendTextMessage(MESSAGE_INFO_DESCR, "It is empty.")
    end
    return true
end
 
Back
Top