How do I prevent the player from popping up the menu?

From OHRRPGCE-Wiki
Jump to navigation Jump to search

The best way to do this is to use suspend player and interpret keystrokes. It's like you were customizing the keyboard, and not implement a function to pop up the menu. Be aware that you won't be allowed to quit as long as the menu is locked !

But we will need a keypress script and to define the global variable we are going to use

Global variable (11, loopkey)
Global variable (12, menulocked)

plotscript, keypress for locked menu, begin

loopkey:=true 
# the global variable loopkey prevents from overloading the script

if (key is pressed(key:esc), xor, key is pressed(key:alt)) then, begin
suspend player
wait(1)
resume player
end

loopkey:=false
wait(1) # wait (1) is very important: it's a while loop. DO NOT ERASE IT
end 

And now the script that will locked and unlocked the menu

# The script prevents the player from poping up the menu
plotscript, menu locked, begin  

set on keypress script (16)
# locked the menu even after a saved game
menu locked:=true
wait(1)
show text box (15) #keyboard is locked
wait for text box

end# end of the plotscript

#---------------------------------------------------------------------------

plotscript, menu unlocked, begin

set on keypress script (none)
# if you are already using a keypress script, change none to the number of your keypress script
menu locked:=false
wait (1) # wait (1) is very important: it's a while loop. DO NOT ERASE IT!

show text box (17) #keyboard is unlocked. Feel free to use the menu again!
wait for text box

end #end of plotscript
#----------------------------------------------------------------------------


And finally here is the key point: the while loop that what make the script able to start. (If you already have a autorun script, just add the third following lines)


#----------------------------------------------------------------------------
plotscript, autorun script for map3, begin

while ((menu locked)==true) do, begin 
menu locked
end 

end #this end for the autorun script
#----------------------------------------------------------------------------

Once you have include all those lines in your code edit custom. Go to the script managment menu and import your hs file. Pick 2 text boxes and write the text in it. Choose a map and give it the autorun script. (I have chosen map3 for the example and pick up two Npcs. Give them "menu locked" and "menu unlocked script"

Hey wait! What should I do if I can't quit? Well, in that case you shall use ctrl+alt+del but it's not likely to happen. Remember? I've made you use npcs and one of them can unlock the menu and so you can quit the game normally!. You talk to npc2 that locked the menu and then to npc4 that unlocked it! (Note that you can do it several times if you want)

How to use those scripts clearly? I highly recommend you if you want for some reasons to prevent the player from popping the menu up to do it only temporaly EXCEPT IF you have made a highly-advanced game design that include a clean (and adapted) quit game function. (Feel to find original way to use the "game over" command if you feel that's fine for your game!)

Please note that we are using a while loop so we don't need any tags in the load game script!

To conclude:[edit]

Of course, you'll want to give it back sooner or later, or at least put in some kind of exit function, or the player won't be able to exit GAME. It's all right to want to make a game people just can't stop playing, but that's not meant to be taken literally.