Jump to content

how to use the OnMenuOpen() event handler


chenwen0624

Recommended Posts

Hello.I am new to TES scripting,and have been using papyrus for a few days.the Creation Kit Wiki said mostly "you must attach a script to an object in the Creation Kit before it will run."that's understandable but i don't know where i can attach my script to if i wish it just run when a menu pops up(i.e,I wish my codes run when Racesexmenu opens).

Then I found this event handler on CK wiki ---- OnMenuOpen and thought i might put the codes in it.but still dont know where to attach the script,if not been attached to anything it won't be execute by itself right?

Link to comment
Share on other sites

A script needs to be attached to something and the something to which it is attached will make different options available to run within it. For example, you can check when a weapon is equipped, an actor stands up, an item quantity changes and so on.

 

You want to run something that happens every time the player opens the menu with your mod installed? if so, then you're best bet is to add a new, constant-effect ability to the player via a quest. If you only want your effect to occur under other circumstances (such as while player has an item equipped, is a werewolf, joins a faction, etc) there are other ways, but this way is a simple method.

 

Create a new constant effect Magic Effect. Make it type Script -> Constant Effect -> Self. Attach the script you wish to run to this. Mark it "Hide in UI" if you'd like to keep it hidden from the player.

Create a new constant effect Ability, to which you should add the above magic effect.

Create a new quest that starts on loading, with two stages. Attach a script that gives the player your ability, and sets the quest stage to complete.

 

The magic effect script would be reasonably straightforward, along the lines of:

 

Event OnEffectStart(Target, Caster)
    RegisterForMenu("MENU NAME 1")
    RegisterForMenu("MENU NAME 2")
EndEvent

Event OnMenuOpen(OpenedMenu)
    if (OpenedMenu == "MENU NAME 1")
         Do Stuff
         RegisterForMenu("MENU NAME 1")
    elseif (OpenedMenu == "MENU NAME 2")
         Do Other Stuff
         RegisterForMenu("MENU NAME 2")
    endif
EndEvent

 

A list of valid menu names is listed on the CK Wiki here. Note you'll need the latest SKSE installed as these functions aren't available in the vanilla CK. Obviously player's will also need SKSE to use this mod.

 

Thinking about it, it could actually be done with just a quest I think, without even needing to be attached to the player. Guess which approach depends on what you wish to do whenever the menu opens.

Link to comment
Share on other sites

Nooooooooooooooooooo, do not use magic effects! Why are people doing this?

 

Make a new quest > Quest Alias Tab > Right click and create new reference alias.

 

An alias can attach data to most anything safely and then safely remove it when the quest is stopped. Read more about how an alias works.

>Name alias - Player

>Click the Specific Reference bubble > select forced reference

> Set the cell to {any} and the ref will auto fill to playerREF

 

In the script window attach this script. Remember reference aliases must extend... ReferenceAlias

 

 

ScriptName PlayerMenuScript extends ReferenceAlias

Event OnInit()
    RegisterForMenu("MENU NAME 1")
    RegisterForMenu("MENU NAME 2")
EndEvent

Event OnMenuOpen(OpenedMenu)
    if (OpenedMenu == "MENU NAME 1")
         Do Stuff
         RegisterForMenu("MENU NAME 1")
    elseif (OpenedMenu == "MENU NAME 2")
         Do Other Stuff
         RegisterForMenu("MENU NAME 2")
    endif
EndEvent

 

 

STOP ADDING MAGIC EFFECTS!

 

 

edit: when you make the quest its already setup the way you need it. Dont fill out anything on the Quest Data tab except the ID. the only purpose the quest serves is to provide an alias to bind a script to. Not a single quest stage is needed

Link to comment
Share on other sites

A script needs to be attached to something and the something to which it is attached will make different options available to run within it. For example, you can check when a weapon is equipped, an actor stands up, an item quantity changes and so on.

 

You want to run something that happens every time the player opens the menu with your mod installed? if so, then you're best bet is to add a new, constant-effect ability to the player via a quest. If you only want your effect to occur under other circumstances (such as while player has an item equipped, is a werewolf, joins a faction, etc) there are other ways, but this way is a simple method.

 

Create a new constant effect Magic Effect. Make it type Script -> Constant Effect -> Self. Attach the script you wish to run to this. Mark it "Hide in UI" if you'd like to keep it hidden from the player.

Create a new constant effect Ability, to which you should add the above magic effect.

Create a new quest that starts on loading, with two stages. Attach a script that gives the player your ability, and sets the quest stage to complete.

 

The magic effect script would be reasonably straightforward, along the lines of:

 

Event OnEffectStart(Target, Caster)
    RegisterForMenu("MENU NAME 1")
    RegisterForMenu("MENU NAME 2")
EndEvent

Event OnMenuOpen(OpenedMenu)
    if (OpenedMenu == "MENU NAME 1")
         Do Stuff
         RegisterForMenu("MENU NAME 1")
    elseif (OpenedMenu == "MENU NAME 2")
         Do Other Stuff
         RegisterForMenu("MENU NAME 2")
    endif
EndEvent

 

A list of valid menu names is listed on the CK Wiki here. Note you'll need the latest SKSE installed as these functions aren't available in the vanilla CK. Obviously player's will also need SKSE to use this mod.

 

Thinking about it, it could actually be done with just a quest I think, without even needing to be attached to the player. Guess which approach depends on what you wish to do whenever the menu opens.

 

Oh. :) you helped me a lot with how to make good use of Quests & Effects.Kudos

Link to comment
Share on other sites

Nooooooooooooooooooo, do not use magic effects! Why are people doing this?

 

Make a new quest > Quest Alias Tab > Right click and create new reference alias.

 

An alias can attach data to most anything safely and then safely remove it when the quest is stopped. Read more about how an alias works.

>Name alias - Player

>Click the Specific Reference bubble > select forced reference

> Set the cell to {any} and the ref will auto fill to playerREF

 

In the script window attach this script. Remember reference aliases must extend... ReferenceAlias

 

 

ScriptName PlayerMenuScript extends ReferenceAlias

Event OnInit()
    RegisterForMenu("MENU NAME 1")
    RegisterForMenu("MENU NAME 2")
EndEvent

Event OnMenuOpen(OpenedMenu)
    if (OpenedMenu == "MENU NAME 1")
         Do Stuff
         RegisterForMenu("MENU NAME 1")
    elseif (OpenedMenu == "MENU NAME 2")
         Do Other Stuff
         RegisterForMenu("MENU NAME 2")
    endif
EndEvent

 

 

STOP ADDING MAGIC EFFECTS!

 

 

edit: when you make the quest its already setup the way you need it. Dont fill out anything on the Quest Data tab except the ID. the only purpose the quest serves is to provide an alias to bind a script to. Not a single quest stage is needed

Thx for the reply!So i guess Aliases are like Refs or Pointers..I'll check it out on wiki.Really hope there's a Chinese translation though...

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...