SHOW:
|
|
- or go back to the newest paste.
| 1 | Scriptname zzzContainerWeightCap extends ReferenceAlias | |
| 2 | ||
| 3 | - | Actor Property Playerref Auto |
| 3 | + | Actor Property PlayerRef Auto |
| 4 | Keyword Property VendorItemArrow Auto | |
| 5 | Float fMax | |
| 6 | Float fCurrent | |
| 7 | Bool bScanContainer | |
| 8 | ||
| 9 | string[] contweight_10 | |
| 10 | string[] contweight_25 | |
| 11 | string[] contweight_30 | |
| 12 | string[] contweight_50 | |
| 13 | string[] contweight_75 | |
| 14 | string[] contweight_100 | |
| 15 | string[] contweight_125 | |
| 16 | string[] contweight_150 | |
| 17 | string[] contweight_175 | |
| 18 | string[] contweight_200 | |
| 19 | string[] contweight_225 | |
| 20 | ||
| 21 | ||
| 22 | Event OnInit() | |
| 23 | InitializeArrays() | |
| 24 | RegisterForMenu("ContainerMenu")
| |
| 25 | EndEvent | |
| 26 | ||
| 27 | ||
| 28 | Event OnMenuOpen(String MenuName) | |
| 29 | If MenuName == "ContainerMenu" | |
| 30 | bScanContainer = True | |
| 31 | EndIf | |
| 32 | EndEvent | |
| 33 | ||
| 34 | ||
| 35 | Event OnMenuClose(String MenuName) | |
| 36 | If MenuName == "ContainerMenu" | |
| 37 | bScanContainer = False | |
| 38 | fCurrent = 0.0 | |
| 39 | EndIf | |
| 40 | EndEvent | |
| 41 | ||
| 42 | ||
| 43 | Event OnItemAdded(Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akSourceContainer) | |
| 44 | WeightChange(False, akBaseItem, aiItemCount, akItemReference, akSourceContainer) | |
| 45 | endEvent | |
| 46 | ||
| 47 | ||
| 48 | Event OnItemRemoved(Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akDestContainer) | |
| 49 | WeightChange(True, akBaseItem, aiItemCount, akItemReference, akDestContainer) | |
| 50 | endEvent | |
| 51 | ||
| 52 | ||
| 53 | Function WeightChange(Bool akAdded, Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akContainer) | |
| 54 | ; 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 | |
| 55 | ||
| 56 | Float fItemWeight | |
| 57 | ||
| 58 | If ( UI.IsMenuOpen("ContainerMenu") && akContainer != None && akContainer as Actor == None )
| |
| 59 | ||
| 60 | ;Check to see if this is the first item to be handled since container was opened | |
| 61 | ;If so, get the expected maximum weight, and current weight of the container | |
| 62 | If ( bScanContainer == True ) | |
| 63 | fMax = getMaxWeight(akContainer) | |
| 64 | - | fCurrent = weighContentsIn(akContainer) |
| 64 | + | fCurrent = weighContentsIn(akContainer) ;Will return current weight with new item(s) added/removed, NOT weight before |
| 65 | bScanContainer = False | |
| 66 | endIf | |
| 67 | ||
| 68 | ;Allow for the fact that arrows have no weight, and calculate item weight * number of items | |
| 69 | If ( akBaseItem.HasKeyword(VendorItemArrow) == 1 ) | |
| 70 | fItemWeight = 0.1*aiItemCount | |
| 71 | else | |
| 72 | fItemWeight = akBaseItem.GetWeight()*aiItemCount | |
| 73 | endIf | |
| 74 | - | |
| 74 | + | |
| 75 | If akAdded ;Item was placed into a container by the player | |
| 76 | ||
| 77 | ; Artificially adjust current weight if arrows were added | |
| 78 | - | ;back to the player if it would be too heavy for the container. |
| 78 | + | If ( akBaseItem.HasKeyword(VendorItemArrow) == 1 ) |
| 79 | - | ;Or, if the item will fit, add the item weight to the stored current weight of the container |
| 79 | + | fCurrent += fItemWeight |
| 80 | - | If ( fMax <= fCurrent + fItemWeight ) |
| 80 | + | endIF |
| 81 | - | akContainer.RemoveItem(akItemReference, aiItemCount, True, Playerref) |
| 81 | + | |
| 82 | ;Compare the max allowed container weight with the current weight + item weight, and give the item | |
| 83 | ;back to the player if it would be too heavy for the container, reducing weight appropriately. | |
| 84 | - | Else |
| 84 | + | If ( fCurrent > fMax ) |
| 85 | - | fCurrent += fItemWeight |
| 85 | + | If ( akItemReference != None ) |
| 86 | akContainer.RemoveItem(akItemReference, aiItemCount, True, PlayerRef) | |
| 87 | Else | |
| 88 | - | else ;Item was removed from a container by the player, so subtract the item weight from the stored |
| 88 | + | akContainer.RemoveItem(akBaseItem, aiItemCount, True, PlayerRef) |
| 89 | - | ;current weight of the container |
| 89 | + | endIf |
| 90 | - | fCurrent -= fItemWeight |
| 90 | + | fCurrent -= fItemWeight |
| 91 | Debug.Notification("This won't fit.")
| |
| 92 | Debug.Notification("Current weight in container: " + fCurrent as Int + " of " + fMax as Int)
| |
| 93 | endIf | |
| 94 | ||
| 95 | else ;Item was removed from a container by the player. Artificially adjust current weight only if arrows were removed | |
| 96 | If ( akBaseItem.HasKeyword(VendorItemArrow) == 1 ) | |
| 97 | fCurrent -= fItemWeight | |
| 98 | endIF | |
| 99 | endIf | |
| 100 | endIf | |
| 101 | endFunction | |
| 102 | ||
| 103 | ||
| 104 | Function InitializeArrays() | |
| 105 | ;Set total in [] if adding to a list | |
| 106 | ||
| 107 | contweight_10 = new string[1] | |
| 108 | contweight_10[0] = "Clutter\\Containers\\Satchel.nif" | |
| 109 | ||
| 110 | contweight_25 = new string[4] | |
| 111 | contweight_25[0] = "Clutter\\Containers\\MiscSackSmall.nif" | |
| 112 | contweight_25[1] = "Clutter\\Containers\\MiscSack02Small.nif" | |
| 113 | contweight_25[2] = "Clutter\\Containers\\MiscSack02SmallFlat.nif" | |
| 114 | contweight_25[3] = "Clutter\\Common\\StrongBox01.nif" | |
| 115 | ||
| 116 | contweight_30 = new string[2] | |
| 117 | contweight_30[0] = "Clutter\\WoodFires\\SpitPotClosedLoose01.nif" | |
| 118 | contweight_30[1] = "Clutter\\WoodFires\\SpitPotClosed01.nif" | |
| 119 | ||
| 120 | contweight_50 = new string[6] | |
| 121 | contweight_50[0] = "Architecture\\WhiteRun\\WRClutter\\WRBurialUrn01.nif" | |
| 122 | contweight_50[1] = "Clutter\\Sack01.NIF" | |
| 123 | contweight_50[2] = "Clutter\\SBurialUrn01.nif" | |
| 124 | contweight_50[3] = "Clutter\\Containers\\MiscPouch.nif" | |
| 125 | contweight_50[4] = "Clutter\\Ruins\\RuinsCanopicJar01.nif" | |
| 126 | contweight_50[5] = "Clutter\\Ruins\\RuinsCanopicJar02.nif" | |
| 127 | ||
| 128 | contweight_75 = new string[8] | |
| 129 | contweight_75[0] = "Clutter\\Containers\\MiscSackLarge.nif" | |
| 130 | contweight_75[1] = "Clutter\\Containers\\MiscSackLargeFlat01.nif" | |
| 131 | contweight_75[2] = "Clutter\\Containers\\MiscSackLargeFlat02.nif" | |
| 132 | contweight_75[3] = "Clutter\\Containers\\MiscSackLargeFlat03.nif" | |
| 133 | contweight_75[4] = "Clutter\\Containers\\MiscSack02Large.nif" | |
| 134 | contweight_75[5] = "Clutter\\Containers\\MiscSack02LargeFlat.nif" | |
| 135 | contweight_75[6] = "Effects\\FXSpiderWebKitSkeeverDinner.nif" | |
| 136 | contweight_75[7] = "Effects\\FXSpiderWebKitDinner.nif" | |
| 137 | ||
| 138 | contweight_100 = new string[6] | |
| 139 | contweight_100[0] = "Clutter\\Common\\EndTable01.nif" | |
| 140 | contweight_100[1] = "Clutter\\Ruins\\RuinsLargeUrnWithStand01.nif" | |
| 141 | contweight_100[2] = "Clutter\\Upperclass\\UpperEndTable01.nif" | |
| 142 | contweight_100[3] = "Furniture\\Noble\\NobleNightTable01.nif" | |
| 143 | contweight_100[4] = "Furniture\\OrcFurniture\\OrcEndTable01.nif" | |
| 144 | contweight_100[5] = "_BYOH\\Furniture\\BYOHUpperEndTable02.nif" | |
| 145 | ||
| 146 | contweight_125 = new string[27] | |
| 147 | contweight_125[0] = "Architecture\\WhiteRun\\WRClutter\\WRCoffin01.nif" | |
| 148 | contweight_125[1] = "Architecture\\Riften\\Clutter\\RTCoffin01.nif" | |
| 149 | contweight_125[2] = "Clutter\\Barrel01.NIF" | |
| 150 | contweight_125[3] = "Clutter\\Common\\Cupboard01.nif" | |
| 151 | contweight_125[4] = "Clutter\\Common\\Dresser01.nif" | |
| 152 | contweight_125[5] = "Clutter\\Common\\Wardrobe01.nif" | |
| 153 | contweight_125[6] = "Clutter\\Common\\CommonCoffin01.nif" | |
| 154 | contweight_125[7] = "Clutter\\Containers\\SafeandLock01.nif" | |
| 155 | contweight_125[8] = "Clutter\\Dwemer\\DweDresser01.nif" | |
| 156 | contweight_125[9] = "Clutter\\Sovngarde\\SovBarrel01.nif" | |
| 157 | contweight_125[10] = "Clutter\\Upperclass\\UpperCupboard.nif" | |
| 158 | contweight_125[11] = "Clutter\\Upperclass\\UpperDresser01.nif" | |
| 159 | contweight_125[12] = "Clutter\\Upperclass\\UpperWardrobe01.nif" | |
| 160 | contweight_125[13] = "Clutter\\Windhelm\\WHcoffin01.nif" | |
| 161 | contweight_125[14] = "Dungeons\\Dwemer\\Clutter\\MrkCryptCoffin01container.nif" | |
| 162 | contweight_125[15] = "Dungeons\\Dwemer\\Clutter\\MrkCryptCoffin02container.nif" | |
| 163 | contweight_125[16] = "Furniture\\OrcFurniture\\OrcDresser01.nif" | |
| 164 | contweight_125[17] = "Dungeons\\Dwemer\\Clutter\\MrkCryptCoffin01container.nif" | |
| 165 | contweight_125[18] = "Dungeons\\Dwemer\\Clutter\\MrkCryptCoffin02container.nif" | |
| 166 | contweight_125[19] = "Furniture\\OrcFurniture\\OrcDresser01.nif" | |
| 167 | contweight_125[20] = "Furniture\\Noble\\NobleChestDrawers01.nif" | |
| 168 | contweight_125[21] = "Furniture\\Noble\\NobleChestDrawers02.nif" | |
| 169 | contweight_125[22] = "Furniture\\Noble\\NobleWardrobe01.nif" | |
| 170 | contweight_125[23] = "Furniture\\Noble\\SCoffin.nif" | |
| 171 | contweight_125[24] = "Furniture\\Noble\\SCoffinPoor.nif" | |
| 172 | contweight_125[25] = "DLC02\\Dungeons\\Apocrypha\\Animated\\ApoUrn\\ApoUrn01.nif" | |
| 173 | contweight_125[26] = "DLC02\\Clutter\\DLC2DarkElfUrn01.nif" | |
| 174 | ||
| 175 | contweight_150 = new string[2] | |
| 176 | contweight_150[0] = "Clutter\\Dwemer\\DweContainter02.nif" | |
| 177 | contweight_150[1] = "DLC02\\Dungeons\\Apocrypha\\Animated\\ApoUrn\\ApoUrn02.nif" | |
| 178 | ||
| 179 | contweight_175 = new string[2] | |
| 180 | contweight_175[0] = "Clutter\\Ruins\\Ruins_SmallChest.nif" | |
| 181 | contweight_175[1] = "DLC02\\Architecture\\Riekling\\DLC2RieklingTent01.nif" | |
| 182 | ||
| 183 | contweight_200 = new string[6] | |
| 184 | contweight_200[0] = "Clutter\\Containers\\Chest01\\Chest01.nif" | |
| 185 | contweight_200[1] = "Clutter\\Falmer\\FalmerContainer.nif" | |
| 186 | contweight_200[2] = "Clutter\\Upperclass\\UpperChest01.nif" | |
| 187 | contweight_200[3] = "DLC01\\Clutter\\DLC01SnowElfChest.nif" | |
| 188 | contweight_200[4] = "DLC01\\SoulCairn\\sc_chest.nif" | |
| 189 | contweight_200[5] = "DLC01\\SoulCairn\\sc_chest02.nif" | |
| 190 | ||
| 191 | contweight_225 = new string[5] | |
| 192 | contweight_225[0] = "Clutter\\Dwemer\\DweChest01.nif" | |
| 193 | contweight_225[1] = "Clutter\\Dwemer\\DweContainer01.nif" | |
| 194 | contweight_225[2] = "Clutter\\Falmer\\FalmerContainer02.nif" | |
| 195 | contweight_225[3] = "Clutter\\Ruins\\Ruins_LargeChest.nif" | |
| 196 | contweight_225[4] = "Furniture\\Noble\\NobleChest01.nif" | |
| 197 | endFunction | |
| 198 | ||
| 199 | ||
| 200 | Float Function getMaxWeight(ObjectReference oSourceContainer) | |
| 201 | ; Decide the max weight of the container | |
| 202 | ||
| 203 | string sModelPath = oSourceContainer.GetBaseObject().GetWorldModelPath() | |
| 204 | ||
| 205 | If contweight_10.Find(sModelPath) != -1 | |
| 206 | return 10.0 | |
| 207 | ElseIf contweight_25.Find(sModelPath) != -1 | |
| 208 | return 25.0 | |
| 209 | ElseIf contweight_30.Find(sModelPath) != -1 | |
| 210 | return 30.0 | |
| 211 | ElseIf contweight_50.Find(sModelPath) != -1 | |
| 212 | return 50.0 | |
| 213 | ElseIf contweight_75.Find(sModelPath) != -1 | |
| 214 | return 75.0 | |
| 215 | ElseIf contweight_100.Find(sModelPath) != -1 | |
| 216 | return 100.0 | |
| 217 | ElseIf contweight_125.Find(sModelPath) != -1 | |
| 218 | return 125.0 | |
| 219 | ElseIf contweight_150.Find(sModelPath) != -1 | |
| 220 | return 150.0 | |
| 221 | ElseIf contweight_175.Find(sModelPath) != -1 | |
| 222 | return 175.0 | |
| 223 | ElseIf contweight_200.Find(sModelPath) != -1 | |
| 224 | return 200.0 | |
| 225 | ElseIf contweight_225.Find(sModelPath) != -1 | |
| 226 | return 225.0 | |
| 227 | Else | |
| 228 | return 150.0 | |
| 229 | EndIf | |
| 230 | endFunction | |
| 231 | - | iTotal += kForm.GetWeight() |
| 231 | + | |
| 232 | ||
| 233 | Float Function weighContentsIn(ObjectReference akContainer) | |
| 234 | Float iTotal | |
| 235 | ||
| 236 | Int iFormIndex = akContainer.GetNumItems() | |
| 237 | While iFormIndex > 0 | |
| 238 | iFormIndex -= 1 | |
| 239 | Form kForm = akContainer.GetNthForm(iFormIndex) | |
| 240 | ||
| 241 | ;Allow for the fact that arrows have no weight, and calculate item weight * number of items | |
| 242 | If ( kForm.HasKeyword(VendorItemArrow) == 1 ) | |
| 243 | iTotal += akContainer.GetItemCount(kForm) * 0.1 | |
| 244 | else | |
| 245 | iTotal += akContainer.GetItemCount(kForm) * kForm.GetWeight() | |
| 246 | endIf | |
| 247 | ||
| 248 | EndWhile | |
| 249 | Return iTotal | |
| 250 | endFunction |