plaguehush

Untitled

May 27th, 2016
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.04 KB | None | 0 0
  1. Scriptname zzzContainerWeightCap extends Actor
  2.  
  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, akContainer)
  45. endEvent
  46.  
  47.  
  48. Event OnItemRemoved(Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akDestContainer)
  49. WeightChange(True, akBaseItem, aiItemCount, akItemReference, akContainer)
  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)
  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. elseIf
  72. fItemWeight = akBaseItem.GetWeight()*aiItemCount
  73. endIf
  74.  
  75. If akAdded ;Item was placed into a container by the player
  76.  
  77. ;Compare the max allowed container weight with the current weight + item weight, and give the item
  78. ;back to the player if it would be too heavy for the container.
  79. ;Or, if the item will fit, add the item weight to the stored current weight of the container
  80. If ( fMax <= fCurrent + fItemWeight )
  81. akContainer.RemoveItem(akItemReference, aiItemCount, PlayerRef)
  82. Debug.Notification("This item won't fit.")
  83. Debug.Notification("Current weight in container: " + fCurrent as Int + " of " + fMax as Int)
  84. Else
  85. fCurrent += fItemWeight
  86. endIf
  87.  
  88. else ;Item was removed from a container by the player, so subtract the item weight from the stored
  89. ;current weight of the container
  90. fCurrent -= fItemWeight
  91. endIf
  92. endIf
  93. endFunction
  94.  
  95.  
  96. Function InitializeArrays()
  97. ;Set total in [] if adding to a list
  98.  
  99. contweight_10 = new string[1]
  100. contweight_10[0] = "Clutter\\Containers\\Satchel.nif"
  101.  
  102. contweight_25 = new string[4]
  103. contweight_25[0] = "Clutter\\Containers\\MiscSackSmall.nif"
  104. contweight_25[1] = "Clutter\\Containers\\MiscSack02Small.nif"
  105. contweight_25[2] = "Clutter\\Containers\\MiscSack02SmallFlat.nif"
  106. contweight_25[3] = "Clutter\\Common\\StrongBox01.nif"
  107.  
  108. contweight_30 = new string[2]
  109. contweight_30[0] = "Clutter\\WoodFires\\SpitPotClosedLoose01.nif"
  110. contweight_30[1] = "Clutter\\WoodFires\\SpitPotClosed01.nif"
  111.  
  112. contweight_50 = new string[6]
  113. contweight_50[0] = "Architecture\\WhiteRun\\WRClutter\\WRBurialUrn01.nif"
  114. contweight_50[1] = "Clutter\\Sack01.NIF"
  115. contweight_50[2] = "Clutter\\SBurialUrn01.nif"
  116. contweight_50[3] = "Clutter\\Containers\\MiscPouch.nif"
  117. contweight_50[4] = "Clutter\\Ruins\\RuinsCanopicJar01.nif"
  118. contweight_50[5] = "Clutter\\Ruins\\RuinsCanopicJar02.nif"
  119.  
  120. contweight_75 = new string[8]
  121. contweight_75[0] = "Clutter\\Containers\\MiscSackLarge.nif"
  122. contweight_75[1] = "Clutter\\Containers\\MiscSackLargeFlat01.nif"
  123. contweight_75[2] = "Clutter\\Containers\\MiscSackLargeFlat02.nif"
  124. contweight_75[3] = "Clutter\\Containers\\MiscSackLargeFlat03.nif"
  125. contweight_75[4] = "Clutter\\Containers\\MiscSack02Large.nif"
  126. contweight_75[5] = "Clutter\\Containers\\MiscSack02LargeFlat.nif"
  127. contweight_75[6] = "Effects\\FXSpiderWebKitSkeeverDinner.nif"
  128. contweight_75[7] = "Effects\\FXSpiderWebKitDinner.nif"
  129.  
  130. contweight_100 = new string[6]
  131. contweight_100[0] = "Clutter\\Common\\EndTable01.nif"
  132. contweight_1006[1] = "Clutter\\Ruins\\RuinsLargeUrnWithStand01.nif"
  133. contweight_100[2] = "Clutter\\Upperclass\\UpperEndTable01.nif"
  134. contweight_100[3] = "Furniture\\Noble\\NobleNightTable01.nif"
  135. contweight_100[4] = "Furniture\\OrcFurniture\\OrcEndTable01.nif"
  136. contweight_100[5] = "_BYOH\\Furniture\\BYOHUpperEndTable02.nif"
  137.  
  138. contweight_125 = new string[27]
  139. contweight_125[0] = "Architecture\\WhiteRun\\WRClutter\\WRCoffin01.nif"
  140. contweight_125[1] = "Architecture\\Riften\Clutter\\RTCoffin01.nif"
  141. contweight_125[2] = "Clutter\\Barrel01.NIF"
  142. contweight_125[3] = "Clutter\\Common\\Cupboard01.nif"
  143. contweight_125[4] = "Clutter\\Common\\Dresser01.nif"
  144. contweight_125[5] = "Clutter\\Common\\Wardrobe01.nif"
  145. contweight_125[6] = "Clutter\\Common\\CommonCoffin01.nif"
  146. contweight_125[7] = "Clutter\\Containers\\SafeandLock01.nif"
  147. contweight_125[8] = "Clutter\\Dwemer\\DweDresser01.nif"
  148. contweight_125[9] = "Clutter\\Sovngarde\\SovBarrel01.nif"
  149. contweight_125[10] = "Clutter\\Upperclass\\UpperCupboard.nif"
  150. contweight_125[11] = "Clutter\\Upperclass\\UpperDresser01.nif"
  151. contweight_125[12] = "Clutter\\Upperclass\\UpperWardrobe01.nif"
  152. contweight_125[13] = "Clutter\\Windhelm\\WHcoffin01.nif"
  153. contweight_125[14] = "Dungeons\\Dwemer\\Clutter\\MrkCryptCoffin01container.nif"
  154. contweight_125[15] = "Dungeons\\Dwemer\\Clutter\\MrkCryptCoffin02container.nif"
  155. contweight_125[16] = "Furniture\\OrcFurniture\\OrcDresser01.nif"
  156. contweight_125[17] = "Dungeons\\Dwemer\\Clutter\\MrkCryptCoffin01container.nif"
  157. contweight_125[18] = "Dungeons\\Dwemer\\Clutter\\MrkCryptCoffin02container.nif"
  158. contweight_125[19] = "Furniture\\OrcFurniture\\OrcDresser01.nif"
  159. contweight_125[20] = "Furniture\\Noble\\NobleChestDrawers01.nif"
  160. contweight_125[21] = "Furniture\\Noble\\NobleChestDrawers02.nif"
  161. contweight_125[22] = "Furniture\\Noble\\NobleWardrobe01.nif"
  162. contweight_125[23] = "Furniture\\Noble\\SCoffin.nif"
  163. contweight_125[24] = "Furniture\\Noble\\SCoffinPoor.nif"
  164. contweight_125[25] = "DLC02\\Dungeons\\Apocrypha\\Animated\\ApoUrn\\ApoUrn01.nif"
  165. contweight_125[26] = "DLC02\\Clutter\\DLC2DarkElfUrn01.nif"
  166.  
  167. contweight_150 = new string[2]
  168. contweight_150[0] = "Clutter\\Dwemer\\DweContainter02.nif"
  169. contweight_150[1] = "DLC02\\Dungeons\\Apocrypha\\Animated\\ApoUrn\\ApoUrn02.nif"
  170.  
  171. contweight_175 = new string[2]
  172. contweight_175[0] = "Clutter\\Ruins\\Ruins_SmallChest.nif"
  173. contweight_175[1] = "DLC02\\Architecture\\Riekling\\DLC2RieklingTent01.nif"
  174.  
  175. contweight_200 = new string[6]
  176. contweight_200[0] = "Clutter\\Containers\\Chest01\\Chest01.nif"
  177. contweight_200[1] = "Clutter\\Falmer\\FalmerContainer.nif"
  178. contweight_200[2] = "Clutter\\Upperclass\\UpperChest01.nif"
  179. contweight_200[3] = "DLC01\\Clutter\\DLC01SnowElfChest.nif"
  180. contweight_200[4] = "DLC01\\SoulCairn\\sc_chest.nif"
  181. contweight_200[5] = "DLC01\\SoulCairn\\sc_chest02.nif"
  182.  
  183. contweight_225 = new string[5]
  184. contweight_225[0] = "Clutter\\Dwemer\\DweChest01.nif"
  185. contweight_225[1] = "Clutter\\Dwemer\\DweContainer01.nif"
  186. contweight_225[2] = "Clutter\\Falmer\\FalmerContainer02.nif"
  187. contweight_225[3] = "Clutter\\Ruins\\Ruins_LargeChest.nif"
  188. contweight_225[4] = "Furniture\\Noble\\NobleChest01.nif"
  189. endFunction
  190.  
  191.  
  192. Float Function getMaxWeight(ObjectReference oSourceContainer) Global
  193. ; Decide the max weight of the container
  194.  
  195. string sModelPath = oSourceContainer.GetBaseObject().GetWorldModelPath()
  196.  
  197. If contweight_10.Find(sModelPath) != -1
  198. return 10.0
  199. ElseIf contweight_25.Find(sModelPath) != -1
  200. return 25.0
  201. ElseIf contweight_30.Find(sModelPath) != -1
  202. return 30.0
  203. ElseIf contweight_50.Find(sModelPath) != -1
  204. return 50.0
  205. ElseIf contweight_75.Find(sModelPath) != -1
  206. return 75.0
  207. ElseIf contweight_100.Find(sModelPath) != -1
  208. return 100.0
  209. ElseIf contweight_125.Find(sModelPath) != -1
  210. return 125.0
  211. ElseIf contweight_150.Find(sModelPath) != -1
  212. return 150.0
  213. ElseIf contweight_175.Find(sModelPath) != -1
  214. return 175.0
  215. ElseIf contweight_200.Find(sModelPath) != -1
  216. return 200.0
  217. ElseIf contweight_225.Find(sModelPath) != -1
  218. return 225.0
  219. Else
  220. return 150.0
  221. EndIf
  222. endFunction
  223.  
  224.  
  225. Float Function weighContentsIn(ObjectReference akContainer) Global
  226. Float iTotal
  227. Int iFormIndex = akContainer.GetNumItems()
  228. While iFormIndex > 0
  229. iFormIndex -= 1
  230. Form kForm = akContainer.GetNthForm(iFormIndex)
  231. iTotal += kForm.GetWeight()
  232. EndIf
  233. EndWhile
  234. Return iTotal
  235. endFunction
Advertisement
Add Comment
Please, Sign In to add comment