Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- scn VMMAutomatVendingMachineSCRIPT
- ; DON'T CHANGE THESE
- int iMenu ; THESE VARIABLES MUST BE HERE!
- int iButton ; THEY ARE NEEDED BY THE SCRIPT IN ORDER FOR IT TO
- int iIndex ; WORK CORRECTLY!
- int iMenuSize ; DO NOT REMOVE ANY OF THEM!
- int iPage ;
- int iPageCount ; I'M SERIOUS, DON'T REMOVE THEM!
- ref rSelected ;
- ref rObject ; UNLESS YOU KNOW WHAT YOU ARE DOING, THEN IT'S OK.
- ; ITEM VARS
- ref rItem1 ; 8 is the maximum number that any properly designed
- ref rItem2 ; menu should have because you should always have a
- ref rItem3 ; cancel button and a next page button on every page.
- ref rItem4
- ref rItem5 ; Remove any of these you don't need to keep the
- ref rItem6 ; script clean.
- ref rItem7
- ref rItem8
- ; The maximum number of items that can be shown on a page. Change this in
- ; the OnLoad block to reflect the number of items you want displayed on
- ; each page of your menu.
- int menuMaxSize
- ; Add any variables you need under here
- BEGIN OnLoad ; =================================================================================
- if (YourModNVSEErrorVariable)
- Return
- endif
- set menuMaxSize to 8
- END
- BEGIN OnActivate Player ; =========================================================================
- if (YourModNVSEErrorVariable)
- Return
- endif
- set iMenu to 5
- END
- BEGIN GameMode ; =================================================================================
- if (iMenu == 0) ; This just returns from here if we aren't in menu mode
- Return ; Doing this helps optimize our script, because the
- endif ; fallout engine is stupid.
- if (iMenu > 0)
- if (iMenu == 5)
- set fTmp to (listGetCount MenuListNameHere) / menuMaxSize ; This block gets the length of the list (keep in mind
- if (fTmp == 0) ; that ListGetCount returns the length of the list
- set iPageCount to 0 ; starting at 1) and determines how many, if any, pages
- else ; the menu will have.
- set iPageCount to ceil fTmp ;
- endif ;
- set iPage to 0
- set iMenu to 10
- elseif (iMenu == 10) ; Menu Display
- set iIndex to iPage * menuMaxSize ; This block will get the items from the menu object list.
- set rItem1 to ListGetNthForm MenuListNameHere iIndex ; It works per each page, multiplying the page number by the
- set iIndex to iPage * menuMaxSize + 1 ; number of objects that can be on a page, and sets each var
- set rItem2 to ListGetNthForm MenuListNameHere iIndex ; accordingly.
- set iIndex to iPage * menuMaxSize + 2 ;
- set rItem3 to ListGetNthForm MenuListNameHere iIndex ; If you need to perform additional work with your items
- set iIndex to iPage * menuMaxSize + 3 ; before they go to the menu code, do it here. Things like
- set rItem4 to ListGetNthForm MenuListNameHere iIndex ; getting the value etc can be done at each item as it is
- set iIndex to iPage * menuMaxSize + 4 ; found.
- set rItem5 to ListGetNthForm MenuListNameHere iIndex ;
- set iIndex to iPage * menuMaxSize + 5 ; Remove the lines for any objects you don't need, such as if
- set rItem6 to ListGetNthForm MenuListNameHere iIndex ; you make your menu only have 6 or 7 max items.
- set iIndex to iPage * menuMaxSize + 6 ;
- set rItem7 to ListGetNthForm MenuListNameHere iIndex ; Example:
- set iIndex to iPage * menuMaxSize + 7 ; iPage=2, menuMaxSize=8, i=button
- set rItem8 to ListGetNthForm MenuListNameHere iIndex ; 2*8=16+i tells us to get the 16+i item from the list.
- ; This is where the 'magic' happens. NVSE MessageBoxEx is used to generate dynamic messages with your own data and
- ; custom named buttons that can hold all kinds of information. A few limitations here:
- ; 1) The function can take a maximum of 20 variables, we're already using 8
- ; 2) These message boxes cannot have a title, though that is minor compared to dynamic button names
- ; 3) We have to have this big mess in order to create all the options, and it's a pain!
- if (iPageCount > 1)
- if (rItem8 != 0)
- MessageBoxEx "MenuTitleOrInformationHere|%n|%n|%n|%n|%n|%n|%n|%n|Next page >|Cancel" rItem1 rItem2 rItem3 rItem4 rItem5 rItem6 rItem7 rItem8
- set iMenuSize to 10
- elseif (rItem7 != 0)
- MessageBoxEx "MenuTitleOrInformationHere|%n|%n|%n|%n|%n|%n|%n|Next page >|Cancel" rItem1 rItem2 rItem3 rItem4 rItem5 rItem6 rItem7
- set iMenuSize to 9
- elseif (rItem6 != 0)
- MessageBoxEx "MenuTitleOrInformationHere|%n|%n|%n|%n|%n|%n|Next page >|Cancel" rItem1 rItem2 rItem3 rItem4 rItem5 rItem6
- set iMenuSize to 8
- elseif (rItem5 != 0)
- MessageBoxEx "MenuTitleOrInformationHere|%n|%n|%n|%n|%n|Next page >|Cancel" rItem1 rItem2 rItem3 rItem4 rItem5
- set iMenuSize to 7
- elseif (rItem4 != 0)
- MessageBoxEx "MenuTitleOrInformationHere|%n|%n|%n|%n|Next page >|Cancel" rItem1 rItem2 rItem3 rItem4
- set iMenuSize to 6
- elseif (rItem3 != 0)
- MessageBoxEx "MenuTitleOrInformationHere|%n|%n|%n|Next page >|Cancel" rItem1 rItem2 rItem3
- set iMenuSize to 5
- elseif (rItem2 != 0)
- MessageBoxEx "MenuTitleOrInformationHere|%n|%n|Next page >|Cancel" rItem1 rItem2
- set iMenuSize to 4
- else
- MessageBoxEx "MenuTitleOrInformationHere|%n|Next page >|Cancel" rItem1
- set iMenuSize to 3
- endif
- else
- if (rItem8 != 0)
- MessageBoxEx "MenuTitleOrInformationHere|%n|%n|%n|%n|%n|%n|%n|%n|Cancel" rItem1 rItem2 rItem3 rItem4 rItem5 rItem6 rItem7 rItem8
- set iMenuSize to 9
- elseif (rItem7 != 0)
- MessageBoxEx "MenuTitleOrInformationHere|%n||%n%n|%n|%n|%n|%n|Cancel" rItem1 rItem2 rItem3 rItem4 rItem5 rItem6 rItem7
- set iMenuSize to 8
- elseif (rItem6 != 0)
- MessageBoxEx "MenuTitleOrInformationHere|%n|%n|%n|%n|%n|%n|Cancel" rItem1 rItem2 rItem3 rItem4 rItem5 rItem6
- set iMenuSize to 7
- elseif (rItem5 != 0)
- MessageBoxEx "MenuTitleOrInformationHere|%n|%n|%n|%n|%n|Cancel" rItem1 rItem2 rItem3 rItem4 rItem5
- set iMenuSize to 6
- elseif (rItem4 != 0)
- MessageBoxEx "MenuTitleOrInformationHere|%n|%n|%n|%n|Cancel" rItem1 rItem2 rItem3 rItem4
- set iMenuSize to 5
- elseif (rItem3 != 0)
- MessageBoxEx "MenuTitleOrInformationHere|%n|%n|%n|Cancel" rItem1 rItem2 rItem3
- set iMenuSize to 4
- elseif (rItem2 != 0)
- MessageBoxEx "MenuTitleOrInformationHere|%n|%n|Cancel" rItem1 rItem2
- set iMenuSize to 3
- else
- MessageBoxEx "MenuTitleOrInformationHere|%n|Cancel" rItem1
- set iMenuSize to 2
- endif
- endif
- set iMenu to 11
- Return
- elseif (iMenu == 11) ; Selected an item
- set iButton to GetButtonPressed
- if (iButton > -1)
- ; Handle "Cancel" ; We want to handle cancel first because it exits the menu.
- if (iButton == (iMenuSize - 1)) ; This is checking the menu size as set in the menu minus the
- set iMenu to 0 ; button value. Buttons start at value 0-9, so keep that in
- Return ; mind when making other lengths of menu.
- endif
- ; Handle "Next page >" ; Here we want to handle the next page button, when it exists.
- if (iPageCount > 1) ; To make sure it exists first, we check that we're showing more
- if (iButton == (iMenuSize - 2)) ; than one page. Then we set the page count up one, make sure
- set iPage to iPage + 1 ; it hasn't gone over our max page count, and return back to
- if (iPage >= iPageCount) ; the top to display the menu again.
- set iPage to 0 ; This shouldn't ever need to be edited, except if you add another
- endif ; button that needs to exist on both menus. There will be an
- set iMenu to 10 ; example of that included with this file.
- Return
- endif
- endif
- ; Now that we've done all that setup work we can actually do something with the value we find.
- ; Here we first get the index of the button clicked by doing pretty much the same math that was done above.
- ; 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
- ; be another list, so long as both lists have the same number of items, and are ordered properly such that
- ; the items at each index of the menu list have coresponding items in the other list used here.
- ; This area is very flexible. It can even be used to show another menu, including actually doing everything
- ; we've already done again. For examples of that see http://newvegas.nexusmods.com/mods/48200
- set iIndex to iPage * menuMaxSize + iButton
- set rSelected to listGetNthForm MenuListNameHere iIndex
- Return
- endif
- endif
- endif
- END
Advertisement
Add Comment
Please, Sign In to add comment