Hazuzi

CCO Chopping script

Jan 5th, 2019
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.07 KB | None | 0 0
  1. Scriptname ResourceFurnitureScript extends ObjectReference Conditional
  2. {script for furniture which the player can use to get resources}
  3.  
  4.  
  5. formlist Property requiredItemList Auto
  6. {required for player to use - optional}
  7.  
  8. Message Property FailureMessage Auto
  9. {Message to say why you can't use this without RequiredWeapon}
  10.  
  11. MiscObject Property Resource Auto
  12. {what you get from using this furniture}
  13.  
  14. int Property ResourceCount = 1 Auto
  15. {how many resources you get per use}
  16.  
  17. GlobalVariable Property FirewoodResourcePerUseGV_CCO auto ;added by Complete Crafting Overhaul by Kryptopyr
  18.  
  19. int property MaxResourcePerActivation = 6 auto
  20. {How many times can this object be used before the player has to re-activate?}
  21.  
  22. GlobalVariable Property FirewoodResourceMaxGV_CCO auto ;added by Complete Crafting Overhaul by Kryptopyr
  23.  
  24. int counter
  25. ; count up how many resources have been gathered on this go.
  26.  
  27. faction property CurrentFollowerFaction auto
  28. {Used to handle player followers using the furniture object}
  29.  
  30. objectReference property NPCfollower auto hidden
  31. {hidden property to track followers who used this}
  32.  
  33. Event OnLoad()
  34. BlockActivation(true)
  35. endEvent
  36.  
  37. Event OnUnload()
  38. ; safety measure
  39. UnregisterForEvents(game.getplayer())
  40. if NPCfollower
  41. UnregisterForEvents(NPCfollower)
  42. endif
  43. endEvent
  44.  
  45. auto STATE normal
  46. Event OnActivate(ObjectReference akActionRef)
  47. gotoState("busy")
  48. ; debug.trace(self + "OnActivate")
  49. if akActionRef == Game.GetPlayer() || (akActionRef as actor).isInFaction(CurrentFollowerFaction)
  50. ; debug.trace("akActionRef is either player or a follower")
  51. if (akActionRef as actor) != game.getPlayer()
  52. ; debug.trace("It's a follower - store in NPCfollower property")
  53. ; if not the player, must be the follower
  54. NPCfollower = akActionRef
  55. endif
  56. bool allowActivation = true
  57. ; check if player has required item
  58. if requiredItemList
  59. if akActionRef.GetItemCount(requiredItemList) == 0
  60. if akActionRef == game.getPlayer()
  61. ; only require the axe item for the player
  62. allowActivation = false
  63. ; debug.trace("allowActivation = "+allowActivation)
  64. FailureMessage.Show()
  65. endif
  66. endif
  67. endif
  68.  
  69. if allowActivation
  70. RegisterForEvents(akActionRef)
  71. ; debug.trace(self + "player/follower activation START")
  72. Activate(akActionRef, true)
  73. ; debug.trace(self + "player/follower activation END")
  74. endif
  75. else
  76. ; ;debug.trace(self + "non-follower NPC activation START")
  77. ; just activate it
  78. Activate(akActionRef, true)
  79. ; ;debug.trace(self + "non-follower NPC activation END")
  80. endif
  81. gotoState("normal")
  82. endEvent
  83. endState
  84.  
  85. STATE busy
  86. ; do nothing
  87. endState
  88.  
  89. Event OnAnimationEvent(ObjectReference akSource, string asEventName)
  90. ; debug.trace(self + ": animation event received=" + asEventName)
  91. if asEventName == "AddToInventory"
  92. ResourceCount = ((Game.GetFormFromFile(0x01CC0506, "Update.esm") As GlobalVariable).GetValue() As Int) ;FirewoodResourcePerUseGV_CCO ;added by Complete Crafting Overhaul by kryptopyr
  93. MaxResourcePerActivation = ((Game.GetFormFromFile(0x01CC0507, "Update.esm") As GlobalVariable).GetValue() As Int) ;FirewoodResourceMaxGV_CCO ;added by Complete Crafting Overhaul by kryptopyr
  94. akSource.AddItem(Resource, ResourceCount)
  95. ; increment counter by however many items we just received
  96. ; debug.trace("Pre-add counter = "+counter)
  97. counter = (counter + resourceCount)
  98. ; debug.trace("Post-add counter = "+counter)
  99. if counter >= MaxResourcePerActivation
  100. ; if we've bagged our limit, kick the player out. Reset timer for next activation
  101. ; debug.trace("Woodpile - player has gotten "+counter+" logs this go. Kicking out.")
  102. counter = 0
  103. (akSource as actor).PlayIdle(IdleWoodchopExit)
  104. unregisterForEvents(akSource)
  105. endif
  106. elseif asEventName == "IdleFurnitureExit"
  107. ; debug.trace("Resource Object Unregistering: "+self)
  108. ; reset the counter if I exit manually
  109. counter = 0
  110. UnregisterForEvents(akSource)
  111. endif
  112. endEvent
  113.  
  114. bool isRegisteredForEvents = false
  115.  
  116. function RegisterForEvents(objectReference whoToRegister)
  117. ; centralize this
  118. isRegisteredForEvents = true
  119. RegisterForAnimationEvent(whoToRegister, "AddToInventory")
  120. RegisterForAnimationEvent(whoToRegister, "SoundPlay . NPCHumanWoodChop")
  121. RegisterForAnimationEvent(whoToRegister, "IdleFurnitureExit")
  122. endFunction
  123.  
  124. function UnregisterForEvents(objectReference whoToUnregister)
  125. ; centralize this
  126.  
  127. ; It is perfectly safe to unregister for events you never registered for, however
  128. ; this function is called as part of OnUnload, and if this object isn't persistent
  129. ; then it may be deleted by the time OnUnload runs, and these function calls will
  130. ; fail. Since RegisterForAnimationEvent persists us, we know it will be safe to
  131. ; call Unregister if we've previously Registered, even if called as a part of
  132. ; OnUnload
  133. if isRegisteredForEvents
  134. isRegisteredForEvents = false
  135. UnRegisterForAnimationEvent(whoToUnregister, "AddToInventory")
  136. UnRegisterForAnimationEvent(whoToUnregister, "IdleFurnitureExit")
  137. endif
  138. endFunction
  139.  
  140. Idle Property IdleWoodchopExit Auto
Add Comment
Please, Sign In to add comment