Advertisement
Sharlikran

Installer Script

Mar 27th, 2017
263
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.31 KB | None | 0 0
  1. scriptname SKEMenuInstallerScript extends Quest
  2.  
  3. Group SKEVanillaWorkshopMenuCache
  4. FormList Property WorkshopMenuMain auto const
  5. {Add to the WorkshopMenuMain - Main Menu}
  6. FormList Property WorkshopMenu01Build auto const
  7. {Add to the WorkshopMenu01Build - Structures}
  8. FormList Property WorkshopMenu01Furniture auto const
  9. {Add to the WorkshopMenu01Furniture - Furniture}
  10. FormList Property WorkshopMenu01Decor auto const
  11. {Add to the WorkshopMenu01Decor - Decorations}
  12. FormList Property WorkshopMenu01Power auto const
  13. {Add to the WorkshopMenu01Power - Power}
  14. FormList Property WorkshopMenu01Resource02Defense auto const
  15. {Add to the WorkshopMenu01Resource02Defense - Defense}
  16. FormList Property WorkshopMenu01Resource auto const
  17. {Add to the WorkshopMenu01Resource - Resource Production}
  18. FormList Property WorkshopMenu01Vendors auto const
  19. {Add to the WorkshopMenu01Vendors - Vendors}
  20. FormList Property WorkshopMenu01Cages auto const
  21. {Add to the WorkshopMenu01Cages - Cages}
  22. FormList Property WorkshopMenu01Raider auto const
  23. {Add to the WorkshopMenu01Raider - Raider}
  24. EndGroup
  25.  
  26. Group SKECustomWorkshopMenuCache
  27. FormList Property SKE_CustomMainMenu_Form auto const
  28. {Add the SKE_CustomMainMenu_Form for Single Menu}
  29.  
  30. FormList Property SKE_Structures_MultiForm auto const
  31. {Add the SKE_Structures_MultiForm}
  32. FormList Property SKE_Furniture_MultiForm auto const
  33. {Add the SKE_Furniture_MultiForm}
  34. FormList Property SKE_Decorations_MultiForm auto const
  35. {Add the SKE_Decorations_MultiForm}
  36. FormList Property SKE_Decorations_OCDecorator_Form auto const
  37. {Add the SKE_Decorations_OCDecorator_Form}
  38. FormList Property SKE_Electricity_MultiForm auto const
  39. {Add the SKE_Electricity_MultiForm}
  40. FormList Property SKE_Defense_MultiForm auto const
  41. {Add the SKE_Defense_MultiForm}
  42. FormList Property SKE_Resources_MultiForm auto const
  43. {Add the SKE_Resources_MultiForm}
  44. FormList Property SKE_Vendors_MultiForm auto const
  45. {Add the SKE_Vendors_MultiForm}
  46. FormList Property SKE_Workbenches_MultiForm auto const
  47. {Add the SKE_Workbenches_MultiForm}
  48. FormList Property SKE_Cages_MultiForm auto const
  49. {Add the SKE_Cages_MultiForm}
  50. FormList Property SKE_Landscaping_MultiForm auto const
  51. {Add the SKE_Landscaping_MultiForm}
  52. FormList Property SKE_SettlerManagement_Form auto const
  53. {Add the SKE_SettlerManagement_Form}
  54. FormList Property SKE_MainHomemakerMenu_Form auto const
  55. {Add the SKE_MainHomemakerMenu_Form}
  56. FormList Property SKE_DDProductions_Form auto const
  57. {Add the SKE_DDProductions_Form}
  58. FormList Property SKE_CustomScript_Form auto const
  59. {Add the SKE_CustomScript_Form}
  60. FormList Property SKE_ExtraSettlementItems_Form auto const
  61. {Add the SKE_ExtraSettlementItems_Form}
  62. EndGroup
  63.  
  64. ;TODO - remove if you dont want to use a while loop
  65. bool uninstallCheckRunning = false
  66. bool usingMultiMenu = false
  67.  
  68. ;====================================================================================================================
  69. ; Quest and Register Events
  70. ;====================================================================================================================
  71.  
  72. Event OnQuestInit()
  73. install_menu()
  74. RegisterForRemoteEvent(Game.GetPlayer(), "OnPlayerLoadGame")
  75. ;TODO - remove if you dont want to use a while loop
  76. checkForUninstall()
  77. RegisterForRemoteEvent(Game.GetPlayer(), "OnDifficultyChanged")
  78. EndEvent
  79.  
  80. ;====================================================================================================================
  81. ; OnPlayerLoadGame and OnDifficultyChanged
  82. ;====================================================================================================================
  83.  
  84. Event Actor.OnPlayerLoadGame(Actor actorref)
  85. install_menu()
  86. ;TODO - remove if you dont want to use a while loop
  87. checkForUninstall()
  88. EndEvent
  89.  
  90. Event Actor.OnDifficultyChanged(Actor actorref, int aOldDifficulty, int aNewDifficulty)
  91. install_menu()
  92. ;TODO - remove if you dont want to use a while loop
  93. checkForUninstall()
  94. EndEvent
  95.  
  96. ;====================================================================================================================
  97. ; Install and Uninstall deciders
  98. ;====================================================================================================================
  99.  
  100. Function install_menu()
  101. if (!usingMultiMenu)
  102. single_install()
  103. else
  104. multimenu_install()
  105. endif
  106. EndFunction
  107.  
  108. Function uninstall_menu()
  109. if (!usingMultiMenu)
  110. single_uninstall()
  111. else
  112. multimenu_uninstall()
  113. endif
  114. EndFunction
  115.  
  116. ;====================================================================================================================
  117. ; Single Menu Install and Restore
  118. ;====================================================================================================================
  119.  
  120. Function single_install()
  121. ; Change to false for Single Menu Install
  122. usingMultiMenu = false
  123.  
  124. WorkshopMenuMain.addForm(SKE_CustomMainMenu_Form)
  125. Debug.notification("Settlement Keywords Single Menu Layout installed!")
  126. EndFunction
  127.  
  128. Function single_uninstall()
  129. WorkshopMenuMain.RemoveAddedForm(SKE_CustomMainMenu_Form)
  130. Debug.notification("Settlement Keywords Single Menu Layout uninstalled!")
  131. EndFunction
  132.  
  133. ;====================================================================================================================
  134. ; Multi Menu Install and Restore
  135. ;====================================================================================================================
  136.  
  137. ;This function adds your new menus or categories to the vanilla formlists
  138. Function multimenu_install()
  139. ; Change to True for Multi Menu Install
  140. usingMultiMenu = true
  141.  
  142. WorkshopMenu01Build.addForm(SKE_Structures_MultiForm)
  143. WorkshopMenu01Furniture.addForm(SKE_Furniture_MultiForm)
  144. WorkshopMenu01Decor.addForm(SKE_Decorations_MultiForm)
  145. WorkshopMenu01Decor.addForm(SKE_Decorations_OCDecorator_Form)
  146. WorkshopMenu01Power.addForm(SKE_Electricity_MultiForm)
  147. WorkshopMenu01Resource02Defense.addForm(SKE_Defense_MultiForm)
  148. WorkshopMenu01Resource.addForm(SKE_Resources_MultiForm)
  149. WorkshopMenu01Vendors.addForm(SKE_Vendors_MultiForm)
  150. WorkshopMenuMain.addForm(SKE_Workbenches_MultiForm)
  151. WorkshopMenu01Cages.addForm(SKE_Cages_MultiForm)
  152. WorkshopMenu01Decor.addForm(SKE_Landscaping_MultiForm)
  153. WorkshopMenuMain.addForm(SKE_SettlerManagement_Form)
  154. WorkshopMenuMain.addForm(SKE_MainHomemakerMenu_Form)
  155. WorkshopMenuMain.addForm(SKE_DDProductions_Form)
  156. WorkshopMenuMain.addForm(SKE_CustomScript_Form)
  157. WorkshopMenuMain.addForm(SKE_ExtraSettlementItems_Form)
  158.  
  159. Debug.notification("Settlement Keywords Multi Menu Layout installed!")
  160. EndFunction
  161.  
  162. Function multimenu_uninstall()
  163. WorkshopMenu01Build.RemoveAddedForm(SKE_Structures_MultiForm)
  164. WorkshopMenu01Furniture.RemoveAddedForm(SKE_Furniture_MultiForm)
  165. WorkshopMenu01Decor.RemoveAddedForm(SKE_Decorations_MultiForm)
  166. WorkshopMenu01Decor.RemoveAddedForm(SKE_Decorations_OCDecorator_Form)
  167. WorkshopMenu01Power.RemoveAddedForm(SKE_Electricity_MultiForm)
  168. WorkshopMenu01Resource02Defense.RemoveAddedForm(SKE_Defense_MultiForm)
  169. WorkshopMenu01Resource.RemoveAddedForm(SKE_Resources_MultiForm)
  170. WorkshopMenu01Vendors.RemoveAddedForm(SKE_Vendors_MultiForm)
  171. WorkshopMenuMain.RemoveAddedForm(SKE_Workbenches_MultiForm)
  172. WorkshopMenu01Cages.RemoveAddedForm(SKE_Cages_MultiForm)
  173. WorkshopMenu01Decor.RemoveAddedForm(SKE_Landscaping_MultiForm)
  174. WorkshopMenuMain.RemoveAddedForm(SKE_SettlerManagement_Form)
  175. WorkshopMenuMain.RemoveAddedForm(SKE_MainHomemakerMenu_Form)
  176. WorkshopMenuMain.RemoveAddedForm(SKE_DDProductions_Form)
  177. WorkshopMenuMain.RemoveAddedForm(SKE_CustomScript_Form)
  178. WorkshopMenuMain.RemoveAddedForm(SKE_ExtraSettlementItems_Form)
  179.  
  180. Debug.notification("Settlement Keywords Multi Menu Layout uninstalled!")
  181. EndFunction
  182.  
  183. ;====================================================================================================================
  184. ; Check For Uninstall
  185. ;====================================================================================================================
  186.  
  187. ;Checks if your plugin is still active. If not removes every none value from the vanilla formlists.
  188. Function checkForUninstall()
  189. ;we only want the loop once
  190. if (!uninstallCheckRunning)
  191. uninstallCheckRunning = true
  192. ;TODO - replace YourMod.esp with the name of your esp
  193. while (Game.IsPluginInstalled("SettlementKeywords.esm"))
  194. Utility.wait(60) ;waits 60 seconds until the condition is checked again
  195. endwhile
  196. ;The plugin is no longer active. Now we have to remove every none value from the edited formlists.
  197.  
  198. ;TODO - Do this with every vanilla menu you edited
  199. removeNoneValues(WorkshopMenuMain)
  200. removeNoneValues(WorkshopMenu01Build)
  201. removeNoneValues(WorkshopMenu01Furniture)
  202. removeNoneValues(WorkshopMenu01Decor)
  203. removeNoneValues(WorkshopMenu01Power)
  204. removeNoneValues(WorkshopMenu01Resource02Defense)
  205. removeNoneValues(WorkshopMenu01Resource)
  206. removeNoneValues(WorkshopMenu01Vendors)
  207. removeNoneValues(WorkshopMenu01Cages)
  208. ;...
  209. uninstallCheckRunning = false
  210. endif
  211. EndFunction
  212.  
  213. ;====================================================================================================================
  214. ; Remove invalid Forms
  215. ;====================================================================================================================
  216.  
  217. Function removeNoneValues(Formlist akCurList)
  218. Int iSize = akCurList.GetSize()
  219. ;Check the size of akCurList to see if it has anything in it
  220. If iSize > 0
  221.  
  222. ;Copy the Form List
  223. Int i
  224. Form[] tmp = New Form[iSize]
  225. While i < iSize
  226. tmp[i] = akCurList.GetAt(i)
  227. i += 1
  228. EndWhile
  229.  
  230. ;Revert the Form List
  231. akCurList.Revert()
  232.  
  233. ;Restore the Form List
  234. i = 0
  235. While i < iSize
  236. If tmp[i] != None
  237. akCurList.AddForm(tmp[i])
  238. EndIf
  239. i += 1
  240. EndWhile
  241. tmp.Clear()
  242. EndIf
  243. EndFunction
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement