How do I implement new keys for the player with hero jumps as an example?

From OHRRPGCE-Wiki
Jump to navigation Jump to search
Revise.png
This article does not meet the standard of quality we would like to have. Feel free to revise it and make it better by using the edit link at the top of the page. This tag should be removed when an editor feels it is of high quality.

The reason this article has been marked is: If you want to make a hero or NPC jump in a cutscene, read How do I make an NPC or hero look like it's jumping? instead

Do you want the player to do more than just talking to NPCs and fighting monsters? Then you should add new keys!

This article explains you how to implement the new keys and only that. Believe me, it's rather difficult for a newbie. So if you want you hero to do something when a specific key is pressed, then work on that first.

We needed something for the hero to do as the key is pressed, so I choose jump which is also aviable on the website. Anyway, you will also need to know what a global variable is.

First we need to define the scripts:

  • In the example, I'm going to make the hero jump using the key Z.
  • I assume that script 16 is free.
  • I assume that global variable 11 is free.

If they are not, change the numbers so that you won't get any error message.

# Then the global variable...
Global variable (11, jump)


Now we write the actual scripts.


#-------------------------------------------
plotscript, onkeyispressedscript, begin

if (key is pressed(key: z)) then, begin 
my keyboard jump #The next script
end

# feel free to add any other keypress here.

end #end of the plotscript 

#-------------------------------------------
plotscript, my keyboard jump, begin

jump:=true

while (jump), do, begin

   put hero (me, hero pixel X (me),hero pixel Y (me)--12)
   wait (3)
   put hero (me, hero pixel X (me),hero pixel Y (me) +12)

   jump:=false
   wait (1) #wait here is very important
   end #end of the while command
   
end #end of the plotscript here
#-------------------------------------------

Compile the scirpt and import it into custom.

Now go back under custom, and on edit the maps, in which you want to be able to jump in. Go under its general map data and change the "On-keypress Script" from "none" to our newly made "onkeyispressedscript."

As you have seen above we've used an autonumber script. As said in the name, when these kinds of scripts don't need a number beacuse they are only launched in other plotscripts. So you cannot choose them when you edit the npcs or the text box conditionals.

  • Another thing you may wonder is, What did we use the global variable for? We used it to create what OHR developers call a while loop.
  • The while loop prevents the script for being loaded several times.
  • If you look at the code you will see that the global variable is turned false as the script ends.
  • But the hero can jump only while jump is true. If you cancel the lines jump:=false then the script will be load over and over again and your game will be (very) slow.
  • Another important line in the code is the wait(1) command. It prevents the game from freezing so DO NOT ERASE IT.

To finish, feel free to add several keys and autonumber scripts using the same method. Just be aware the script must stay as light as possible so do not put more than 7 keys.

Remember that, you have first to search what the hero will do, as the key is pressed, and be sure your code is good.

How do I make the new keys unactive while cutscenes?[edit]

You have implemented new keys, but the problem is that the player can press on it during ctscenes. You can stop this, and it's easy too. You use "set on keypressed script" command.

# include the following line before the suspend player command in your cutscene script.
set on keypress script (none)

And when the cutscene ends just add this simple line,

# include the following line after the the resume player command in your script
set on keypress script (@on key is pressed script)

See Also[edit]