Advertisement
ThoraldGM

DCS Laundry Script (added scrap check, player option)

Sep 26th, 2017
289
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.45 KB | None | 0 0
  1. Scriptname DCS_Laundry_Script extends Quest
  2. { It just works. }
  3.  
  4. ; DIAMOND CITY SWAT VERSION 2.0: https://www.nexusmods.com/fallout4/mods/10893/
  5. ; A FALLOUT 4 MOD BY @THORALDGM | THORALDGM.COM | SCRIPT UPDATED 20170926
  6. ;
  7. ; This script makes washers functional in Diamond City security office. Max compatibility with other mods.
  8. ;
  9. ; PERMISSIONS:
  10. ;
  11. ; - Do not repost my mod. If you want to tweak minor changes, send me the esp and I will post it in Files.
  12. ; - Language translations are allowed only on same platforms where I posted mod. Please mail link when done.
  13. ; - This mod may not be folded entirely into a larger work without my written permission and collaboration.
  14. ; - Please ask if you want to use parts of my code to improve other mods. Must be unique and credit source.
  15. ;
  16. ; - If you have any questions, or see a better way to do something, please let me know.
  17. ;
  18. ; SCRIPT SECTIONS:
  19. ;
  20. ; LINE 041: PROPERTIES
  21. ; LINE 062: ON INIT
  22. ; LINE 096: IS WASHER AVAILABLE
  23. ; LINE 123: ENABLE LAUNDRY
  24. ; LINE 133: DISABLE LAUNDRY
  25. ; LINE 149: ON ITEM ADDED
  26. ;
  27. ; WARNINGS:
  28. ;
  29. ; - ANYTHING PLACED IN WASHER WILL BE STRIPPED OF ARMOR/WEAPON MODS DURING TRANSFER TO DRYER!
  30. ; - WEAPONS PLACED IN WASHER WILL GENERATE SMALL AMOUNTS OF AMMO IN DRYER. THIS CAN BE FARMED/REPEATED.
  31. ;
  32. ; This does not create working washers/dryers in workshops. For that functionality, check out these mods:
  33. ; - Functional Washer: https://www.nexusmods.com/fallout4/mods/14402/
  34. ; - Laundry Day: https://www.nexusmods.com/fallout4/mods/9042/
  35. ;
  36. ; Other laundromats in game that could benefit from this method:
  37. ; - http://fallout.wikia.com/wiki/Charlestown_laundry
  38. ; - http://fallout.wikia.com/wiki/Faded_Glory_laundromat
  39.  
  40. ; ------------------------------------------------------------------------------------------------------------
  41. ; PROPERTIES
  42. ; ------------------------------------------------------------------------------------------------------------
  43.  
  44. FormList Property flCleanClothes Auto Const Mandatory ; FormList of clean clothes
  45. FormList Property flDirtyClothes Auto Const Mandatory ; FormList of dirty clothes
  46.  
  47. ReferenceAlias Property raWasher1 Auto Const ; Left washer
  48. ReferenceAlias Property raWasher2 Auto Const ; Center washer
  49. ReferenceAlias Property raWasher3 Auto Const ; Right washer
  50.  
  51. ReferenceAlias Property raDryer1 Auto Const ; Left dryer
  52. ReferenceAlias Property raDryer2 Auto Const ; Center dryer
  53. ReferenceAlias Property raDryer3 Auto Const ; Right dryer
  54.  
  55. Sound Property pFXHumanCannibalGush Auto Const Mandatory ; Gurgling sound for washers
  56. Sound Property pDRSFacilityXBlastOpenEBuzzer Auto Const Mandatory ; Buzzer sound for dryers
  57.  
  58. GlobalVariable Property gvDevTracking Auto Mandatory ; Are dev messages turned on
  59. GlobalVariable Property gvPlayerWantsLaundry Auto Mandatory ; Does player want working washers
  60.  
  61. ; ------------------------------------------------------------------------------------------------------------
  62. ; EVENT: ON INIT
  63. ; ------------------------------------------------------------------------------------------------------------
  64.  
  65. Event OnInit()
  66. If gvPlayerWantsLaundry.GetValue() == 1 ; If player wants working washers...
  67.  
  68. If IsWasherAvailable(raWasher1) ; If left washer is available,
  69. EnableLaundry(raWasher1) ; enable left washer functionality.
  70.  
  71. If gvDevTracking.GetValue() == 1 ; Inform dev tracker.
  72. Debug.Notification("DCS: Left washer enabled.")
  73. EndIf
  74. EndIf
  75.  
  76. If IsWasherAvailable(raWasher2) ; If center washer is available,
  77. EnableLaundry(raWasher2) ; enable center washer functionality.
  78.  
  79. If gvDevTracking.GetValue() == 1 ; Inform dev tracker.
  80. Debug.Notification("DCS: Center washer enabled.")
  81. EndIf
  82. EndIf
  83.  
  84. If IsWasherAvailable(raWasher3) ; If right washer is available,
  85. EnableLaundry(raWasher3) ; enable right washer functionality.
  86.  
  87. If gvDevTracking.GetValue() == 1 ; Inform dev tracker.
  88. Debug.Notification("DCS: Right washer enabled.")
  89. EndIf
  90. EndIf
  91.  
  92. EndIf
  93. EndEvent
  94.  
  95. ; ------------------------------------------------------------------------------------------------------------
  96. ; CUSTOM FUNCTION: IS WASHER AVAILABLE
  97. ; ------------------------------------------------------------------------------------------------------------
  98.  
  99. Bool Function IsWasherAvailable(ReferenceAlias raMachine)
  100. ObjectReference obMachine ; Prepare to get objref of refalias
  101.  
  102. If !raMachine ; If no refalias passed to function
  103. return False ; tell caller washer not available
  104.  
  105. ElseIf raMachine != raWasher1 && raMachine != raWasher2 && raMachine != raWasher3
  106. return False ; If not security office washer, decline.
  107. Else
  108. obMachine = raMachine.GetReference() ; otherwise fill objref and continue
  109. EndIf
  110.  
  111. ; ********************************************************************************************************
  112. ; FUNCTION ONLY PROCEEDS PAST THIS POINT IF CALLER IS ASKING ABOUT A SECURITY OFFICE WASHER!
  113. ; ********************************************************************************************************
  114.  
  115. If !obMachine || obMachine.IsDisabled() || obMachine.IsDeleted() ; If washer is scrapped or wack
  116. return False ; tell caller washer not available
  117. Else
  118. return True ; otherwise washer is good to go!
  119. EndIf
  120. EndFunction
  121.  
  122. ; ------------------------------------------------------------------------------------------------------------
  123. ; CUSTOM FUNCTION: ENABLE LAUNDRY
  124. ; ------------------------------------------------------------------------------------------------------------
  125.  
  126. Function EnableLaundry(ReferenceAlias raMachine)
  127. AddInventoryEventFilter(None) ; Required filter for OnItemAdded
  128. Utility.Wait(0.1) ; Let stack apply filter before registrations
  129. RegisterForRemoteEvent(raMachine, "OnItemAdded") ; Listen for washer event on ref passed to function
  130. EndFunction
  131.  
  132. ; ------------------------------------------------------------------------------------------------------------
  133. ; CUSTOM FUNCTION: DISABLE LAUNDRY
  134. ; ------------------------------------------------------------------------------------------------------------
  135.  
  136. Function DisableLaundry()
  137. RemoveAllInventoryEventFilters() ; Remove the required OnItemAdded filter
  138. UnregisterForRemoteEvent(raWasher1, "OnItemAdded") ; Stop listening for left washer event
  139. UnregisterForRemoteEvent(raWasher2, "OnItemAdded") ; Stop listening for center washer event
  140. UnregisterForRemoteEvent(raWasher3, "OnItemAdded") ; Stop listening for right washer event
  141.  
  142. If gvDevTracking.GetValue() == 1 ; Inform dev tracker.
  143. Debug.Notification("DCS: Laundry disabled.")
  144. EndIf
  145.  
  146. EndFunction
  147.  
  148. ; ------------------------------------------------------------------------------------------------------------
  149. ; EVENT: ON ITEM ADDED
  150. ; ------------------------------------------------------------------------------------------------------------
  151.  
  152. Event ReferenceAlias.OnItemAdded(ReferenceAlias akSender, Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akSourceContainer)
  153.  
  154. ; ********************************************************************************************************
  155. ; PAIR INCOMING WASHER WITH OUTGOING DRYER
  156. ; ********************************************************************************************************
  157.  
  158. Form LaunderedItem = akBaseItem ; Store item for pending transfer
  159. ObjectReference obSender = akSender.GetReference() ; Get objref of the washer refalias
  160. ObjectReference ClothesDestination ; Prepare to assign a dryer
  161. String GoWhere ; String for assigned dryer
  162.  
  163. If akSender == raWasher1
  164. ClothesDestination = raDryer1.GetReference() ; Left washer targets left dryer
  165. GoWhere = "left"
  166. ElseIf akSender == raWasher2
  167. ClothesDestination = raDryer2.GetReference() ; Center washer targets center dryer
  168. GoWhere = "center"
  169. Else
  170. ClothesDestination = raDryer3.GetReference() ; Right washer targets right dryer
  171. GoWhere = "right"
  172. EndIf
  173.  
  174. If gvDevTracking.GetValue() == 1
  175. Debug.Notification("DCS: Destination is " + GoWhere + " dryer.") ; Inform dev tracker.
  176. EndIf
  177.  
  178. ; ********************************************************************************************************
  179. ; SWAP OUTGOING ITEM WITH CLEAN ITEM IF AVAILABLE
  180. ; ********************************************************************************************************
  181.  
  182. If flDirtyClothes.HasForm(akBaseItem) ; If item is on dirty clothes list
  183. Int index = flDirtyClothes.Find(akBaseItem) ; get exact position on the list
  184. LaunderedItem = flCleanClothes.GetAt(index) ; Replace transfer item with clean version
  185. EndIf
  186.  
  187. ; ********************************************************************************************************
  188. ; REMOVE ITEM FROM WASHER, ADD OUTGOING ITEM TO DRYER, PLAY GURGLING & BUZZER SOUNDS
  189. ; ********************************************************************************************************
  190.  
  191. ClothesDestination.AddItem(LaunderedItem, 1, true) ; Silently add item to dryer
  192. obSender.RemoveItem(akBaseItem, 1, true) ; Silently delete item from washer
  193.  
  194. Bool bInstanceID = pFXHumanCannibalGush.PlayAndWait(akSourceContainer) ; Assign & play gurgling sound. When finished,
  195. Int iInstanceID = pDRSFacilityXBlastOpenEBuzzer.Play(akSourceContainer) ; assign & play buzzer sound
  196. EndEvent
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement