How can I run a script instead of/before/after the menu comes up?

From OHRRPGCE-Wiki
Jump to navigation Jump to search

Script After Menu[edit]

Starting with the voxhumana release, the OHRRPGCE supports user defined menus which include script triggers. To make a script run after the main menu closes, set it as the "On close" script of the main menu in the menu editor.

Script Before/On Opening Menu[edit]

Note that if you want a script to run while the menu is displayed then you need to turn on the "Allow gameplay and scripts" menu bitset.

One Way[edit]

Running a script before the menu comes up is easy. You can set a script as the Menu-action plotscript in the Special Plotscripts menu. This will cause the main menu to not open, so you will need to open it manually in your script:

plotscript, my main menu, begin
  open menu(0)  # The main menu
  #Rest of script goes here...
end

Another Way[edit]

Here is an alternative way to do this, using an on-key-press script (set in general map data; you will need to set it on every map) that checks for the escape or alt keys. (Note! The engine checks the 'filtered alt' key, not the plain alt key!)

plotscript, my key handler, begin
  if (key is pressed (key: esc), or, key is pressed (key: filtered alt)) then (
    #script goes here...
  )
end

Script Instead Of Menu[edit]

Set a plotscript which you want to be run when the player presses the menu key as the Menu-action plotscript in the Special Plotscripts menu.

The Old Way[edit]

For completeness, here is an alternative way to prevent the menu from coming up at all that doesn't use the Menu-action script trigger, so that you can replace it something else using a regular on-keypress plotscript.

The player must be suspended at the instant the game checks whether it should pull up the menu, and there are two ways to implement this. The first is to suspend player for the entire game, or map, or scene as the case may be. This isn't an easy solution, because you will have to write scripts to handle all of the things you have disabled, like moving the hero when the player pushes an arrow key.

The much simpler solution is to suspend the player for one tick when esc or alt is pressed, and then resume it again after Game.exe has been fooled into not displaying the menu. To make sure that the menu doesn't appear if the holds down alt or space, even when the "Allow double triggering of scripts" general bitset is not set, you need to use a while loop. The following is written to work even if your script code contains wait commands:

plotscript, my key handler, begin
  if (key is pressed (key: esc), or, key is pressed (key: filtered alt)) then (
    suspend player
 
    #script goes here...
 
    while (key is pressed (key: esc), or, key is pressed (key: filtered alt)) do (
      wait (1)
    )
    resume player
  )
end

See Also[edit]