• 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+ Script backpack reduces 25% capacity

Forkz

Well-Known Member
Joined
Jun 29, 2020
Messages
380
Solutions
1
Reaction score
89
Hi otlanders,

I'm looking for a backpack script that when equipped reduces the capacity of the items inside it by 25%.

Anyone to help with this script?
 
I think if you set an item to a negative weight, it increases the players capacity when worn.

So.. you'd just want to adjust the backpacks weight whenever Player:onInventoryUpdate is called.. and whenever you equip/deEquip the backpack (assuming the inventory is updated when you add/remove an item inside the backpack as well.. so that items given via script/npc will also trigger the update. Never used it before.. so idk)
You'll get some mixed results at the bottom of the capacity.. when an item could technically fit.. if the backpack weight were adjusted before the item went in.. but meh. I don't see a good solution for that.

Anyway, something like this should work

Lua:
local backpackId = 1111
local percentReduction = 0.25 -- 25%

local backpack = findTheBackpackItemHoweverYouNeedTo
backpack:setAttribute(ITEM_ATTRIBUTE_WEIGHT, 0) -- minor hack, so we can get the weight of stuff inside, ignoring the backpack itself, since we can't know it's current weight

local backpackContentsWeight = backpack:getWeight()
local newBackpackWeight = ItemType(backpackId):getWeight() - (backpackContentsWeight * percentReduction)
backpack:setAttribute(ITEM_ATTRIBUTE_WEIGHT, newBackpackWeight)
 
I think if you set an item to a negative weight, it increases the players capacity when worn.

So.. you'd just want to adjust the backpacks weight whenever Player:onInventoryUpdate is called.. and whenever you equip/deEquip the backpack (assuming the inventory is updated when you add/remove an item inside the backpack as well.. so that items given via script/npc will also trigger the update. Never used it before.. so idk)
You'll get some mixed results at the bottom of the capacity.. when an item could technically fit.. if the backpack weight were adjusted before the item went in.. but meh. I don't see a good solution for that.

Anyway, something like this should work

Lua:
local backpackId = 1111
local percentReduction = 0.25 -- 25%

local backpack = findTheBackpackItemHoweverYouNeedTo
backpack:setAttribute(ITEM_ATTRIBUTE_WEIGHT, 0) -- minor hack, so we can get the weight of stuff inside, ignoring the backpack itself, since we can't know it's current weight

local backpackContentsWeight = backpack:getWeight()
local newBackpackWeight = ItemType(backpackId):getWeight() - (backpackContentsWeight * percentReduction)
backpack:setAttribute(ITEM_ATTRIBUTE_WEIGHT, newBackpackWeight)
I will test and come back with updates
 
Back
Top