Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Scriptname zzzContainerWeightCap extends ReferenceAlias
- Actor Property PlayerRef Auto
- Keyword Property VendorItemArrow Auto
- Float fMax
- Float fCurrent
- Bool bScanContainer
- string[] contweight_10
- string[] contweight_25
- string[] contweight_30
- string[] contweight_50
- string[] contweight_75
- string[] contweight_100
- string[] contweight_125
- string[] contweight_150
- string[] contweight_175
- string[] contweight_200
- string[] contweight_225
- Event OnInit()
- InitializeArrays()
- RegisterForMenu("ContainerMenu")
- EndEvent
- Event OnMenuOpen(String MenuName)
- If MenuName == "ContainerMenu"
- bScanContainer = True
- EndIf
- EndEvent
- Event OnMenuClose(String MenuName)
- If MenuName == "ContainerMenu"
- bScanContainer = False
- fCurrent = 0.0
- EndIf
- EndEvent
- Event OnItemAdded(Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akSourceContainer)
- WeightChange(False, akBaseItem, aiItemCount, akItemReference, akSourceContainer)
- endEvent
- Event OnItemRemoved(Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akDestContainer)
- WeightChange(True, akBaseItem, aiItemCount, akItemReference, akDestContainer)
- endEvent
- Function WeightChange(Bool akAdded, Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akContainer)
- ; akAdded will be TRUE if an item has been added to a container, and FALSE if the player has retrieved an item from a container
- Float fItemWeight
- If ( UI.IsMenuOpen("ContainerMenu") && akContainer != None && akContainer as Actor == None )
- ;Check to see if this is the first item to be handled since container was opened
- ;If so, get the expected maximum weight, and current weight of the container
- If ( bScanContainer == True )
- fMax = getMaxWeight(akContainer)
- fCurrent = weighContentsIn(akContainer) ;Will return current weight with new item(s) added/removed, NOT weight before
- bScanContainer = False
- endIf
- ;Allow for the fact that arrows have no weight, and calculate item weight * number of items
- If ( akBaseItem.HasKeyword(VendorItemArrow) == 1 )
- fItemWeight = 0.1*aiItemCount
- else
- fItemWeight = akBaseItem.GetWeight()*aiItemCount
- endIf
- If akAdded ;Item was placed into a container by the player
- ; Artificially adjust current weight if arrows were added
- If ( akBaseItem.HasKeyword(VendorItemArrow) == 1 )
- fCurrent += fItemWeight
- endIF
- ;Compare the max allowed container weight with the current weight + item weight, and give the item
- ;back to the player if it would be too heavy for the container, reducing weight appropriately.
- If ( fCurrent > fMax )
- If ( akItemReference != None )
- akContainer.RemoveItem(akItemReference, aiItemCount, True, PlayerRef)
- Else
- akContainer.RemoveItem(akBaseItem, aiItemCount, True, PlayerRef)
- endIf
- fCurrent -= fItemWeight
- Debug.Notification("This won't fit.")
- Debug.Notification("Current weight in container: " + fCurrent as Int + " of " + fMax as Int)
- endIf
- else ;Item was removed from a container by the player. Artificially adjust current weight only if arrows were removed
- If ( akBaseItem.HasKeyword(VendorItemArrow) == 1 )
- fCurrent -= fItemWeight
- endIF
- endIf
- endIf
- endFunction
- Function InitializeArrays()
- ;Set total in [] if adding to a list
- contweight_10 = new string[1]
- contweight_10[0] = "Clutter\\Containers\\Satchel.nif"
- contweight_25 = new string[4]
- contweight_25[0] = "Clutter\\Containers\\MiscSackSmall.nif"
- contweight_25[1] = "Clutter\\Containers\\MiscSack02Small.nif"
- contweight_25[2] = "Clutter\\Containers\\MiscSack02SmallFlat.nif"
- contweight_25[3] = "Clutter\\Common\\StrongBox01.nif"
- contweight_30 = new string[2]
- contweight_30[0] = "Clutter\\WoodFires\\SpitPotClosedLoose01.nif"
- contweight_30[1] = "Clutter\\WoodFires\\SpitPotClosed01.nif"
- contweight_50 = new string[6]
- contweight_50[0] = "Architecture\\WhiteRun\\WRClutter\\WRBurialUrn01.nif"
- contweight_50[1] = "Clutter\\Sack01.NIF"
- contweight_50[2] = "Clutter\\SBurialUrn01.nif"
- contweight_50[3] = "Clutter\\Containers\\MiscPouch.nif"
- contweight_50[4] = "Clutter\\Ruins\\RuinsCanopicJar01.nif"
- contweight_50[5] = "Clutter\\Ruins\\RuinsCanopicJar02.nif"
- contweight_75 = new string[8]
- contweight_75[0] = "Clutter\\Containers\\MiscSackLarge.nif"
- contweight_75[1] = "Clutter\\Containers\\MiscSackLargeFlat01.nif"
- contweight_75[2] = "Clutter\\Containers\\MiscSackLargeFlat02.nif"
- contweight_75[3] = "Clutter\\Containers\\MiscSackLargeFlat03.nif"
- contweight_75[4] = "Clutter\\Containers\\MiscSack02Large.nif"
- contweight_75[5] = "Clutter\\Containers\\MiscSack02LargeFlat.nif"
- contweight_75[6] = "Effects\\FXSpiderWebKitSkeeverDinner.nif"
- contweight_75[7] = "Effects\\FXSpiderWebKitDinner.nif"
- contweight_100 = new string[6]
- contweight_100[0] = "Clutter\\Common\\EndTable01.nif"
- contweight_100[1] = "Clutter\\Ruins\\RuinsLargeUrnWithStand01.nif"
- contweight_100[2] = "Clutter\\Upperclass\\UpperEndTable01.nif"
- contweight_100[3] = "Furniture\\Noble\\NobleNightTable01.nif"
- contweight_100[4] = "Furniture\\OrcFurniture\\OrcEndTable01.nif"
- contweight_100[5] = "_BYOH\\Furniture\\BYOHUpperEndTable02.nif"
- contweight_125 = new string[27]
- contweight_125[0] = "Architecture\\WhiteRun\\WRClutter\\WRCoffin01.nif"
- contweight_125[1] = "Architecture\\Riften\\Clutter\\RTCoffin01.nif"
- contweight_125[2] = "Clutter\\Barrel01.NIF"
- contweight_125[3] = "Clutter\\Common\\Cupboard01.nif"
- contweight_125[4] = "Clutter\\Common\\Dresser01.nif"
- contweight_125[5] = "Clutter\\Common\\Wardrobe01.nif"
- contweight_125[6] = "Clutter\\Common\\CommonCoffin01.nif"
- contweight_125[7] = "Clutter\\Containers\\SafeandLock01.nif"
- contweight_125[8] = "Clutter\\Dwemer\\DweDresser01.nif"
- contweight_125[9] = "Clutter\\Sovngarde\\SovBarrel01.nif"
- contweight_125[10] = "Clutter\\Upperclass\\UpperCupboard.nif"
- contweight_125[11] = "Clutter\\Upperclass\\UpperDresser01.nif"
- contweight_125[12] = "Clutter\\Upperclass\\UpperWardrobe01.nif"
- contweight_125[13] = "Clutter\\Windhelm\\WHcoffin01.nif"
- contweight_125[14] = "Dungeons\\Dwemer\\Clutter\\MrkCryptCoffin01container.nif"
- contweight_125[15] = "Dungeons\\Dwemer\\Clutter\\MrkCryptCoffin02container.nif"
- contweight_125[16] = "Furniture\\OrcFurniture\\OrcDresser01.nif"
- contweight_125[17] = "Dungeons\\Dwemer\\Clutter\\MrkCryptCoffin01container.nif"
- contweight_125[18] = "Dungeons\\Dwemer\\Clutter\\MrkCryptCoffin02container.nif"
- contweight_125[19] = "Furniture\\OrcFurniture\\OrcDresser01.nif"
- contweight_125[20] = "Furniture\\Noble\\NobleChestDrawers01.nif"
- contweight_125[21] = "Furniture\\Noble\\NobleChestDrawers02.nif"
- contweight_125[22] = "Furniture\\Noble\\NobleWardrobe01.nif"
- contweight_125[23] = "Furniture\\Noble\\SCoffin.nif"
- contweight_125[24] = "Furniture\\Noble\\SCoffinPoor.nif"
- contweight_125[25] = "DLC02\\Dungeons\\Apocrypha\\Animated\\ApoUrn\\ApoUrn01.nif"
- contweight_125[26] = "DLC02\\Clutter\\DLC2DarkElfUrn01.nif"
- contweight_150 = new string[2]
- contweight_150[0] = "Clutter\\Dwemer\\DweContainter02.nif"
- contweight_150[1] = "DLC02\\Dungeons\\Apocrypha\\Animated\\ApoUrn\\ApoUrn02.nif"
- contweight_175 = new string[2]
- contweight_175[0] = "Clutter\\Ruins\\Ruins_SmallChest.nif"
- contweight_175[1] = "DLC02\\Architecture\\Riekling\\DLC2RieklingTent01.nif"
- contweight_200 = new string[6]
- contweight_200[0] = "Clutter\\Containers\\Chest01\\Chest01.nif"
- contweight_200[1] = "Clutter\\Falmer\\FalmerContainer.nif"
- contweight_200[2] = "Clutter\\Upperclass\\UpperChest01.nif"
- contweight_200[3] = "DLC01\\Clutter\\DLC01SnowElfChest.nif"
- contweight_200[4] = "DLC01\\SoulCairn\\sc_chest.nif"
- contweight_200[5] = "DLC01\\SoulCairn\\sc_chest02.nif"
- contweight_225 = new string[5]
- contweight_225[0] = "Clutter\\Dwemer\\DweChest01.nif"
- contweight_225[1] = "Clutter\\Dwemer\\DweContainer01.nif"
- contweight_225[2] = "Clutter\\Falmer\\FalmerContainer02.nif"
- contweight_225[3] = "Clutter\\Ruins\\Ruins_LargeChest.nif"
- contweight_225[4] = "Furniture\\Noble\\NobleChest01.nif"
- endFunction
- Float Function getMaxWeight(ObjectReference oSourceContainer)
- ; Decide the max weight of the container
- string sModelPath = oSourceContainer.GetBaseObject().GetWorldModelPath()
- If contweight_10.Find(sModelPath) != -1
- return 10.0
- ElseIf contweight_25.Find(sModelPath) != -1
- return 25.0
- ElseIf contweight_30.Find(sModelPath) != -1
- return 30.0
- ElseIf contweight_50.Find(sModelPath) != -1
- return 50.0
- ElseIf contweight_75.Find(sModelPath) != -1
- return 75.0
- ElseIf contweight_100.Find(sModelPath) != -1
- return 100.0
- ElseIf contweight_125.Find(sModelPath) != -1
- return 125.0
- ElseIf contweight_150.Find(sModelPath) != -1
- return 150.0
- ElseIf contweight_175.Find(sModelPath) != -1
- return 175.0
- ElseIf contweight_200.Find(sModelPath) != -1
- return 200.0
- ElseIf contweight_225.Find(sModelPath) != -1
- return 225.0
- Else
- return 150.0
- EndIf
- endFunction
- Float Function weighContentsIn(ObjectReference akContainer)
- Float iTotal
- Int iFormIndex = akContainer.GetNumItems()
- While iFormIndex > 0
- iFormIndex -= 1
- Form kForm = akContainer.GetNthForm(iFormIndex)
- ;Allow for the fact that arrows have no weight, and calculate item weight * number of items
- If ( kForm.HasKeyword(VendorItemArrow) == 1 )
- iTotal += akContainer.GetItemCount(kForm) * 0.1
- else
- iTotal += akContainer.GetItemCount(kForm) * kForm.GetWeight()
- endIf
- EndWhile
- Return iTotal
- endFunction
Add Comment
Please, Sign In to add comment