I have seen many many question on RPG`s and I can
easily answer them, but it takes a while to do
everything. Some people on the community asks for a
whole battle engine witch I think is a bit harsh for the
coders. They will continue to bump until they get their
battle engine, but nobody posts it. This is the same for
every other question on RPG`s. Once I saw this
competition I thought "I always wanted to write a
tutorial to help people on their RPG`s, but I don`t really
help people that doesn't deserve it! So I thought I
could spend the day to write it because I have a reason
" I will write a bunch of information then the basics until and it will get more complex just skip it until you
found what you need...
What is a RPG?
RPG stands for Role-Playing Game.
A RPG is a game in which the participants assume the
roles of fictional characters and collaboratively create
or follow stories. There may be one story or there may
be a bunch of stories for a bunch of characters.
Anyway that pleases you. Remember you have full
control over your game. Use that control!
Participants determine the actions of their characters
based on their characterization, and the actions
succeed or fail according to a formal system of rules
and guidelines. Within the rules, players can improvise
freely; their choices shape the direction and outcome
of the games. In other word players improvise while
battling or moving around.
A role-playing game rarely has winners or losers. That
makes role-playing games fundamentally different from
board games, card games, sports and most other
types of games. Its more of walking around, socializing
and finishing the adventure set.
A RPG needs to have a story engaged of your
imagination. The better the story the anxious people
get to see the end and continue playing. That is your
goal to make people play and to continue playing it.
RPG`s always have ways to increase your characters
stats(Which you should have.) such as weapons, items
or other equipments.
Those are the basic aspects of a RPG. Scientists have
yet to find a limit to your memory and imagination, so I
suggest you use it to make the best RPG game ever!
What should a good RPG have?
A good RPG should have characters that you either
create or change the stats...or just change he stats if
you want to avoid lots of work.
A good RPG should also have a battle engine ATB or
RTB.
Always have a theme. Don`t just use the ordinary 21st
century(I see that as boring) also don`t mix your
themes don`t make a old theme of long ago, but add
guns like snipers... Rather make spears they throw.
Also instead of using teleporters or airplanes in an old
theme use something that looks old eg. Airship.
Nobody is stopping you from designing your own stuff
tho

Have decent motion and game play that challenges the
brain. Don`t just let them go forward that way they
won`t do any work. A game is all about making
decision. Make multiple paths that take you to multiple
places or take you to a dead end. My point is don`t
make it too simple. Have them think were to go.
Also a good aspects of RPG`s re variety. Why would
you wan`t to make 5 cities that has the exact same
design? Why would you want to give everyone the
same magical skills? Keep things like that in mind.
What will this tutorial include?
I would just make you look at the chapters, but I want to
make this look good. So I will list everything the tutorial
will include.
Note: I am making this up as I type, but I will test and
make an example, but I`m not sure whether they are in
the same order as the index.
The tutorial will include:
-Name system
-Grid movement system
-Items
-Stats
-Battle system
-How long you have played the game
-Magic
-Outside magic ("Field magic"

-Outside items ("Field items"

-Rooms
-Shops
-Money
-Various code from various other good RPG games.
And this tutorial might be updated, but that's all ATM.
Note: Some functions may require the registered
version of game maker and the example will be in gmk
(gm7) format.
OK lets start!
Beginning
I won`t use good sprites until I have written the tutorial
completely finished then I will provide my other sprites
and an example.
After opening GM and have your sprites (Witch I use
circles for) you ill need to follow this tutorial editing just
what you wan`t since I will comment most of the code
inside(The code) and outside(Right here).
Grid Movement System
You can do the grid movement system in many ways...
The first and neatest way to do this is with a script.
Assuming you have your sprite walking and standing
or running I will use this code. (Running not required)
----------------------------------------------------------------------
SNAPPING TO A GRID
----------------------------------------------------------------------
Believe it or not there is actually a function that's line
that snaps your player to a grid
Firstly we would want variables to control these pieces
faster. For this I will use a variable called.
key_grid
Now we need to give it a value. So I am going to do this
in the BEGIN STEP event since we want it to happen at
the start of each step.
Since we are doing this with scripts I will call my script
player_beginstep
Then this is its value.
key_grid = (place_snapped(16,16))
Explanation:
key_grid is the variable and place_snapped is to snap
it to a grid. Both of the 16 is how it will be snapped the
h and v. The default is 16X16 and they are most of the
times the same or it won`t be a grid.
Now anywhere in the player we can call that command by
typing key_grid we will use this.
Now we want to make the player move along the grid so
I will create a script for the players step event. I will call
it
player_step
Now every time the player moves we first want to check
whether he is snapped to the grid. So at the top of the
script I am writing this.
{
if key_grid then
{
Explanation:
The if will check whether it is a certain value.
key_grid is the variable witch can be found above.
The then will tell gm to perform the next action if the if
meets the requirements.
Than action alone will do absolutely nothing it will just
throw an error.
----------------------------------------------------------------------
MOVING ON THE GRID
WALKING
----------------------------------------------------------------------
Now its time to make the player move by the grid.
I will use his (Which is the easiest for me)
Firstly we will need more variables to call the motion
faster.
Go back to your BEGIN STEP event and add this below
the code you already typed there.
key_left = (keyboard_check(vk_left))
key_right = (keyboard_check(vk_right))
key_up = (keyboard_check(vk_up))
key_down = (keyboard_check(vk_down))
Explanation:
All of the key_WHATEVER is the key that will be pressed.
keyboard_check is a function witch checks that a key
is pressed (Key goes between ())
vk_left, vk_right, vk_up and vk_down are the key that
will be pressed left, right, up and down.
This goes just below the code in the STEP EVENT.
Below your script in STEP EVENT just copy/paste this
and change words in capital letters to your sprite name.
if key_left then {sprite_index=LEFT SPRITE
WALKING image_speed=0.25 speed=2 direction=180}
if key_right then {sprite_index=RIGHT SPRITE
WALKING image_speed=0.25 speed=2 direction=0}
if key_up then {sprite_index=UP SPRITE WALKING
image_speed=0.25 speed=2 direction=90}
if key_down then {sprite_index=DOWN SPRITE
WALKING image_speed=0.25 speed=2 direction=270}
}
[gml]
Explanation:
It would be unnecessary to explain all 4 pieces since
they are basically the same.
The if checks whether that action is true.
The key_up, key_down, key_left and key_right are
variables displayed above.
Then checks if that action is true what will happen after
its true?
sprite_index is to change the sprite of the object into a
different sprite. In our case the direction.
Image_speed will simply slow down the animation of
the sprite. This is normally used with animations of 4
frames or so.
speed would be the speed he will move.
The direction is the direction he will move
180 = Left
0 = Right
90 = Up
270 = Down
Now create an object with the player_step in the step
event and the player_beginstep in the begin step.
Run the game.
As you can see the player is snapped to a grid, but the
motion isn`t quite right.
Lets fix that.
In your begin step we wan`t this
[gml]key_anykey = (key_left || key_right || key_up ||
key_down);
Explanation:
key_anykey is our variable on how we will call it.
You might wonder what this is.
(key_left || key_right || key_up || key_down)
well the keys are the variables, witch should be in your
script at the top somewhere.
The || means or.
So it will check whether anyone of those keys are
pressed.
Now we add another piece of code just below that
piece.
key_nokey = ((!keyboard_check(vk_down) and !
keyboard_check(vk_up) and !keyboard_check(vk_left)
and !keyboard_check(vk_right)))
key_nokey is the variable we will use to call it. Then as
I explained above somewhere what the keyboard_check
and the vk`s do. Now there's something else there is a
! in front of it. That means not. So that will be activated
if those keys are not pressed.
Now it will be useless to run he game since we havn`t
done anything, but introduce the variables with some
code.
Now its time to use one of those variables.
I am putting his in the step script.
This is the same as the step part above replace in
capital letters.
if key_nokey and key_grid then {{
if sprite_index=WLKING SPRITE RIGHT then
sprite_index=STANDING SPRITE RIGHT
else if sprite_index=WLKING SPRITE LEFT then
sprite_index=STANDING SPRITE LEFT
else if sprite_index=WLKING SPRITE UP then
sprite_index=STANDING SPRITE UP
else if sprite_index=WLKING SPRITE DOWN then
sprite_index=STANDING SPRITE DOWN}
speed=0 move_snap(16,16) image_speed=0
image_index=0} else {speed=speed direction=direction
image_speed=image_speed}
}
Explanation:
This is similar to the step code above, but I will still
explain.
if key_nokey and key_grid then {{ are our
variables witch you should know by now what it does.
sprite_index=a standing sprite This is really quite
simple it is if the above is true the sprite index would be
a standing sprite.
Same with the other 3 functions.
Then we have
Now some new code.
if sprite_index and then there was a walking sprite and
"then" it means that it will check whether the sprite is
the sprites index (witch is walking) then do the next
part
speed=0 move_snap(16,16) image_speed=0
image_index=0} else {speed=speed direction=direction
image_speed=image_speed}
}
speed will be the speed it goes at when the function is
true. move snap is to activate the grid again (if true)
image_speed is the speed the animation will go. In this
case it won`t move.
Image_index we add 0 to make it false. So it won`t
have a set image except for the one you gave it.
The rest of the code is to keep the the same if the
correct button is pressed. Therefore keeping the
default I made and not making anything go out of
control
Run the game...
Look at that magic
Its a perfect grid that can be used in any RPG game.
----------------------------------------------------------------------
WALKING SCRIPTS
----------------------------------------------------------------------
If you worked with me your code should look like this.
You have 2 scripts
1. player_step
2. player_endstep
In the player step script I have this.
{
if key_grid then
{
if key_left then {sprite_index=sprite image_speed=0.25
speed=2 direction=180}
if key_right then {sprite_index=sprite
image_speed=0.25 speed=2 direction=0}
if key_up then {sprite_index=sprite image_speed=0.25
speed=2 direction=90}
if key_down then {sprite_index=sprite
image_speed=0.25 speed=2 direction=270}
}
if key_nokey and key_grid then {{
if sprite_index=sprite then sprite_index=sprite
else if sprite_index=sprite then sprite_index=sprite
else if sprite_index=sprite then sprite_index=sprite
else if sprite_index=sprite then sprite_index=sprite}
speed=0 move_snap(16,16) image_speed=0
image_index=0} else {speed=speed direction=direction
image_speed=image_speed}
}
Replacing the "sprite" with he correct sprite needed.
In the player_beginstep script I have this
key_grid = (place_snapped(16,16))
key_left = (keyboard_check(vk_left))
key_right = (keyboard_check(vk_right))
key_up = (keyboard_check(vk_up))
key_down = (keyboard_check(vk_down))
key_anykey= (key_left || key_right || key_up ||
key_down);
key_nokey = ((!keyboard_check(vk_down) and !
keyboard_check(vk_up) and !keyboard_check(vk_left)
and !keyboard_check(vk_right)))
----------------------------------------------------------------------
RUNNING
----------------------------------------------------------------------
Adding running.
Yes you can add running to give your game more
flexibility.
For those of you who don`t know how this is how you
do it.
In the begin step script you add this under key_anykey
key_run = (keyboard_check(ord("X"
))You should know what everything does, but there is
something new. ord. You cannot use vk_ for the letters
on your keyboard so to use keyboard buttons with ord
you do this.
ord(""
that's it.----------------------------------------------------------------------
MOVING ON GRID
----------------------------------------------------------------------
In the step event script you put this (Replace in capital
letters)
if key_run and key_left then {sprite_index=RUN
SPRITE LEFT image_speed=0.5 speed=4 direction=180}
if key_run and key_right then {sprite_index=RUN
SPRITE RIGHT image_speed=0.5 speed=4 direction=0}
if key_run and key_up then {sprite_index=RUN SPRITE
UP image_speed=0.5 speed=4 direction=90}
if key_run and key_down then {sprite_index=RUN
SPRITE DOWN image_speed=0.5 speed=4
direction=270}
That is the same as the walking script it just checks if
its walking and if the run button is checked.
Lastly add this somewhere in the step event.
if key_nokey and key_grid then {{
if sprite_index=RUN SPRITE LEFT then
sprite_index=STANDING SPRITE LEFT
else if sprite_index=RUN SPRITE RIGHT then
sprite_index=STANDING SPRITE RIGHT
else if sprite_index=RUN SPRITE UP then
sprite_index=STANDING SPRITE UP
else if sprite_index=RUN SPRITE DOWN then
sprite_index=STANDING SPRITE DOWN}
speed=0 move_snap(16,16) image_speed=0
image_index=0} else {speed=speed direction=direction
image_speed=image_speed}
}
----------------------------------------------------------------------
MOVING SCRIPS
----------------------------------------------------------------------
It also has 2 scripts
These scripts are a bit longer.
player_beginstep
key_grid = (place_snapped(16,16))
key_left = (keyboard_check(vk_left))
key_right = (keyboard_check(vk_right))
key_up = (keyboard_check(vk_up))
key_down = (keyboard_check(vk_down))
key_anykey= (key_left || key_right || key_up ||
key_down);
key_run = (keyboard_check(ord("X" )))
key_nokey = ((!keyboard_check(vk_down) and !
keyboard_check(vk_up) and !keyboard_check(vk_left)
and !keyboard_check(vk_right)))
player_step
{
if key_grid then
{
if key_left then {sprite_index=sprite image_speed=0.25
speed=2 direction=180}
if key_right then {sprite_index=sprite
image_speed=0.25 speed=2 direction=0}
if key_up then {sprite_index=sprite image_speed=0.25
speed=2 direction=90}
if key_down then {sprite_index=sprite
image_speed=0.25 speed=2 direction=270}
if key_run and key_left then {sprite_index=sprite
image_speed=0.5 speed=4 direction=180}
if key_run and key_right then {sprite_index=sprite
image_speed=0.5 speed=4 direction=0}
if key_run and key_up then {sprite_index=sprite
image_speed=0.5 speed=4 direction=90}
if key_run and key_down then {sprite_index=sprite
image_speed=0.5 speed=4 direction=270}
}
if key_nokey and key_grid then {{
if sprite_index=sprite then sprite_index=sprite
else if sprite_index=sprite then sprite_index=sprite
else if sprite_index=sprite then sprite_index=sprite
else if sprite_index=sprite then sprite_index=sprite}
speed=0 move_snap(16,16) image_speed=0
image_index=0} else {speed=speed direction=direction
image_speed=image_speed}
//////////////This is only if run and walk are 2 different sprites
if key_nokey and key_grid then {{
if sprite_index=sprite then sprite_index=sprite
else if sprite_index=sprite then sprite_index=sprite
else if sprite_index=sprite then sprite_index=sprite
else if sprite_index=sprite then sprite_index=sprite}
speed=0 move_snap(16,16) image_speed=0
image_index=0} else {speed=speed direction=direction
image_speed=image_speed}
}
There's your grid movement!
Example at the bottom of the page.
Next I will do the money, rooms and shops.
All 3 of these are also fairly easy to do. The easiest way is probably variables.
----------------------------------------------------------------------
ADDING THE COINS
----------------------------------------------------------------------
Well they need something to buy with right?
Now to make it easy all we have to do is set a variable. I think we should make it global.coins=0 so we can use it anywhere and we what the player to start with 0 coins.
This can either be with the player or in a controller. I recommend a controller, but its up to you.
So in the create event of the controller we add
global.coins=0
Now get something to increase the coins.
I will use a coin sprite, but you could just use a trigger if you wan`t.
Now its your money`s. You can do this with the player to, but then the player will have allot of actions in the end and it will look really unneat.
In the money`s collision event with the player destroy the money.
Do it by doing this.
instance_destroy();
We also want the money to increase so we will have to increase the money.
We do this by typing.
global.money+=5
If you type + before the = you will add the value to the global variable.
You can insert the money in the room, but you won`t see it since you don`t know what the value is.
Now in the controler`s draw event we want to draw the value.
Lets draw it at the op left side of the screen.
We type
draw_text(0,0,"Coins: "+string(global.coins)+""

Explanation:
draw_text draws the text then its the X and Y c-ordinates you have to set.
The string it has to draw comes next.
Now people will ask what the hell is happening you type
"+string(global.coins)+" and it displays the value.
The reason is that you convert the value to a string then draw the variable global.coins so it shows your value.
If done correctly and you add money in the level and pickup the money you will see that the money increases.
There your money is done.
----------------------------------------------------------------------
SHOP
----------------------------------------------------------------------
Whats the point in having money if you can`t spend it?
Shops are helpful and not that complicated. There are many ways to do this and most of the ways suck

I will try to make a better shop system.
Those long ones like final fantasy take much more than just 20 lines of code I will have to make a whole other tutorial just to do that!
This will work as follow.
Allot of people don`t know how gm`s draw system works so for this will make 2 sprites. For those who can`t draws convenience.
Create your sprite and put it in a box over it. (The sprite must be in front of the box) then copy the sprite to make it an animation and make the border(Or anything for that matter) a different color.
See my example below.
Now after you got the sprites
Create an object with the items name.
Then in the create event of the item type
image_speed=0
Then in the mouse enter event we want the sprite to go to the next sub-image. So we type this in the mouse enter event.
image_index=1
and then in the mouse leave event type tis
image_index=0
You might want to make the depth something like 20.
Then in the left mouse button released event we add this
switch (show_question(" Do you want to buy a potion for 10 coins" ))
{
case 1: show_message("Thank you.#You bought a potion for 10 coins" ) break
case 0: show_message("Well if you are sure." )break
}
Explanation:
switch means it will be something eg. yes
show_question shows a yes/no question.
Then we add case 1: the our statement. Yes would be 1 and 0 will be no.
OK there you got your potion you can buy.
We will extend it later.
Now put the potion in the room and make a shop controller.
Then in the create event will do this, but its not necessary.
show_message("Hello and welcome to the shop" )
Then you should have added the object in that room.
Comments
Loading comments...