CREATING A SPRINT/RUN KEY

How to turn another key on your keyboard into a button that will allow your hero to sprint/run when held down.

PROGRAMMING A SPRINT/RUN KEY


INTRODUCTION
Alright as a fresh member of the forums, I'd like to introduce myself. The name's Digital Koifish. I'm not really a big programmer, I'm more of a concept artist. You can see some of my stuff at digitalkoifish.blogspot.com.


TUTORIAL
So anyway, this tutorial is relatively simple. All the RM2K and RM2K3 pros already know how to do this but for those you who still wanna figure it out, here it is.

The basic idea I'm going to teach (or maybe rehash) today is how to program a button (like the shift key in my example) to make a character sprint when held down, or leave them walking when left neutral.

If you can read the coding and understand how to do it without me walking you through it, just skip to the last part where all the codes are as this is rather long winded for a short series of coding.


WHAT YOU NEED TO KNOW
-Common Events
-Variables


PROGRAMMING
So let's begin by creating some common events:

The first event you will want to create is for the running speed. So in a slot on your 'Common Events' tab in your 'Database' create an event for running speed and name it accordingly. I called mine hero.run. Now set this event to trigger on Call.

In this event you will basically set your hero's pace to run so double click in the event area and open the event editor. Then go to tab 2 in either RM2K or RM2K3 and go to Move Event. Select Hero for the event you want to move and then set the pace.

The trick to setting the pace is to first hit 'Decrease Move Speed' four or five times to default it to the lowest speed and then increase it to the desired speed as you please. This is so if you change the movement speed at a later point in the game and then try to use the sprint key, it won't mess up the speed your character will move.

I hit 'Decrease Move Speed' four times and then hit 'Increase Move Speed' three times.

Your event will look like this:

Move Event: Hero, Decrease Move Speed, Decrease Move Speed, Decrease Move Speed, Decrease Move Speed, Increase Move Speed, Increase Move Speed, Increase Move Speed


Now it's time to do the same for your next event. Event number two is to set the pace for your hero's walking pace. I named this one hero.walk. Set this one to trigger on Call also.

Do the same thing here with your movements. Hit 'Decrease Move Speed' four or five times, then hit 'Increase Move Speed' the number of times that is one less than your hero's running speed. In my case, I hit 'Decrease Move Speed' four times and then hit 'Increase Move Speed' only two times instead of three.

The second common event now looks like this:

Move Event: Hero, Decrease Move Speed, Decrease Move Speed, Decrease Move Speed, Decrease Move Speed, Increase Move Speed, Increase Move Speed

Now for the last event. The third event you will program will be for the key that you want to hold down to make your hero sprint. In my case, I chose the 'Shift' key. This is the most difficult part of the programming, but it's actually very mundane.

Create the last event and name it something regarding the key you want to press. I named mine key.pace. Set this one to Parallel Process. Now in the event, you will want to program in this order. First open up Key Input Processing--it's in the third tab of RM2K and RM2K3.

Now to program the button you will have to pick the one you wish to 'hotwire' the running feature to. I chose the Shift key so I checked only the shift key and unchecked all the others. Make note of the number next to the the key you want to program. The Shift key's number is 7. Make sure that you uncheck 'Wait Until Key Is Pressed'. Now go up to the top and make a variable to store the key in. I called mine key.run. This variable will basically store the fact that you want this one button to be mapped to another event this variable is mapped to.

Now create a Conditional Branch (I believe it's called Fork Event Options or something in RM2K). For the conditions, set it so that the variable that you stored your Sprint Key is in is 'Equal To' the number associated with that key. So for mine, I set it so that key.run is 'Equal To' 7 because the Shift key is mapped to the number 7. Hit Ok to get back into the 'if' area.

In the 'if' area you will create a Call Event that will call your running event (in my case it will call the event hero.run). This basically makes it so that if the Shift key is pressed, it will make the hero run. BUT WAIT! If you press the Shift key and have nothing else, the hero will constantly be at an increased pace! Which is where the 'Else Handler' comes in.

In the 'Else Handler' you will have to program what happens if you don't press the button. So in the 'Else Handler' create a Call Event to call your walking event (in my case hero.walk). AND NOW WHEN YOU DON'T PRESS THE SHIFT KEY DOWN, THE HERO WILL WALK! HOORAY!

The final event will look like this:

Key Input Proc: 0001:key.run
Branch if Var 0001:key.run is 7
Call Event: hero.run

:Else Handler
Call Event: hero.walk

:End



FINAL PROGRAMMING LOOK
Common Event: hero.run
Move Event: Hero, Decrease Move Speed, Decrease Move Speed, Decrease Move Speed, Decrease Move Speed, Increase Move Speed, Increase Move Speed, Increase Move Speed


Common Event: hero.walk
Move Event: Hero, Decrease Move Speed, Decrease Move Speed, Decrease Move Speed, Decrease Move Speed, Increase Move Speed, Increase Move Speed

Common Event: key.pace
Key Input Proc: 0001:key.run
Branch if Var 0001:key.run is 7
Call Event: hero.run

:Else Handler
Call Event: hero.walk

:End



VARIATIONS
This is also very easy, but you can make movement look more fluid by creating two different sprite sets with different leg gaits. As it is now, the event will only make the hero sprite look like he/she is speed walking but if you wanted to, you could pixel out two different sprite sets (one for walking, and the other with a wider gait for running) and then substitute them. That way, the sprite will look normal while walking and then when the Sprinting/Running key is held down, they will actually look like they are moving with larger strides.

To do this, just fix the final common event by going 'Change Sprite Association' to the desired sprite before you Call Event. The Common Event: key.pace would then look like this:

Common Event: key.pace
Key Input Proc: 0001:key.run
Branch if Var 0001:key.run is 7
Change Sprite Association: Hero Name heroset-1
Call Event: hero.run

:Else Handler
Change Sprite Association: Hero Name heroset-2
Call Event: hero.walk

:End



THANK YOU FOR READING! I know it was rather long winded for a simple code but I hope this helped someone out there.

Posts

Pages: 1
The tutorial needs a few corrections. I feel like an idiot because when I listed the names of my events, I put them in which doesn't display in the actual article. So anyway, the event for running speed is hero.run and the name for the walking speed is hero.walk. The common event for the key is key.pace. Some of you probably would have figured it out without me pointing it out, but I thought I'd add the corrections here in case anyone was confused.
Corfaisus
"It's frustrating because - as much as Corf is otherwise an irredeemable person - his 2k/3 mapping is on point." ~ psy_wombats
7874
One thing I must ask, though pardon me for doing so this late after the article was made, but how would you go about turning off this system for cut-scenes that require the use of the hero moving at a pre-determined speed, as to not cut off another event's walk path?
comment=20305
One thing I must ask, though pardon me for doing so this late after the article was made, but how would you go about turning off this system for cut-scenes that require the use of the hero moving at a pre-determined speed, as to not cut off another event's walk path?


Whoa I got back to this comment late. I haven't been on as of recent so sorry about that. I don't know how I would do it personally, I'd have to look at the programming again but the logical way to go about it would be to program something to stop the button event from being called on for the duration of the cut-scene, set the pace yourself, then at the end of the of the cut-scene turn the events back on.

Again i would have to look at it to see what the actual programming needed would have to be, but I think it'd be quite easy to work around.
Try making it, as a whole, on a switch. I got the idea from the jump tut. I can make my jump active or inactive for cutscenes. Maybe this can work the same being set up really similarly.
I'm in the middle of implementing this myself, I think you can get around the cutscenes issue entirely with the use of the "trigger switch" function next to where you'd choose "parallel process" for the common event.

It'll still work as a PP but only when enabled by a second switch being on - which you'd obviously turn off at the beginning of any pre-scripted hero movement and off at the end.

EDIT: Actually there's still a lot of issues with triggering events whilst the PP is running, off to the forums.
It works, but none of the teleport events work.
Hi i apologize as i am new to this kind of thing i done the coding exactly like that however it I cannot see the difference in speed... what am i doing wrong?
I'm using steam's version of RPGM2K3 but nothing I do seems to work.
My code looks like this:
@> Conditional Branch: Variable 0003:key.run == 7
@> Call Event: hero.run
@>
: Else
@> Call Event: hero.walk
@>
: Branch End

Are there any differences between the two products or am I doing something wrong?
Pages: 1