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

From OHRRPGCE-Wiki

(Difference between revisions)
Jump to: navigation, search
(menu scripts no longer WIP)
(Script Instead Of Menu: correct script for held down keys)
 
Line 45: Line 45:
In order to prevent the menu from coming up at all, so that you can replace it with your own custom menu, 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.
In order to prevent the menu from coming up at all, so that you can replace it with your own custom menu, 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 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 calling the menu.
+
The 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 calling 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:
<pre>
<pre>
Line 53: Line 53:
   if (key is pressed (key: esc), or, key is pressed (key: alt)) then (
   if (key is pressed (key: esc), or, key is pressed (key: alt)) then (
     suspend player
     suspend player
-
     wait (1)
+
 +
     #script goes here...
 +
 +
    while (key is pressed (key: esc), or, key is pressed (key: alt)) then (
 +
      wait (1)
 +
    )
     resume player
     resume player
-
    #script gos here...
 
   )
   )
end
end
</pre>
</pre>
-
 
==See Also==
==See Also==

Current revision as of 05:31, 2 November 2009

Contents

[edit] New Way

Starting with the voxhumana release, the OHRRPGCE supports user defined menus which include script triggers.

Revise.png
This article or section is not complete. If you wish, you may finish it, and remove this tag when you are done.

needs example

[edit] Old Way

Obsolete.png
This article (or part thereof) is obsolete. It may have made sense in the past, but it does not make sense now. It is kept here only for historic curiosity and/or posterity.

Running a script before the menu comes up is easy enough. All you need is an on-key-press script that checks for the escape or alt keys. The other two are minor variations.

[edit] Script Before Menu

Use an on-key-press script (set in general map data) that checks for the Esc or alt keys being pressed:

include, scancode.hsi

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

You can't use wait commands in such a script (see below for reason). If you need to use wait commands, you need to disable the menu altogether.

[edit] Script After Menu

To make a script run after the menu closes, you need to add a single wait command to the front of the script code. When a menu key is pressed, the script interpreter runs your script and runs into the wait command. At this, it will stop interpreting, and GAME.EXE will get on with other things. Finding that esc was pressed, it will bring up the menu and concentrate on that until the player closes the menu. To the plotscript, only one tick has passed in all this time because GAME.EXE moved into a different state while displaying the menu.

include, scancode.hsi

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

[edit] Script Instead Of Menu

In order to prevent the menu from coming up at all, so that you can replace it with your own custom menu, 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 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 calling 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:

include, scancode.hsi

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

[edit] See Also