Advertisement
klts

DynamicBackpackUpgrades.lua

Dec 31st, 2024
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 19.65 KB | None | 0 0
  1. local BannedItemTypes = {"KeyRing"} -- list of banned containers.
  2.  
  3. local SandboxInit = false
  4. local KnivesCanRemove = SandboxVars.DynamicBackpacks.KnivesCanRemove or false
  5. local BaseUpgrades = SandboxVars.DynamicBackpacks.BaseUpgradeSlots or 1
  6. local BackModifier = SandboxVars.DynamicBackpacks.BackSlotModifier or 1
  7. local FannyModifier = SandboxVars.DynamicBackpacks.FannySlotModifier or 0
  8. local OtherModifier = SandboxVars.DynamicBackpacks.OtherSlotModifier or 0
  9. local TailoringModifier = SandboxVars.DynamicBackpacks.TailoringModifier or 10
  10. if TailoringModifier == 0 then TailoringModifier = 11 end -- easier to make the math function do this than to make a whole set of "if" statements.
  11.  
  12. local CapacityBonusCloth = SandboxVars.DynamicBackpacks.ClothCapacityBonus or 1
  13. local CapacityBonusJean = SandboxVars.DynamicBackpacks.JeanCapacityBonus or 1
  14. local CapacityBonusLeather = SandboxVars.DynamicBackpacks.LeatherCapacityBonus or 2
  15. local CapacityBonusMilitary = SandboxVars.DynamicBackpacks.MilitaryCapacityBonus or 2
  16.  
  17.  
  18. local UpgradeItemValues = {
  19. ["UpgradeCapacityCloth"] = 1 + (SandboxVars.DynamicBackpacks.ClothCapacityPercentage or 0.1),
  20. ["UpgradeWeightReductionCloth"] = 1 - (SandboxVars.DynamicBackpacks.ClothReductionPercentage or 0.15),
  21.  
  22. ["UpgradeCapacityJean"] = 1 + (SandboxVars.DynamicBackpacks.JeanCapacityPercentage or 0.2),
  23. ["UpgradeWeightReductionJean"] = 1 - (SandboxVars.DynamicBackpacks.JeanReductionPercentage or 0.25),
  24.  
  25. ["UpgradeCapacityLeather"] = 1 + (SandboxVars.DynamicBackpacks.LeatherCapacityPercentage or 0.25),
  26. ["UpgradeWeightReductionLeather"] = 1 - (SandboxVars.DynamicBackpacks.LeatherReductionPercentage or 0.35),
  27.  
  28. ["UpgradeCapacityMilitary"] = 1 + (SandboxVars.DynamicBackpacks.MilitaryCapacityPercentage or 0.35),
  29. ["UpgradeWeightReductionMilitary"] = 1 - (SandboxVars.DynamicBackpacks.MilitaryReductionPercentage or 0.5),
  30. }
  31.  
  32. function getUpgradeItemValue(ItemType) -- for use in other scripts.
  33.     return UpgradeItemValues[ItemType]
  34. end
  35.  
  36. function UpdateSandboxSettings()
  37.     SandboxInit = true
  38.     KnivesCanRemove = SandboxVars.DynamicBackpacks.KnivesCanRemove or false
  39.     BaseUpgrades = SandboxVars.DynamicBackpacks.BaseUpgradeSlots or 1
  40.     BackModifier = SandboxVars.DynamicBackpacks.BackSlotModifier or 1
  41.     FannyModifier = SandboxVars.DynamicBackpacks.FannySlotModifier or 0
  42.     OtherModifier = SandboxVars.DynamicBackpacks.OtherSlotModifier or 0
  43.     TailoringModifier = SandboxVars.DynamicBackpacks.TailoringModifier or 10
  44.     if TailoringModifier == 0 then TailoringModifier = 11 end -- easier to make the math function do this than to make a whole set of "if" statements.
  45.  
  46.     CapacityBonusCloth = SandboxVars.DynamicBackpacks.ClothCapacityBonus or 1
  47.     CapacityBonusJean = SandboxVars.DynamicBackpacks.JeanCapacityBonus or 1
  48.     CapacityBonusLeather = SandboxVars.DynamicBackpacks.LeatherCapacityBonus or 2
  49.     CapacityBonusMilitary = SandboxVars.DynamicBackpacks.MilitaryCapacityBonus or 2
  50.  
  51.  
  52.     UpgradeItemValues = {
  53.     ["UpgradeCapacityCloth"] = 1 + (SandboxVars.DynamicBackpacks.ClothCapacityPercentage or 0.1),
  54.     ["UpgradeWeightReductionCloth"] = 1 - (SandboxVars.DynamicBackpacks.ClothReductionPercentage or 0.15),
  55.  
  56.     ["UpgradeCapacityJean"] = 1 + (SandboxVars.DynamicBackpacks.JeanCapacityPercentage or 0.2),
  57.     ["UpgradeWeightReductionJean"] = 1 - (SandboxVars.DynamicBackpacks.JeanReductionPercentage or 0.25),
  58.  
  59.     ["UpgradeCapacityLeather"] = 1 + (SandboxVars.DynamicBackpacks.LeatherCapacityPercentage or 0.25),
  60.     ["UpgradeWeightReductionLeather"] = 1 - (SandboxVars.DynamicBackpacks.LeatherReductionPercentage or 0.35),
  61.  
  62.     ["UpgradeCapacityMilitary"] = 1 + (SandboxVars.DynamicBackpacks.MilitaryCapacityPercentage or 0.35),
  63.     ["UpgradeWeightReductionMilitary"] = 1 - (SandboxVars.DynamicBackpacks.MilitaryReductionPercentage or 0.5),
  64.     }
  65. end
  66.  
  67. function ItemBanCheck(Item)
  68.     local Type = Item:getType()
  69.     for i,v in pairs(BannedItemTypes) do
  70.         if Type == v then
  71.             return true
  72.         end
  73.     end
  74.     return false
  75. end
  76. function ItemValid(Item)
  77.     if Item and Item:IsInventoryContainer() and not ItemBanCheck(Item) then
  78.         return true
  79.     else
  80.         return false
  81.     end
  82. end
  83.  
  84. function TableCheck(Table,For,UseIndex)
  85.     for i,v in pairs(Table) do
  86.         if UseIndex then
  87.             if i == For then return true end
  88.         else
  89.             if v == For then return true end
  90.         end
  91.        
  92.     end
  93.     return false
  94. end
  95. function TableShallowCopy(Table)
  96.     local Copy = {}
  97.     for i,v in pairs(Table) do
  98.         Copy[i] = v
  99.     end
  100.     return Copy
  101. end
  102. function Round(Num,DecimalPlaces)
  103.     return math.floor((Num*10^DecimalPlaces)+0.5)/10^DecimalPlaces
  104. end
  105.  
  106. function GetUpgradeItems(Container,ReturnTable)
  107.     local Inventory = Container:getInventory()
  108.     for i = 0, Inventory:getItems():size() - 1 do
  109.         local Item = Inventory:getItems():get(i);
  110.         if Item and Item:getType() then
  111.             if Item:IsInventoryContainer() and Item:isEquipped() then
  112.                 ReturnTable = GetUpgradeItems(Item,ReturnTable)
  113.             elseif UpgradeItemValues[Item:getType()] then
  114.                 table.insert(ReturnTable,Item)
  115.                 --print("Item Found")
  116.             end
  117.         end
  118.     end
  119.     return ReturnTable
  120. end
  121.  
  122. function GetTheoreticalStats(BaseCapacity,BaseWR,UpgradesTable)
  123.     local CapacityBonus = 0
  124.     local WeightMod = 1
  125.     for i,v in pairs(UpgradesTable) do
  126.         if UpgradeItemValues[v] >= 1 then
  127.             CapacityBonus = CapacityBonus + math.floor(BaseCapacity*(UpgradeItemValues[v]-1))
  128.             if v == "UpgradeCapacityCloth" then
  129.                 CapacityBonus = CapacityBonus + CapacityBonusCloth
  130.             elseif v == "UpgradeCapacityJean" then
  131.                 CapacityBonus = CapacityBonus + CapacityBonusJean
  132.             elseif v == "UpgradeCapacityLeather" then
  133.                 CapacityBonus = CapacityBonus + CapacityBonusLeather
  134.             elseif v == "UpgradeCapacityMilitary" then
  135.                 CapacityBonus = CapacityBonus + CapacityBonusMilitary
  136.             end
  137.         end
  138.         if UpgradeItemValues[v] < 1 then
  139.             WeightMod = WeightMod*UpgradeItemValues[v]
  140.         end
  141.     end
  142.     return math.floor(BaseCapacity+CapacityBonus+0.5),math.floor(100.5-(100-BaseWR)*WeightMod)
  143. end
  144.  
  145. function GetUpgradedStats(Bag)
  146.     local imd = Bag:getModData()
  147.     local CapacityBonus = 0
  148.     local WeightMod = 1
  149.     for i,v in pairs(imd.LUpgrades) do
  150.         if UpgradeItemValues[v] >= 1 then
  151.             CapacityBonus = CapacityBonus + math.floor(imd.LCapacity*(UpgradeItemValues[v]-1))
  152.             if v == "UpgradeCapacityCloth" then
  153.                 CapacityBonus = CapacityBonus + CapacityBonusCloth
  154.             elseif v == "UpgradeCapacityJean" then
  155.                 CapacityBonus = CapacityBonus + CapacityBonusJean
  156.             elseif v == "UpgradeCapacityLeather" then
  157.                 CapacityBonus = CapacityBonus + CapacityBonusLeather
  158.             elseif v == "UpgradeCapacityMilitary" then
  159.                 CapacityBonus = CapacityBonus + CapacityBonusMilitary
  160.             end
  161.         end
  162.         if UpgradeItemValues[v] < 1 then
  163.             WeightMod = WeightMod*UpgradeItemValues[v]
  164.         end
  165.     end
  166.     return Round(imd.LCapacity+CapacityBonus,0),Round(100-(100-imd.LWeightReduction)*WeightMod,0)
  167. end
  168.  
  169. function GetMaxUpgrades(Item)
  170.     if Item["canBeEquipped"](Item) == "Back" then --FannyPackBack FannyPackFront
  171.         return BaseUpgrades + BackModifier
  172.     elseif Item["canBeEquipped"](Item) == "FannyPackBack" or Item["canBeEquipped"](Item) == "FannyPackFront" then
  173.         return BaseUpgrades + FannyModifier
  174.     else
  175.         return BaseUpgrades + OtherModifier
  176.     end
  177. end
  178.  
  179. function InitBackpack(Item) -- this function exists in here and in TooltipOverride.lua
  180.     local imd = Item:getModData()
  181.     imd.LUpgrades = imd.LUpgrades or {}
  182.     imd.LCapacity = imd.LCapacity or Item:getCapacity()
  183.     imd.LWeightReduction = imd.LWeightReduction or Item:getWeightReduction()
  184.     imd.LFixState = "Show"
  185.     imd.LDynamicBackpacksInit = true
  186.     imd.LMaxUpgrades = GetMaxUpgrades(Item)
  187. end
  188.  
  189. function UpdateBag(Bag)
  190.     local imd = Bag:getModData()
  191.     local CapacityBonus = 0
  192.     local WeightMod = 1
  193.    
  194.     imd.LMaxUpgrades = GetMaxUpgrades(Bag)
  195.    
  196.     local UpgradedCapacity, UpgradedWeightReduction = GetUpgradedStats(Bag)
  197.    
  198.     Bag:setCapacity(UpgradedCapacity)
  199.     Bag:setWeightReduction(UpgradedWeightReduction)
  200. end
  201.  
  202. function AddUpgrade(Bag,Item,Player)
  203.     if not Bag or not Bag:IsInventoryContainer() or not Item or not Item:getContainer() then return end
  204.     local imd = Bag:getModData()
  205.     if imd.LMaxUpgrades > 0 and #imd.LUpgrades >= imd.LMaxUpgrades + math.floor(Player:getPerkLevel(Perks.Tailoring)/TailoringModifier) then return end
  206.    
  207.     if UpgradeItemValues[Item:getType()] then
  208.         table.insert(imd.LUpgrades,Item:getType())
  209.         Item:getContainer():Remove(Item)
  210.         UpdateBag(Bag)
  211.     else
  212.         print("Upgrade Not In List?")
  213.     end
  214. end
  215.  
  216. function RemoveUpgrade(Bag,ItemType,Player)
  217.     if not Bag or not Bag:IsInventoryContainer() or not ItemType then return end
  218.     local imd = Bag:getModData()
  219.    
  220.     for i,v in pairs(imd.LUpgrades) do
  221.         if v == ItemType then
  222.             local Inventory = Bag:getContainer()
  223.             local Item = Inventory:AddItem("DynamicBackpacks."..ItemType)
  224.             Inventory:addItemOnServer(Item)
  225.             table.remove(imd.LUpgrades,i)
  226.             UpdateBag(Bag)
  227.             break
  228.         end
  229.     end
  230.    
  231.     if #imd.LUpgrades <= 0 then
  232.         imd.LFixState = "Show"
  233.     end
  234. end
  235. --local NewAction = ISInventoryTransferAction:new(Player, I, FromContainer, ToContainer, Time)
  236. function HasDurability(Item)
  237.     if not Item:getCondition() or Item:getCondition() > 0 then
  238.         return true
  239.     end
  240.     return false
  241. end
  242. function CheckForAndGetUpgradeItems(Player,Fetch)
  243.     local inv = Player:getInventory()
  244.     local Needle = inv:getFirstTagRecurse("SewingNeedle")
  245.     local Thread = inv:getFirstTypeRecurse("Thread")
  246.     --local Thread = inv:getFirstTypeEvalRecurse("Thread",function(item) return item:getRemainingUses() > 0 end)
  247.     if not Needle or not Thread then return false end
  248.     if Fetch and not inv:contains(Needle) then
  249.         ISTimedActionQueue.add(ISInventoryTransferAction:new(Player, Needle, Needle:getContainer(), inv, Needle:getWeight()*60))
  250.     end
  251.     if Fetch and not inv:contains(Thread) then
  252.         ISTimedActionQueue.add(ISInventoryTransferAction:new(Player, Thread, Thread:getContainer(), inv, Thread:getWeight()*60))
  253.     end
  254.     return Needle, Thread
  255. end
  256. function CheckForAndGetRemoveItems(Player,Fetch)
  257.     local inv = Player:getInventory()
  258.     local Scissors = inv:getFirstTagEvalRecurse("Scissors",HasDurability)
  259.     --for i,v in pairs(ScissorsItemTypes) do
  260.         --Scissors = inv:getFirstTypeRecurse(v)
  261.     --end
  262.     if KnivesCanRemove and not Scissors then Scissors = inv:getFirstTagEvalRecurse("SharpKnife",HasDurability) end
  263.    
  264.     if not Scissors then return false end
  265.     if Fetch and not inv:contains(Scissors) then
  266.         ISTimedActionQueue.add(ISInventoryTransferAction:new(Player, Scissors, Scissors:getContainer(), inv, Scissors:getWeight()*60))
  267.     end
  268.     return Scissors, Damaged
  269. end
  270.  
  271.  
  272.  
  273. function RemoveValid(Bag,UpgradeItemType)
  274.     if UpgradeItemValues[UpgradeItemType] < 1 then
  275.         return true -- Weight Reduction upgrades dont matter.
  276.     else
  277.         local FakeUpgrades = TableShallowCopy(Bag:getModData().LUpgrades)
  278.         for i,v in pairs(FakeUpgrades) do
  279.             if v == UpgradeItemType then
  280.                 table.remove(FakeUpgrades,i)
  281.             end
  282.         end
  283.        
  284.         local imd = Bag:getModData()
  285.         local CurrentWeight = Bag:getContentsWeight()
  286.         local BaseCapacity = imd.LCapacity
  287.         local BaseWR = imd.LWeightReduction
  288.         local NewCapacity, NewReduction = GetTheoreticalStats(BaseCapacity,BaseWR,FakeUpgrades)
  289.        
  290.         if CurrentWeight <= NewCapacity then
  291.             return true
  292.         else
  293.             local Str = Round(CurrentWeight,2).."/"..Round(NewCapacity,2)
  294.             return false, string.format(getText("UI_LazoloTooFullToRemove"),Str)
  295.         end
  296.     end
  297. end
  298.  
  299. function OnMenuOptionSelected(Player, OnComplete, Bag, ItemInfo, JobType)
  300.     local ExtraItems = {}
  301.     if instanceof(ItemInfo,"InventoryItem") then --ItemInfo is a bag when adding an upgrade, making it an Inventory Item, ItemInfo is a string of the item type when removing upgrades.
  302.         local Needle, Thread = CheckForAndGetUpgradeItems(Player,true)
  303.         if not Needle then return false end
  304.         table.insert(ExtraItems,ItemInfo)
  305.         table.insert(ExtraItems,Needle)
  306.         table.insert(ExtraItems,Thread)
  307.        
  308.         if not Player:getInventory():contains(ItemInfo) then
  309.             ISTimedActionQueue.add(ISInventoryTransferAction:new(Player, ItemInfo, ItemInfo:getContainer(), Player:getInventory(), ItemInfo:getWeight()*60))
  310.         end
  311.     else
  312.         local Scissors = CheckForAndGetRemoveItems(Player, true)
  313.         if not Scissors then return end
  314.         local IsValid = RemoveValid(Bag,ItemInfo)
  315.         if not IsValid then return end
  316.         table.insert(ExtraItems,Scissors)
  317.     end
  318.     if Bag and not Player:getInventory():contains(Bag) then --make sure we have the bag and upgrade item if we dont already.
  319.         ISTimedActionQueue.add(ISInventoryTransferAction:new(Player, Bag, Bag:getContainer(), Player:getInventory(), Bag:getWeight()*50))
  320.     end
  321.    
  322.     ISTimedActionQueue.add(ISDynamicBackpacksAction:new(Player, OnComplete, Bag, ItemInfo, JobType, ExtraItems))
  323. end
  324.  
  325.  
  326. function OnInventoryContextMenu(playernum, Context, Items)
  327.     local Player = getSpecificPlayer(playernum)
  328.     for i,v in pairs(Items) do
  329.         local Item = v
  330.         if not instanceof(v,"InventoryItem") then
  331.             Item = v.items[1]
  332.         end
  333.        
  334.         local tags = Item:getTags()
  335.         for i=0, tags:size() - 1 do
  336.             print(tags:get(i))
  337.         end
  338.        
  339.         if ItemValid(Item) then -- player clicked on a bag
  340.             local imd = Item:getModData()
  341.            
  342.             if not imd.LDynamicBackpacksInit then
  343.                 InitBackpack(Item)
  344.             end
  345.            
  346.             if imd.LMaxUpgrades > 0 and #imd.LUpgrades < imd.LMaxUpgrades + math.floor(Player:getPerkLevel(Perks.Tailoring)/TailoringModifier) then
  347.                 local UpgradeItems = GetUpgradeItems(Player,{})
  348.                 local UpgradeMenu
  349.                 local Needle, Thread = CheckForAndGetUpgradeItems(Player, false)
  350.                 if #UpgradeItems > 0 then
  351.                     if Needle then
  352.                         for i2,v2 in pairs(UpgradeItems) do
  353.                             if not UpgradeMenu then
  354.                                 UpgradeMenu = ISContextMenu:getNew(Context)
  355.                                 Context:addSubMenu(Context:insertOptionBefore(getText("ContextMenu_Drop"),getText("UI_LazoloAddUpgrade")),UpgradeMenu)
  356.                             end
  357.                             --addOption(name, target, onSelect, ...)
  358.                             --onSelect(target, ...)
  359.                             UpgradeMenu:addOption(v2:getDisplayName(),Player,OnMenuOptionSelected,AddUpgrade,Item,v2,getText("UI_LazoloAddUpgrade"))
  360.                         end
  361.                     else
  362.                         local Option = Context:insertOptionBefore(getText("ContextMenu_Drop"),getText("UI_LazoloAddUpgrade"))
  363.                         local Tooltip = ISInventoryPaneContextMenu.addToolTip() -- this is such a mess to add tooltips jesus.
  364.                         Option.toolTip = Tooltip
  365.                         Tooltip.description = getText("UI_LazoloRequiresNeedleThread")
  366.                         Option.notAvailable = true
  367.                     end
  368.                 end
  369.             end
  370.            
  371.             --Context:insertOptionBefore(getText("ContextMenu_Drop"),"Break",Player,function() Item:setCapacity(5) end) -- used for testing the fix system.
  372.            
  373.             if #imd.LUpgrades >= 1 then -- add remove optoins.
  374.                
  375.                 local Scissors = CheckForAndGetRemoveItems(Player, false)
  376.                 if Scissors then
  377.                     local RemoveMenu
  378.                     RemoveMenu = ISContextMenu:getNew(Context)
  379.                     Context:addSubMenu(Context:insertOptionBefore(getText("ContextMenu_Drop"),getText("UI_LazoloRemoveUpgrade")),RemoveMenu)
  380.                    
  381.                     for i2,v2 in pairs(imd.LUpgrades) do
  382.                         local IsValid, Message = RemoveValid(Item,v2)
  383.                         if IsValid then
  384.                             RemoveMenu:addOption(getText("UI_"..v2),Player,OnMenuOptionSelected,RemoveUpgrade,Item,v2,getText("UI_LazoloRemoveUpgrade"))
  385.                         else
  386.                             local Option = RemoveMenu:addOption(getText("UI_"..v2))
  387.                             local Tooltip = ISInventoryPaneContextMenu:addToolTip()
  388.                             Option.toolTip = Tooltip
  389.                             Tooltip.description = Message
  390.                             Option.notAvailable = true
  391.                         end
  392.                     end
  393.                 else
  394.                     local Option = Context:insertOptionBefore(getText("ContextMenu_Drop"),getText("UI_LazoloRemoveUpgrade"))
  395.                     local Tooltip = ISInventoryPaneContextMenu.addToolTip()
  396.                     Option.toolTip = Tooltip
  397.                     if not KnivesCanRemove then
  398.                         Tooltip.description = getText("UI_LazoloRequiresScissors")
  399.                     else
  400.                         Tooltip.description = getText("UI_LazoloRequiresSharpItem")
  401.                     end
  402.                     Option.notAvailable = true
  403.                 end
  404.                
  405.                
  406.                 -- check if item needs updating
  407.                 if imd.LFixState ~= "Hide" then
  408.                     local UpgradedCapacity, UpgradedWeightReduction = GetUpgradedStats(Item)
  409.                     if UpgradedCapacity and UpgradedWeightReduction and (Item:getCapacity() ~= UpgradedCapacity or Item:getWeightReduction() ~= UpgradedWeightReduction) then
  410.                         if imd.LFixState == "Auto" then
  411.                             local OnceButton = Context:insertOptionBefore(getText("ContextMenu_Drop"),getText("UI_LazoloFixManual"),Item,UpdateBag)
  412.                             local Tooltip = ISInventoryPaneContextMenu.addToolTip()
  413.                             OnceButton.toolTip = Tooltip
  414.                             Tooltip.description = getText("UI_LazoloFixManualDesc").."\n"..string.format(getText("UI_LazoloExpectedStats"),tostring(UpgradedCapacity),tostring(UpgradedWeightReduction))
  415.                         else
  416.                             local UpdateMenu = ISContextMenu:getNew(Context)
  417.                             Context:addSubMenu(Context:insertOptionBefore(getText("ContextMenu_Drop"),getText("UI_LazoloFixUpgrades")),UpdateMenu)
  418.                            
  419.                             local OnceButton = UpdateMenu:addOption(getText("UI_LazoloFixOnce"),Item,UpdateBag)
  420.                             local Tooltip = ISInventoryPaneContextMenu.addToolTip()
  421.                             OnceButton.toolTip = Tooltip
  422.                             Tooltip.description = getText("UI_LazoloFixOnceDesc").."\n"..string.format(getText("UI_LazoloExpectedStats"),tostring(UpgradedCapacity),tostring(UpgradedWeightReduction))
  423.                            
  424.                             local AlwaysButton = UpdateMenu:addOption(getText("UI_LazoloFixAlways"),Item,function(Item)
  425.                                 UpdateBag(Item)
  426.                                 Item:getModData().LFixState = "Auto"
  427.                             end)
  428.                             local Tooltip = ISInventoryPaneContextMenu.addToolTip()
  429.                             AlwaysButton.toolTip = Tooltip
  430.                             Tooltip.description = getText("UI_LazoloFixAlwaysDesc")
  431.                            
  432.                             local NeverButton = UpdateMenu:addOption(getText("UI_LazoloFixNever"),Item,function(Item)
  433.                                 Item:getModData().LFixState = "Hide"
  434.                             end)
  435.                             local Tooltip = ISInventoryPaneContextMenu.addToolTip()
  436.                             NeverButton.toolTip = Tooltip
  437.                             Tooltip.description = getText("UI_LazoloFixNeverDesc")
  438.                         end
  439.                     end
  440.                 end
  441.                
  442.             end
  443.            
  444.             break
  445.         elseif UpgradeItemValues[Item:getType()] then --Player clicked on an upgrade
  446.             local UpgradeMenu
  447.             local Inventory = Player:getInventory()
  448.             local Needle, Thread = CheckForAndGetUpgradeItems(Player)
  449.             if Needle then
  450.                 for i = 0, Inventory:getItems():size() - 1 do
  451.                     local BagItem = Inventory:getItems():get(i);
  452.                     if BagItem and Item:getType() then
  453.                         if ItemValid(BagItem) then
  454.                             if not BagItem:getModData().LDynamicBackpacksInit then
  455.                                 InitBackpack(BagItem)
  456.                             end
  457.                             if BagItem:getModData().LMaxUpgrades > 0 and #BagItem:getModData().LUpgrades < BagItem:getModData().LMaxUpgrades + math.floor(Player:getPerkLevel(Perks.Tailoring)/TailoringModifier) then
  458.                                 if not UpgradeMenu then
  459.                                     UpgradeMenu = ISContextMenu:getNew(Context)
  460.                                     Context:addSubMenu(Context:insertOptionBefore(getText("ContextMenu_Drop"),getText("UI_LazoloUpgradeBag")),UpgradeMenu)
  461.                                 end
  462.                                 UpgradeMenu:addOption(BagItem:getDisplayName(),Player,OnMenuOptionSelected,AddUpgrade,BagItem,Item,getText("UI_LazoloAddUpgrade"))
  463.                             end
  464.                         end
  465.                     end
  466.                 end
  467.             else
  468.                 local Option = Context:insertOptionBefore(getText("ContextMenu_Drop"),getText("UI_LazoloAddUpgrade"))
  469.                 local Tooltip = ISInventoryPaneContextMenu.addToolTip()
  470.                 Option.toolTip = Tooltip
  471.                 Tooltip.description = getText("UI_LazoloRequiresNeedleThread")
  472.                 Option.notAvailable = true
  473.             end
  474.         end
  475.     end
  476. end
  477. function InvCheck()
  478.     local Inventory = getPlayer():getInventory()
  479.     for i = 0, Inventory:getItems():size() - 1 do
  480.         local Item = Inventory:getItems():get(i)
  481.         if Item and Item:IsInventoryContainer() and Item:getModData().LFixState and Item:getModData().LFixState == "Auto" then
  482.             local Capacity, Reduction = GetUpgradedStats(Item)
  483.             if Capacity and Reduction and (Item:getCapacity() ~= Capacity or Item:getWeightReduction() ~= Reduction) then
  484.                 UpdateBag(Item)
  485.                 --print("Auto Updating Bag")
  486.             end
  487.         end
  488.     end
  489. end
  490.  
  491. Events.OnFillInventoryObjectContextMenu.Add(OnInventoryContextMenu)
  492. Events.OnGameStart.Add(UpdateSandboxSettings)
  493. Events.EveryOneMinute.Add(InvCheck)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement