Hazuzi

SSE CCOR+Traps Mining script

Jan 5th, 2019
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.17 KB | None | 0 0
  1. scriptName MineOreScript extends objectReference
  2. ;
  3. ;This script handles the Ore Veins and handshakes with the mining furniture
  4. ;===================================================================
  5.  
  6.  
  7. sound property DrScOreOpen auto
  8. {sound played when Ore is acquired}
  9.  
  10. formlist property mineOreToolsList auto
  11. {Optional: Player must have at least one item from this formlist to interact}
  12.  
  13. Message Property FailureMessage Auto
  14. {Message to say why you can't use this without RequiredWeapon}
  15.  
  16. Message Property DepletedMessage Auto
  17. {Message to say that this vein is depleted}
  18.  
  19. MiscObject Property Ore Auto
  20. {what you get from this Ore Vein}
  21.  
  22. LeveledItem property lItemGems10 auto
  23. {Optional: Gems that may be mined along with ore}
  24.  
  25. int Property ResourceCount = 1 Auto
  26. {how many resources you get per drop}
  27.  
  28. GlobalVariable Property ResourceCountGV_CCO auto ;added by Complete Crafting Overhaul by Kryptopyr
  29.  
  30. int property ResourceCountTotal = 3 auto
  31. {how many resources this has before it is depleted}
  32.  
  33. GlobalVariable Property ResourceCountTotalGV_CCO auto ;added by Complete Crafting Overhaul by Kryptopyr
  34.  
  35. int property ResourceCountCurrent = -1 auto Hidden
  36. {Used to track the current remaining resources}
  37.  
  38. int property StrikesBeforeCollection = 1 Auto
  39. {how many times this is struck before giving a resource}
  40.  
  41. GlobalVariable Property StrikesBeforeCollectionGV_CCO auto ;added by Complete Crafting Overhaul by Kryptopyr
  42.  
  43. int property StrikesCurrent = -1 Auto hidden
  44. {Current number of strikes}
  45.  
  46. int property AttackStrikesBeforeCollection = 3 Auto
  47. {how many times this is struck by attacks before giving a resource}
  48.  
  49. GlobalVariable Property AttackStrikesBeforeCollectionGV_CCO auto ;added by Complete Crafting Overhaul by Kryptopyr
  50.  
  51. int property BYOHDeposit = 0 auto ;added by Complete Crafting Overhaul by Kryptopyr Set this to 1 for Clay & Stone deposits found in Hearthfire DLC.
  52. int property StalhrimDeposit = 0 auto ;added by Complete Crafting Overhaul by Kryptopyr Set this to 1 for Stalhrim in order to double the number of strikes it takes to mine.
  53. int property DLC2MineGem = 0 auto ;added by Complete Crafting Overhaul by Kryptopyr Set this to 1 for Gem Geodes found in Dragonborn DLC (can also be used for any ore where the max number of resources obtained should always be 1).
  54. int property DLC1Shellbug = 0 auto ;added by Complete Crafting Overhaul by Kryptopyr Set this to 1 for Shellbugs found in Dawnguard DLC (can also be used for any ore where the max number of resources obtained should always be 3).
  55. int property SkillAdvance = 0 auto ;added by Complete Crafting Overhaul by Kryptopyr
  56. int property MiningSkillIncrease = 0 auto ;added by Complete Crafting Overhaul by Kryptopyr
  57.  
  58. int property AttackStrikesCurrent = -1 Auto hidden
  59. {Current number of attack strikes}
  60.  
  61. mineOreFurnitureScript property myFurniture auto hidden
  62. {the furniture for this piece of ore, set in script}
  63.  
  64. objectReference property objSelf auto hidden
  65. {objectReference to self}
  66.  
  67. AchievementsScript property AchievementsQuest auto
  68.  
  69. Location Property CidhnaMineLocation Auto
  70.  
  71. Quest Property MS02 Auto
  72.  
  73. Quest Property DialogueCidhnaMine Auto
  74.  
  75. ObjectReference Property CidhnaMinePlayerBedREF Auto
  76.  
  77.  
  78. ;===================================================================
  79. ;;EVENT BLOCK
  80. ;===================================================================
  81.  
  82. event onCellAttach()
  83. ; debug.Trace(self + ": is running onCellAttach")
  84. blockActivation()
  85. SetNoFavorAllowed()
  86. objSelf = self as objectReference
  87. if !getLinkedRef()
  88. ; debug.Trace(self + ": does not have a linked ref, going to depleted state")
  89. depleteOreDueToFailure()
  90. endif
  91. endEvent
  92.  
  93. event onActivate(objectReference akActivator)
  94. ; debug.Trace(self + " has been activated by " + akActivator)
  95.  
  96. ;Actor is attempting to mine
  97. if akActivator as actor
  98. ;if the actor is the player
  99. if akActivator == game.getPlayer()
  100. ;USKP 1.3.0 FixStart - Deactivate sneaking before mining to prevent sneak issues.
  101. if game.getPlayer().IsSneaking()
  102. game.getPlayer().StartSneaking()
  103. endif
  104. ;USKP 1.3.0 FixEnd
  105.  
  106. ;if this is not depleted and the player has the right item
  107. If ResourceCountCurrent == 0
  108. DepletedMessage.Show()
  109. elseif playerHasTools() == false
  110. FailureMessage.Show()
  111. ;enter the furniture
  112. else
  113. If Game.GetPlayer().GetCurrentLocation() == CidhnaMineLocation && MS02.ISRunning() == False
  114. ; debug.Trace(self + "Player is in Cidhna Mine, activate the bed to serve time")
  115. CidhnaMinePlayerBedREF.Activate(Game.GetPlayer())
  116. DialogueCidhnaMine.SetStage(45)
  117. Return
  118. EndIf
  119. ; debug.Trace(self + " should cause " + akActivator + " to activate " + getLinkedRef())
  120. if getLinkedRef()
  121. myFurniture = getLinkedRef() as mineOreFurnitureScript
  122. myFurniture.lastActivateRef = objSelf
  123. getLinkedRef().activate(akActivator)
  124. AchievementsQuest.incHardworker(2)
  125. Else
  126. ; debug.Trace(self + ": error this ore does not have a linkedRef")
  127. endif
  128. endif
  129. Else
  130. if getLinkedRef()
  131. getLinkedRef().activate(akActivator)
  132. Else
  133. ; debug.Trace(self + ": error this ore does not have a linkedRef")
  134. endif
  135. EndIf
  136.  
  137. ;Furniture is telling ore it has been struck
  138. ElseIf akActivator == GetLinkedRef()
  139. ; debug.Trace(self + ": has been activated by" + akActivator)
  140. ProccessStrikes()
  141.  
  142. ;Something unexpected has activated the ore
  143. Else
  144. ; debug.Trace(self + "has been activated by: " + akActivator + " why?")
  145. endif
  146. endEvent
  147.  
  148. ;;;May add on hit with pickaxe here later
  149. Event OnHit(ObjectReference akAggressor, Form akSource, Projectile akProjectile, bool abPowerAttack, bool abSneakAttack, bool abBashAttack, bool abHitBlocked)
  150. ; debug.Trace(self + ": onHit - akAgressor = " + akAggressor + "; akSource = " + akSource)
  151. if akAggressor == game.getPlayer()
  152. ;PATCH 1.5 CAPTURE ON HIT EVENT AND BRING UP SERVE TIME DIALOG FOR CIDHNA MINE
  153. if mineOreToolsList.hasForm(akSource)
  154. If Game.GetPlayer().GetCurrentLocation() == CidhnaMineLocation && MS02.ISRunning() == False
  155. ; debug.Trace(self + "Player is in Cidhna Mine, activate the bed to serve time")
  156. CidhnaMinePlayerBedREF.Activate(Game.GetPlayer())
  157. DialogueCidhnaMine.SetStage(45)
  158. Return
  159. EndIf
  160. proccessAttackStrikes()
  161. endif
  162. endif
  163. endEvent
  164.  
  165. event onReset()
  166. ; debug.Trace(self + ": is running onReset")
  167. ;THIS WASN'T WORKING RIGHT
  168. self.Reset()
  169. self.clearDestruction()
  170. self.setDestroyed(False)
  171. ; if getLinkedRef()
  172. resourceCountCurrent = -1
  173. ; else
  174. ; depleteOreDueToFailure()
  175. ; endif
  176. ;USKP 1.3.0 FixStart - if ore is enabled then disable and enable to avoid becoming un-mineable upon respawn.
  177. if self.isEnabled()
  178. self.disable()
  179. self.enable()
  180. endif
  181. ;USKP 1.3.0 FixEnd
  182. endEvent
  183.  
  184. ;===================================================================
  185. ;;FUNCTION BLOCK
  186. ;===================================================================
  187. bool function playerHasTools()
  188. if Game.GetPlayer().GetItemCount(mineOreToolsList) > 0
  189. ; debug.Trace(self + ": playerHasTools is returning true")
  190. return true
  191. Else
  192. ; debug.Trace(self + ": playerHasTools is returning false")
  193. return false
  194. endIf
  195. endFunction
  196.  
  197. function proccessAttackStrikes()
  198. if AttackStrikesCurrent <= -1
  199. if StalhrimDeposit == 1 ;added by Complete Crafting Overhaul by kryptopyr
  200. AttackStrikesBeforeCollection = 2*((Game.GetFormFromFile(0x01CC0504, "Update.esm") As GlobalVariable).GetValue() As Int) ;AttackStrikesBeforeCollectionGV_CCO
  201. else
  202. AttackStrikesBeforeCollection = ((Game.GetFormFromFile(0x01CC0504, "Update.esm") As GlobalVariable).GetValue() As Int) ;AttackStrikesBeforeCollectionGV_CCO
  203. endif ;^^added by Complete Crafting Overhaul by kryptopyr
  204. AttackStrikesCurrent = AttackStrikesBeforeCollection
  205. EndIf
  206. AttackStrikesCurrent -= 1
  207.  
  208. if AttackStrikesCurrent == 0
  209. AttackstrikesCurrent = AttackStrikesBeforeCollection
  210. giveOre()
  211. endIf
  212. CreateDetectionEvent(Game.GetPlayer(), 250) ;added by TRAPS MAKE NOISE by Kryptopyr
  213. endFunction
  214.  
  215. function proccessStrikes()
  216. if StrikesCurrent <= -1
  217. if StalhrimDeposit == 1 ;added by Complete Crafting Overhaul by kryptopyr
  218. StrikesBeforeCollection = 2*((Game.GetFormFromFile(0x01CC0503, "Update.esm") As GlobalVariable).GetValue() As Int) ;StrikesBeforeCollectionGV_CCO
  219. else
  220. StrikesBeforeCollection = ((Game.GetFormFromFile(0x01CC0503, "Update.esm") As GlobalVariable).GetValue() As Int) ;StrikesBeforeCollectionGV_CCO
  221. endif ;^^added by Complete Crafting Overhaul by kryptopyr
  222. StrikesCurrent = StrikesBeforeCollection
  223. EndIf
  224. StrikesCurrent -= 1
  225.  
  226. if StrikesCurrent == 0
  227. strikesCurrent = StrikesBeforeCollection
  228. giveOre()
  229. endIf
  230. CreateDetectionEvent(Game.GetPlayer(), 250) ;added by TRAPS MAKE NOISE by Kryptopyr
  231. endFunction
  232.  
  233. function giveOre()
  234. if DLC2MineGem == 1 ;added by Complete Crafting Overhaul by kryptopyr
  235. ResourceCountTotal = 1
  236. elseif DLC1Shellbug == 1
  237. ResourceCountTotal = 3
  238. elseif BYOHDeposit == 1
  239. ResourceCountTotal = 1000
  240. else
  241. ResourceCountTotal = ((Game.GetFormFromFile(0x01CC0502, "Update.esm") As GlobalVariable).GetValue() As Int) ;ResourceCountTotalGV_CCO
  242. endif ;^^added by Complete Crafting Overhaul by kryptopyr
  243. if ResourceCountCurrent == -1
  244. ResourceCountCurrent = ResourceCountTotal
  245. EndIf
  246.  
  247. if ResourceCountCurrent > 0
  248. MiningSkillIncrease = ((Game.GetFormFromFile(0x01CC0450, "Update.esm") As GlobalVariable).GetValue() As Int) ;added by Complete Crafting Overhaul by kryptopyr
  249. if MiningSkillIncrease > 0
  250. Game.AdvanceSkill("Smithing", MiningSkillIncrease)
  251. endif
  252. ResourceCount = ((Game.GetFormFromFile(0x01CC0501, "Update.esm") As GlobalVariable).GetValue() As Int) ;ResourceCountGV_CCO
  253. if BYOHDeposit == 1
  254. ResourceCount = ResourceCount+3
  255. endif ;^^added by Complete Crafting Overhaul by kryptopyr
  256. ResourceCountCurrent -= 1
  257. ; debug.Trace(self + ": ResourceCountCurrent = " + ResourceCountCurrent)
  258. if ResourceCountCurrent == 0
  259.  
  260. ; debug.Trace(self + ": ResourceCountCurrent == 0 - depleted" )
  261. self.damageObject(50)
  262. getLinkedRef().activate(objSelf)
  263. DrScOreOpen.play(self)
  264. self.setDestroyed(true)
  265. ; if this vein has ore and/or gems defined, give them.
  266. if ore
  267. (game.getPlayer()).addItem(Ore, ResourceCount)
  268. endif
  269. if lItemGems10
  270. (game.getPlayer()).addItem(lItemGems10)
  271. endif
  272. DepletedMessage.Show()
  273. else
  274. DrScOreOpen.play(self)
  275. ; if this vein has ore and/or gems defined, give them.
  276. if ore
  277. (game.getPlayer()).addItem(Ore, ResourceCount)
  278. endif
  279. if lItemGems10
  280. (game.getPlayer()).addItem(lItemGems10)
  281. endif
  282. endif
  283. elseif ResourceCountCurrent == 0
  284. getLinkedRef().activate(objSelf)
  285. (getLinkedRef() as MineOreFurnitureScript).goToDepletedState()
  286. DepletedMessage.Show()
  287. endif
  288.  
  289. EndFunction
  290.  
  291. function depleteOreDueToFailure()
  292. self.damageObject(50)
  293. ;THIS WASN'T WORKING RIGHT
  294. self.setDestroyed(true)
  295. ResourceCountCurrent = 0
  296. endFunction
Advertisement
Add Comment
Please, Sign In to add comment