Advertisement
Sharlikran

Category Installer

May 9th, 2016
237
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.90 KB | None | 0 0
  1. scriptname CustomCategoriesInstallerScript extends Quest
  2.  
  3. Group VanillaWorkshopMenus
  4. FormList property VanillaWorkshopMenu auto const
  5. {The menu you want to add your new categeory to}
  6. ;Add more properties for other vanilla menus if needed
  7. ;Tipp: Name your properties as your forms in CK, so you can auto fill them with one click
  8. EndGroup
  9.  
  10. Group CustomWorkshopMenus
  11. FormList property CustomWorkshopMenu auto const
  12. {A menu you want to add to a vanilla menu}
  13. Keyword property CustomWorkshopCategory auto const
  14. {A category you want to add to a vanilla menu}
  15. ;Add more properties for other custom menus/keywords if needed
  16. ;Tipp: Name your properties as your forms in CK, so you can auto fill them with one click
  17. EndGroup
  18.  
  19. ;TODO - remove if you dont want to use a while loop
  20. bool uninstallCheckRunning = false
  21.  
  22. ;====================================================================================================================
  23. ;Add your new forms
  24. ;====================================================================================================================
  25.  
  26. ;The event OnPlayerLoadGame will not be executed the first time the player loads his game with this plugin active, so
  27. ;we have to call the install() function manually once.
  28. Event OnQuestInit()
  29. install()
  30. RegisterForRemoteEvent(Game.GetPlayer(), "OnPlayerLoadGame")
  31. ;TODO - remove if you dont want to use a while loop
  32. checkForUninstall()
  33. EndEvent
  34.  
  35. ;Calls the install function everytime the player loads his game. If you are adding many categories, you should stop
  36. ;the time first. If your script runs longer then a few seconds, remove this event and the line
  37. ;RegisterForRemoteEvent(Game.GetPlayer(), "OnPlayerLoadGame") above
  38. ;This event is a safety feature, in case some other mod calls the revert() function on one of the formlists you want
  39. ;to edit.
  40. Event Actor.OnPlayerLoadGame(Actor actorref)
  41. install()
  42. ;TODO - remove if you dont want to use a while loop
  43. checkForUninstall()
  44. EndEvent
  45.  
  46. ;This function adds your new menus or categories to the vanilla formlists
  47. Function install()
  48. ;TODO - Adjust this function to your needs.
  49. ;Add your new keywords and / or formlists to the vanilla ones here
  50. ;=======================================================
  51.  
  52. VanillaWorkshopMenu.addForm(CustomWorkshopMenu)
  53. VanillaWorkshopMenu.addForm(CustomWorkshopCategory)
  54. ;...
  55.  
  56. ;"if (Menu.hasForm(form))" is not needed, because formlists cannot contain the same form twice
  57. EndFunction
  58.  
  59. ;====================================================================================================================
  60. ;Remove your new forms manually (for example using an uninstall chem...). This will not work if your mod has already
  61. ;been uninstalled.
  62. ;====================================================================================================================
  63.  
  64. ;This Function is called to uninstall your new categories manually and will only work as long as your mod is still
  65. ;active.
  66. Function uninstall_manually()
  67. ;TODO This function is called to uninstall your mod. Remove all forms you added above here.
  68. ;=======================================================
  69. VanillaWorkshopMenu.RemoveAddedForm(CustomWorkshopMenu)
  70. VanillaWorkshopMenu.RemoveAddedForm(CustomWorkshopCategory)
  71. ;...
  72. EndFunction
  73.  
  74. ;TODO - Remove everything belwo if your don't want to call a possibly endless while loop
  75. ;====================================================================================================================
  76. ;Remove none values automatically after your mod was uninstalled. This will not work if your mod is still active.
  77. ;====================================================================================================================
  78.  
  79. ;Checks if your plugin is still active. If not removes every none value from the vanilla formlists.
  80. Function checkForUninstall()
  81. ;we only want the loop once
  82. if (!uninstallCheckRunning)
  83. uninstallCheckRunning = true
  84. ;TODO - replace YourMod.esp with the name of your esp
  85. while (Game.IsPluginInstalled("YourMod.esp"))
  86. Utility.wait(60) ;waits 60 seconds until the condition is checked again
  87. endwhile
  88. ;The plugin is no longer active. Now we have to remove every none value from the edited formlists.
  89.  
  90. ;TODO - Do this with every vanilla menu you edited
  91. removeNoneValues(VanillaWorkshopMenu)
  92. ;...
  93. uninstallCheckRunning = false
  94. endif
  95. EndFunction
  96.  
  97. ;This function removes all none values from a formlist.
  98. Function removeNoneValues(Formlist flst)
  99. Formlist temp = flst
  100. ;revert the formlist to remove every form that was added with a script, including forms of other plugins
  101. VanillaWorkshopMenu.revert()
  102. int i = 0
  103. while (i < temp.getSize())
  104. if (temp.getAt(i)) ;true if the form at index i is not none
  105. flst.addForm(temp.getAt(i))
  106. ;"if (Menu.hasForm(form))" is not needed, because formlists cannot contain the same form twice
  107. endif
  108. i+=1
  109. endwhile
  110. EndFunction
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement