Difference between revisions of "Options Menu"

86 bytes added ,  13:25, 12 April 2012
m
Changed first example to OnContainerChanged()
imported>JustinOther
imported>JustinOther
m (Changed first example to OnContainerChanged())
Line 2: Line 2:
[[Category:Papyrus]]
[[Category:Papyrus]]
== Overview ==
== Overview ==
Using [[Show - Message]], it is possible to make an options menu with any number of buttons and/or levels. In this example, we'll use a playable apparel item, but a menu can be prompted and managed in a number of ways. First off, create a message form and add/fill in its buttons. Note that no more than ten buttons can be offered by any given message box and that the button indices are offset by one such that the first option's index is 0 and not 1.
Using [[Show - Message]], it is possible to make an options menu with any number of buttons and/or levels. In these examples, we'll use apparel items, but a menu can be prompted and managed in a number of ways. First off, create a message form and add/fill in its buttons. Note that no more than ten buttons can be offered by any given message box and that the button indices are offset by one such that the first option's index is 0 and not 1.


== Examples ==
== Examples ==
*For the first example, we'll have only three options: Mage, Thief, and Warrior. Each time the item is equipped by the player, the menu will be prompted and will exit as soon as a button is selected, executing the appropriate code.
*For the first example, we'll have only three options: Mage, Thief, and Warrior. The token should be unplayable in this case. When the item is added to the player, the menu will be prompted and will exit as soon as a button is selected, executing the appropriate code.


<source lang="papyrus">ScriptName OptionsMenuScript extends ObjectReference
<source lang="papyrus">ScriptName OptionsMenuScript extends ObjectReference
Line 11: Line 11:
Message Property OptionsMESG Auto
Message Property OptionsMESG Auto


Event OnEquipped(Actor akActor)
Event OnContainerChanged(ObjectReference akNewContainer, ObjectReference akOldContainer)


If akActor == Game.GetPlayer() ; Only the player
If akNewContainer == Game.GetPlayer() ; Only the player
Game.DisablePlayerControls(False, False, False, False, False, True) ; Momentarily disable other menus
akActor.EquipItem(GetBaseObject(), True, True) ; Prevent unequip/reequip in favorites until the current menu is resolved
Utility.Wait(0.01) ; This ensures equipping the token from the favorites menu works
akActor.UnequipItem(GetBaseObject(), False, True) ; Silently unequip item
Game.EnablePlayerControls(False, False, False, False, False, True) ; Undo DisablePlayerControls
Int iButton = OptionsMESG.Show() ; Shows your menu. iButton == -1 until input
Int iButton = OptionsMESG.Show() ; Shows your menu. iButton == -1 until input
If (iButton == 0) ; Mage
If (iButton != =-1)
Debug.Notification("Mage selected")
If (iButton == 1)  ; Mage
ElseIf (iButton == 1) ; Thief
Debug.Notification("Mage selected")
Debug.Notification("Thief selected")
ElseIf (iButton == 1) ; Thief
ElseIf (iButton == 2) ; Warrior
Debug.Notification("Thief selected")
Debug.Notification("Warrior selected")
ElseIf (iButton == 2) ; Warrior
Debug.Notification("Warrior selected")
EndIf
akNewContainer.RemoveItem(GetBaseObject(), 1, True) ; Silently remove token
EndIf
EndIf
EndIf
EndIf
EndEvent </source>
EndEvent </source>


*For the next example, we'll offer sub-options for each main selection. For a multilevel menu, a function works well. Keep in mind each message forms' buttons can have conditions, so you could hide "Lunch" and "Dinner" if it's time for breakfast or hide "Lobster" if it's not currently available.
*For the next example, we'll offer sub-options for each main selection. For a multilevel menu, a function works well. Keep in mind each message forms' buttons can have conditions, so you could hide "Lunch" and "Dinner" if it's time for breakfast or hide "Lobster" if it's not currently available. In this case, to make it repeatable, we'll use a playable apparel item so the menu will show each time it is equipped


<source lang="papyrus">ScriptName OptionsMenuScript extends ObjectReference
<source lang="papyrus">ScriptName OptionsMenuScript extends ObjectReference
Line 43: Line 42:


If akActor == Game.GetPlayer()
If akActor == Game.GetPlayer()
Game.DisablePlayerControls(False, False, False, False, False, True)
Game.DisablePlayerControls(False, False, False, False, False, True) ; Momentarily disable other menus
akActor.EquipItem(GetBaseObject(), True, True)
Game.GetPlayer().EquipItem(GetBaseObject(), True, True) ; Prevent unequip/reequip in favorites until the current menu is resolved
Utility.Wait(0.01)
Utility.Wait(0.01) ; This ensures equipping the token from the favorites menu works
akActor.UnequipItem(GetBaseObject(), False, True)
Game.GetPlayer().UnequipItem(GetBaseObject(), False, True) ; Silently unequip item
Game.EnablePlayerControls(False, False, False, False, False, True)
Game.EnablePlayerControls(False, False, False, False, False, True) ; Undo DisablePlayerControls
Menu()
Menu()
EndIf
EndIf
Anonymous user