gribbleshnibit8

Dynamic Message Box with NVSE

Oct 14th, 2013
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.53 KB | None | 0 0
  1. scn VMMAutomatVendingMachineSCRIPT
  2.  
  3. ; DON'T CHANGE THESE
  4. int iMenu ; THESE VARIABLES MUST BE HERE!
  5. int iButton ; THEY ARE NEEDED BY THE SCRIPT IN ORDER FOR IT TO
  6. int iIndex ; WORK CORRECTLY!
  7. int iMenuSize ; DO NOT REMOVE ANY OF THEM!
  8. int iPage ;
  9. int iPageCount ; I'M SERIOUS, DON'T REMOVE THEM!
  10. ref rSelected ;
  11. ref rObject ; UNLESS YOU KNOW WHAT YOU ARE DOING, THEN IT'S OK.
  12.  
  13. ; ITEM VARS
  14. ref rItem1 ; 8 is the maximum number that any properly designed
  15. ref rItem2 ; menu should have because you should always have a
  16. ref rItem3 ; cancel button and a next page button on every page.
  17. ref rItem4
  18. ref rItem5 ; Remove any of these you don't need to keep the
  19. ref rItem6 ; script clean.
  20. ref rItem7
  21. ref rItem8
  22.  
  23. ; The maximum number of items that can be shown on a page. Change this in
  24. ; the OnLoad block to reflect the number of items you want displayed on
  25. ; each page of your menu.
  26. int menuMaxSize
  27.  
  28. ; Add any variables you need under here
  29.  
  30.  
  31. BEGIN OnLoad ; =================================================================================
  32. if (YourModNVSEErrorVariable)
  33. Return
  34. endif
  35. set menuMaxSize to 8
  36. END
  37.  
  38.  
  39. BEGIN OnActivate Player ; =========================================================================
  40. if (YourModNVSEErrorVariable)
  41. Return
  42. endif
  43. set iMenu to 5
  44. END
  45.  
  46.  
  47. BEGIN GameMode ; =================================================================================
  48. if (iMenu == 0) ; This just returns from here if we aren't in menu mode
  49. Return ; Doing this helps optimize our script, because the
  50. endif ; fallout engine is stupid.
  51.  
  52. if (iMenu > 0)
  53. if (iMenu == 5)
  54. set fTmp to (listGetCount MenuListNameHere) / menuMaxSize ; This block gets the length of the list (keep in mind
  55. if (fTmp == 0) ; that ListGetCount returns the length of the list
  56. set iPageCount to 0 ; starting at 1) and determines how many, if any, pages
  57. else ; the menu will have.
  58. set iPageCount to ceil fTmp ;
  59. endif ;
  60. set iPage to 0
  61. set iMenu to 10
  62. elseif (iMenu == 10) ; Menu Display
  63. set iIndex to iPage * menuMaxSize ; This block will get the items from the menu object list.
  64. set rItem1 to ListGetNthForm MenuListNameHere iIndex ; It works per each page, multiplying the page number by the
  65. set iIndex to iPage * menuMaxSize + 1 ; number of objects that can be on a page, and sets each var
  66. set rItem2 to ListGetNthForm MenuListNameHere iIndex ; accordingly.
  67. set iIndex to iPage * menuMaxSize + 2 ;
  68. set rItem3 to ListGetNthForm MenuListNameHere iIndex ; If you need to perform additional work with your items
  69. set iIndex to iPage * menuMaxSize + 3 ; before they go to the menu code, do it here. Things like
  70. set rItem4 to ListGetNthForm MenuListNameHere iIndex ; getting the value etc can be done at each item as it is
  71. set iIndex to iPage * menuMaxSize + 4 ; found.
  72. set rItem5 to ListGetNthForm MenuListNameHere iIndex ;
  73. set iIndex to iPage * menuMaxSize + 5 ; Remove the lines for any objects you don't need, such as if
  74. set rItem6 to ListGetNthForm MenuListNameHere iIndex ; you make your menu only have 6 or 7 max items.
  75. set iIndex to iPage * menuMaxSize + 6 ;
  76. set rItem7 to ListGetNthForm MenuListNameHere iIndex ; Example:
  77. set iIndex to iPage * menuMaxSize + 7 ; iPage=2, menuMaxSize=8, i=button
  78. set rItem8 to ListGetNthForm MenuListNameHere iIndex ; 2*8=16+i tells us to get the 16+i item from the list.
  79.  
  80. ; This is where the 'magic' happens. NVSE MessageBoxEx is used to generate dynamic messages with your own data and
  81. ; custom named buttons that can hold all kinds of information. A few limitations here:
  82. ; 1) The function can take a maximum of 20 variables, we're already using 8
  83. ; 2) These message boxes cannot have a title, though that is minor compared to dynamic button names
  84. ; 3) We have to have this big mess in order to create all the options, and it's a pain!
  85. if (iPageCount > 1)
  86. if (rItem8 != 0)
  87. MessageBoxEx "MenuTitleOrInformationHere|%n|%n|%n|%n|%n|%n|%n|%n|Next page >|Cancel" rItem1 rItem2 rItem3 rItem4 rItem5 rItem6 rItem7 rItem8
  88. set iMenuSize to 10
  89. elseif (rItem7 != 0)
  90. MessageBoxEx "MenuTitleOrInformationHere|%n|%n|%n|%n|%n|%n|%n|Next page >|Cancel" rItem1 rItem2 rItem3 rItem4 rItem5 rItem6 rItem7
  91. set iMenuSize to 9
  92. elseif (rItem6 != 0)
  93. MessageBoxEx "MenuTitleOrInformationHere|%n|%n|%n|%n|%n|%n|Next page >|Cancel" rItem1 rItem2 rItem3 rItem4 rItem5 rItem6
  94. set iMenuSize to 8
  95. elseif (rItem5 != 0)
  96. MessageBoxEx "MenuTitleOrInformationHere|%n|%n|%n|%n|%n|Next page >|Cancel" rItem1 rItem2 rItem3 rItem4 rItem5
  97. set iMenuSize to 7
  98. elseif (rItem4 != 0)
  99. MessageBoxEx "MenuTitleOrInformationHere|%n|%n|%n|%n|Next page >|Cancel" rItem1 rItem2 rItem3 rItem4
  100. set iMenuSize to 6
  101. elseif (rItem3 != 0)
  102. MessageBoxEx "MenuTitleOrInformationHere|%n|%n|%n|Next page >|Cancel" rItem1 rItem2 rItem3
  103. set iMenuSize to 5
  104. elseif (rItem2 != 0)
  105. MessageBoxEx "MenuTitleOrInformationHere|%n|%n|Next page >|Cancel" rItem1 rItem2
  106. set iMenuSize to 4
  107. else
  108. MessageBoxEx "MenuTitleOrInformationHere|%n|Next page >|Cancel" rItem1
  109. set iMenuSize to 3
  110. endif
  111. else
  112. if (rItem8 != 0)
  113. MessageBoxEx "MenuTitleOrInformationHere|%n|%n|%n|%n|%n|%n|%n|%n|Cancel" rItem1 rItem2 rItem3 rItem4 rItem5 rItem6 rItem7 rItem8
  114. set iMenuSize to 9
  115. elseif (rItem7 != 0)
  116. MessageBoxEx "MenuTitleOrInformationHere|%n||%n%n|%n|%n|%n|%n|Cancel" rItem1 rItem2 rItem3 rItem4 rItem5 rItem6 rItem7
  117. set iMenuSize to 8
  118. elseif (rItem6 != 0)
  119. MessageBoxEx "MenuTitleOrInformationHere|%n|%n|%n|%n|%n|%n|Cancel" rItem1 rItem2 rItem3 rItem4 rItem5 rItem6
  120. set iMenuSize to 7
  121. elseif (rItem5 != 0)
  122. MessageBoxEx "MenuTitleOrInformationHere|%n|%n|%n|%n|%n|Cancel" rItem1 rItem2 rItem3 rItem4 rItem5
  123. set iMenuSize to 6
  124. elseif (rItem4 != 0)
  125. MessageBoxEx "MenuTitleOrInformationHere|%n|%n|%n|%n|Cancel" rItem1 rItem2 rItem3 rItem4
  126. set iMenuSize to 5
  127. elseif (rItem3 != 0)
  128. MessageBoxEx "MenuTitleOrInformationHere|%n|%n|%n|Cancel" rItem1 rItem2 rItem3
  129. set iMenuSize to 4
  130. elseif (rItem2 != 0)
  131. MessageBoxEx "MenuTitleOrInformationHere|%n|%n|Cancel" rItem1 rItem2
  132. set iMenuSize to 3
  133. else
  134. MessageBoxEx "MenuTitleOrInformationHere|%n|Cancel" rItem1
  135. set iMenuSize to 2
  136. endif
  137. endif
  138. set iMenu to 11
  139. Return
  140. elseif (iMenu == 11) ; Selected an item
  141. set iButton to GetButtonPressed
  142. if (iButton > -1)
  143. ; Handle "Cancel" ; We want to handle cancel first because it exits the menu.
  144. if (iButton == (iMenuSize - 1)) ; This is checking the menu size as set in the menu minus the
  145. set iMenu to 0 ; button value. Buttons start at value 0-9, so keep that in
  146. Return ; mind when making other lengths of menu.
  147. endif
  148. ; Handle "Next page >" ; Here we want to handle the next page button, when it exists.
  149. if (iPageCount > 1) ; To make sure it exists first, we check that we're showing more
  150. if (iButton == (iMenuSize - 2)) ; than one page. Then we set the page count up one, make sure
  151. set iPage to iPage + 1 ; it hasn't gone over our max page count, and return back to
  152. if (iPage >= iPageCount) ; the top to display the menu again.
  153. set iPage to 0 ; This shouldn't ever need to be edited, except if you add another
  154. endif ; button that needs to exist on both menus. There will be an
  155. set iMenu to 10 ; example of that included with this file.
  156. Return
  157. endif
  158. endif
  159. ; Now that we've done all that setup work we can actually do something with the value we find.
  160. ; Here we first get the index of the button clicked by doing pretty much the same math that was done above.
  161. ; Then we look in a list to find the object we want to use. This list can be the menu item list, or it can
  162. ; be another list, so long as both lists have the same number of items, and are ordered properly such that
  163. ; the items at each index of the menu list have coresponding items in the other list used here.
  164. ; This area is very flexible. It can even be used to show another menu, including actually doing everything
  165. ; we've already done again. For examples of that see http://newvegas.nexusmods.com/mods/48200
  166. set iIndex to iPage * menuMaxSize + iButton
  167. set rSelected to listGetNthForm MenuListNameHere iIndex
  168.  
  169. Return
  170. endif
  171. endif
  172. endif
  173. END
Advertisement
Add Comment
Please, Sign In to add comment