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

From OHRRPGCE-Wiki
Jump to: navigation, 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]

Running a script before the menu comes up is easy enough. All you need is 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 that if you want the script to continue running while the menu is displayed then you need to turn on the "Allow gameplay and scripts" menu bitset.

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

Script Instead Of Menu[edit]

In order to prevent the menu from coming up at all, so that you can replace it something else, 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: alt)) then (
    suspend player
 
    #script goes here...
 
    while (key is pressed (key: esc), or, key is pressed (key: alt)) then (
      wait (1)
    )
    resume player
  )
end

See Also[edit]