ThoraldGM

DCS Quest Script (Complete OnInit with error wrapping)

Sep 29th, 2017
327
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.39 KB | None | 0 0
  1. ; ------------------------------------------------------------------------------------------------------------
  2. ; EVENT: ON INIT
  3. ; ------------------------------------------------------------------------------------------------------------
  4.  
  5. Event OnInit()
  6.  
  7. ; ********************************************************************************************************
  8. ; ASSIGN PLAYER'S CHOICE (LOCKER, DESK, OR CABINET) AS GUARD GEAR CONTAINER
  9. ; ********************************************************************************************************
  10.  
  11. Int PlayerChoice = gvGearContainerChoice.GetValue() as Int ; Did player choose 1, 2, or 3
  12.  
  13. If PlayerChoice == 3
  14. raGearContainer.ForceRefTo(raCabinet.GetReference()) ; If 3, assign cabinet
  15. ElseIf PlayerChoice == 2
  16. raGearContainer.ForceRefTo(raDesk.GetReference()) ; If 2, assign desk
  17. Else
  18. raGearContainer.ForceRefTo(raLocker.GetReference()) ; Else assign locker (default)
  19. EndIf
  20.  
  21. ; ********************************************************************************************************
  22. ; IF CHOICE HAS BEEN SCRAPPED BY PLAYER OR OTHERWISE MISSING, REASSIGN GUARD GEAR CONTAINER
  23. ; ********************************************************************************************************
  24.  
  25. Int RedirectAttempts = 0 ; How many ref changes attempted?
  26. String strFoundRef = "NONE" ; Placeholder string for dev tracker
  27.  
  28. While (raGearContainer.GetReference() == None) && RedirectAttempts < 3 ; Make 3 attempts if scrapped
  29.  
  30. Debug.Notification("DCS: Container not found. Redirecting...") ; Notify player of error correction
  31.  
  32. RedirectAttempts += 1 ; Increment number of attempts
  33.  
  34. PlayerChoice += 1 ; Select the next available choice
  35.  
  36. If PlayerChoice == 4 ; If choice is out of bounds,
  37. PlayerChoice = 1 ; next choice is the first option
  38. EndIf
  39.  
  40. If PlayerChoice == 3
  41. raGearContainer.ForceRefTo(raCabinet.GetReference()) ; If 3, assign cabinet
  42. strFoundRef = "cabinet"
  43. ElseIf PlayerChoice == 2
  44. raGearContainer.ForceRefTo(raDesk.GetReference()) ; If 2, assign desk
  45. strFoundRef = "desk"
  46. Else
  47. raGearContainer.ForceRefTo(raLocker.GetReference()) ; Else assign locker (default)
  48. strFoundRef = "locker"
  49. EndIf
  50.  
  51. If strFoundRef != "NONE"
  52. Debug.Notification("DCS: Reassigned to " + strFoundRef + ".") ; Notify player of change
  53. EndWhile
  54.  
  55. ; ********************************************************************************************************
  56. ; ANNOUNCE RESULTS AND WARN IF ALL THREE OPTIONS WERE SCRAPPED BY PLAYER OR NOT FOUND
  57. ; ********************************************************************************************************
  58.  
  59. ; Mod requires guard gear container to be accessible by player. If no accessible container, fail forward.
  60.  
  61. ; Replace message box debug with message box show. Critical message should display on all platforms!
  62.  
  63. If raGearContainer.GetReference() == None
  64. Debug.MessageBox("Diamond City SWAT: No containers found! Proceeding with default gear.")
  65. gvGearContainerChoice.SetValue(0) ; Flag script as using default gear instead of player container!
  66. Else
  67. If gvDevTracking.GetValue() == 1
  68. Debug.Notification("DCS: Guard gear is in " + strFoundRef + ".")
  69. EndIf
  70. EndIf
  71.  
  72. ; ********************************************************************************************************
  73. ; SET OWNERSHIP OF GUARD GEAR CONTAINER SO PLAYER DOESN'T STEAL ITEMS AND GET ATTACKED
  74. ;
  75. ; NOTE THAT EVERYTHING FROM HERE TO THE END OF ONINIT ONLY HAPPENS IF PLAYER HAS CONTAINER ACCESS!
  76. ; ********************************************************************************************************
  77.  
  78. If gvGearContainerChoice.GetValue() as Int != 0 ; If using locker, desk, or cabinet...
  79.  
  80. obGearContainer = raGearContainer.GetReference() ; Grab ObjRef of the RefAlias
  81. Cell GearContainerCell = obGearContainer.GetParentCell() ; Grab parent cell of the ObjRef
  82. GearContainerCell.SetFactionOwner(pPlayerFaction) ; Remove stolen flag from cell/container
  83.  
  84. ; This method makes everything in Security Office belong to the player, including the jail key.
  85. ; I would rather change flag on the container only, but obGearContainer.SetActorOwner(NONE) didn't work.
  86. ; I may also look into making player ownership of the Security Office a MCM option that can be toggled.
  87.  
  88. ; Note that choosing Arturo's "All Others Pay Caps" cabinet changes Market, not Security Office!
  89.  
  90. ; ****************************************************************************************************
  91. ; WARN PLAYER IF CONTAINER IS STILL DANGEROUS
  92. ; ****************************************************************************************************
  93.  
  94. Bool bPlayerOwns = (GearContainerCell.GetFactionOwner() == pPlayerFaction)
  95.  
  96. If !bPlayerOwns
  97. ; This first notification is a critical warning, so display even if player doesn't want dev messages.
  98. ; Criticals are rare. Dev messages are spammy. Dev messages default to off in final version.
  99.  
  100. Debug.Notification("DCS: SET FACTION FAILED!") ; Show notice on top left screen corner
  101. Debug.Trace("DIAMOND CITY SWAT: SET FACTION FAILED!") ; Write warning in log file
  102. Else
  103. If gvDevTracking.GetValue() == 1 ; If player wants developer messages
  104. Debug.Notification("DCS: Player owns cell.") ; inform player that faction updated
  105. EndIf
  106. EndIf
  107.  
  108. ; ****************************************************************************************************
  109. ; POPULATE LIST OF SLOT NAME STRINGS FOR DEV MESSAGES
  110. ; ****************************************************************************************************
  111.  
  112. strSortedItems = new string[24]
  113. strSortedItems[0] = "headgear"
  114. strSortedItems[1] = "outfit"
  115. strSortedItems[2] = "gloves"
  116. strSortedItems[3] = "bracelet"
  117. strSortedItems[4] = "jacket"
  118. strSortedItems[5] = "top"
  119. strSortedItems[6] = "leg addon"
  120. strSortedItems[7] = "bottom"
  121. strSortedItems[8] = "chestplate"
  122. strSortedItems[9] = "left arm"
  123. strSortedItems[10] = "right arm"
  124. strSortedItems[11] = "left leg"
  125. strSortedItems[12] = "right leg"
  126. strSortedItems[13] = "full mask"
  127. strSortedItems[14] = "eyewear"
  128. strSortedItems[15] = "partial mask"
  129. strSortedItems[16] = "neckwear"
  130. strSortedItems[17] = "ring"
  131. strSortedItems[18] = "cloak or pack"
  132. strSortedItems[19] = "satchel"
  133. strSortedItems[20] = "bandolier"
  134. strSortedItems[21] = "cargo"
  135. strSortedItems[22] = "gun on back"
  136. strSortedItems[23] = "left hand item"
  137.  
  138. If gvDevTracking.GetValue() == 1
  139. Debug.Notification("DCS: Strings filled.")
  140. EndIf
  141.  
  142. ; ****************************************************************************************************
  143. ; IF PLAYER HAS AWKCR MOD INSTALLED, START INTER-MOD COMMUNICATION AND GRAB NECESSARY FORMS
  144. ; ****************************************************************************************************
  145.  
  146. ArmorKywds = new keyword[24] ; There are 24 biped slots that are most relevant to armors.
  147.  
  148. bModInstalled = Game.IsPluginInstalled("ArmorKeywords.esm")
  149. Utility.Wait(0.1) ; Give stack a moment to find mod before I start grabbing forms.
  150.  
  151. If bModInstalled
  152.  
  153. ; AWKCR keyword IDs for biped armor slots are from Gambit77's Armorsmith Extended tutorial:
  154. ; https://forums.nexusmods.com/index.php?showtopic=3687915
  155.  
  156. ; See also:
  157. ; https://www.creationkit.com/fallout4/index.php?title=Biped_Slots
  158. ; https://www.creationkit.com/fallout4/index.php?title=Inter-mod_Communication
  159.  
  160. ArmorKywds[0] = Game.GetFormFromFile(0x01000813, "ArmorKeywords.esm") as Keyword
  161. ArmorKywds[1] = Game.GetFormFromFile(0x0100081E, "ArmorKeywords.esm") as Keyword
  162. ArmorKywds[2] = Game.GetFormFromFile(0x0100081D, "ArmorKeywords.esm") as Keyword
  163. ArmorKywds[3] = Game.GetFormFromFile(0x01000831, "ArmorKeywords.esm") as Keyword
  164. ArmorKywds[4] = Game.GetFormFromFile(0x01000832, "ArmorKeywords.esm") as Keyword
  165. ArmorKywds[5] = Game.GetFormFromFile(0x0100081B, "ArmorKeywords.esm") as Keyword
  166. ArmorKywds[6] = Game.GetFormFromFile(0x01000833, "ArmorKeywords.esm") as Keyword
  167. ArmorKywds[7] = Game.GetFormFromFile(0x0100081C, "ArmorKeywords.esm") as Keyword
  168. ArmorKywds[8] = Game.GetFormFromFile(0x0100080E, "ArmorKeywords.esm") as Keyword
  169. ArmorKywds[9] = Game.GetFormFromFile(0x01000803, "ArmorKeywords.esm") as Keyword
  170. ArmorKywds[10] = Game.GetFormFromFile(0x01000804, "ArmorKeywords.esm") as Keyword
  171. ArmorKywds[11] = Game.GetFormFromFile(0x01000805, "ArmorKeywords.esm") as Keyword
  172. ArmorKywds[12] = Game.GetFormFromFile(0x01000806, "ArmorKeywords.esm") as Keyword
  173. ArmorKywds[13] = Game.GetFormFromFile(0x0100080F, "ArmorKeywords.esm") as Keyword
  174. ArmorKywds[14] = Game.GetFormFromFile(0x0100080C, "ArmorKeywords.esm") as Keyword
  175. ArmorKywds[15] = Game.GetFormFromFile(0x01000801, "ArmorKeywords.esm") as Keyword
  176. ArmorKywds[16] = Game.GetFormFromFile(0x01000810, "ArmorKeywords.esm") as Keyword
  177. ArmorKywds[17] = Game.GetFormFromFile(0x0100081F, "ArmorKeywords.esm") as Keyword
  178. ArmorKywds[18] = Game.GetFormFromFile(0x01000839, "ArmorKeywords.esm") as Keyword
  179. ArmorKywds[19] = Game.GetFormFromFile(0x01000834, "ArmorKeywords.esm") as Keyword
  180. ArmorKywds[20] = Game.GetFormFromFile(0x01000838, "ArmorKeywords.esm") as Keyword
  181. ArmorKywds[21] = Game.GetFormFromFile(0x01000836, "ArmorKeywords.esm") as Keyword
  182. ArmorKywds[22] = Game.GetFormFromFile(0x0100083E, "ArmorKeywords.esm") as Keyword
  183. ArmorKywds[23] = Game.GetFormFromFile(0x01000837, "ArmorKeywords.esm") as Keyword
  184.  
  185. AK_Slot30_Hat = Game.GetFormFromFile(0x0100080D, "ArmorKeywords.esm") as Keyword
  186. AK_Slot36_Bracelet = Game.GetFormFromFile(0x01000811, "ArmorKeywords.esm") as Keyword
  187. AK_Slot46_Headband = Game.GetFormFromFile(0x0100083F, "ArmorKeywords.esm") as Keyword
  188. AK_Slot46_MaskFull = Game.GetFormFromFile(0x0100083A, "ArmorKeywords.esm") as Keyword
  189. AK_Slot49_Mouth = Game.GetFormFromFile(0x0100083B, "ArmorKeywords.esm") as Keyword
  190. AK_Slot50_Scarf = Game.GetFormFromFile(0x0100083D, "ArmorKeywords.esm") as Keyword
  191. AK_Slot54_Pack = Game.GetFormFromFile(0x01000824, "ArmorKeywords.esm") as Keyword
  192. AK_Slot55_GunOnHip = Game.GetFormFromFile(0x0100083C, "ArmorKeywords.esm") as Keyword
  193. AK_Slot55_Satchel = Game.GetFormFromFile(0x01000861, "ArmorKeywords.esm") as Keyword
  194. AK_Slot56_Harness = Game.GetFormFromFile(0x01000835, "ArmorKeywords.esm") as Keyword
  195. AK_Slot58_Piercing = Game.GetFormFromFile(0x01000812, "ArmorKeywords.esm") as Keyword
  196.  
  197. If gvDevTracking.GetValue() == 1
  198. Debug.Notification("DCS: AWKCR handled.")
  199. EndIf
  200.  
  201. EndIf
  202.  
  203. ; ****************************************************************************************************
  204. ; REGISTER (START LISTENING) FOR REMOTE EVENTS, SO SCRIPT CAN REACT
  205. ; ****************************************************************************************************
  206.  
  207. AddInventoryEventFilter(None) ; Required filter for OnItemAdded and OnItemRemoved
  208. Utility.Wait(0.1) ; Give stack a moment to set up required filter before I register events.
  209.  
  210. RegisterForRemoteEvent(raGearContainer, "OnItemAdded") ; Do something when items added to gear container
  211. RegisterForRemoteEvent(raGearContainer, "OnItemRemoved") ; Do something when items removed from gear container
  212.  
  213. Else
  214. ; Else player scrapped all containers and is using fail forward default, so no custom gear functionality.
  215. EndIf
  216.  
  217. EndEvent
Advertisement
Add Comment
Please, Sign In to add comment