Making an RPG with AGS

From Adventure Game Studio | Wiki
Jump to: navigation, search
This article uses deprecated code/functionalities.
Information in this article may be out of date or just plain wrong!

This article/section was written for an older version of AGS.
AGS 2.7 uses new, easier, Object-Oriented scripting and so this article needs updating to reflect the new style scripts.

It is possible to make RPG's with AGS; but you will need some coding experience.

I'll tell you how to develop RPG games with AGS Scripting in this tutorial. Yes, there are some free other game developing tools which you could make RPG's, but you can add adventure elements to your game easily if you use AGS.

Firstly, I should say that there are many ways to script RPG's with AGS. I will tell the way I use while I was developing Asporia: Hidden Threat in this tutorial (all the screenshots are from the source code of the game.)

The Variables Like Health, Mana and Exp.

We need these variables to develop our RPG game. Add this script to game_start section.

GiveScore(7); //Health. You can also use GlobalInt for this.
SetGlobalInt(2,8); //Mana
SetGlobalInt(3,0); //Exp-weapons.
SetGlobalInt(4,0); //Exp-mage.

This is what I used for Asporia. You can use only one variable for exp. if you want.

also if you want,

SetGlobalInt(5,5); //the enemy's HP is set to 5

So our health is 7 and mana is 8 units. We haven't got experience points yet. To decrease the mana points, use this script:

SetGlobalInt (2, GetGlobalInt(2)-1); //We lost 1 mana point.

The GUI Which Shows The Health, Mana and EXP. Status

Let's prepare our GUI where we can learn how many health, mana and exp. we have.

Tuto-gui1.PNG We need GUI Labels for this. Create some GUI labels, let some of them be the texts like "Mana, Exp"; and let the others be "..." blank, which will show the number of the variables.

The "HP: @SCORE@" script: This is our health as we designated the game score as hit points. Type HP: @SCORE@ code in the Text blank of the label which you want to use as the HP status.

After preparing the labels with texts and the other labels with blanks, write this code to repeatedly_execute section:

string mana;

string expweapon;

string expmagic;

string enemyhp; //this is the HP of your enemy. ignore it for now.

StrFormat (mana, "%d", GetGlobalInt (2));

StrFormat (expweapon, "%d", GetGlobalInt (3));

StrFormat (expmagic, "%d", GetGlobalInt (4));

StrFormat (dusmanhp, "%d", GetGlobalInt (5));

SetLabelText (0, 1, mana); //so the mana points will be shown in the GUI 0, Label 1)

SetLabelText (0, 2, exp);

SetLabelText (0, 9, expbuyu);

SetLabelText (4, 1, dusmanhp); //this code isn't too necessary for now. it is about another GUI, number 4.

So the variables in the game should have been displayed in the GUI.

Turn Based Fights: Weapons, Magics, Enemies, and Enemy A.I.

Another important thing for the RPG's: Weapons, magics, enemies and their artificial intelligence. Tuto-inv1.PNG

I guess there are many ways to create weapons in AGS. But I will tell the weapon system used in Asporia. All the weapons and magics are actually inventory items, and you use them onto enemy characters (or hotspots represents them like in my RPG).


Then use these inventory items for the enemies. (The enemies in Asporia was actually hotspots, but you can use Characters as enemies.) The first scripts you should use for the fireball magic :

PlaySound(1); //plays the sound

Display("You throwed a fireball to the undead.");

SetGlobalInt (5, GetGlobalInt(5)-3); //enemy HP is decreased 3 points

SetGlobalInt (2, GetGlobalInt(2)-1); //your MP (mana point) is decreased 1 point.

SetGlobalInt (4, GetGlobalInt(4)+3);//gained 3 exp. for using magic.

And the second step of the scripts (write them in the next "Run Script" hotspot command):

if (GetGlobalInt(5) <= 0) {



NewRoom(30); //if the undead's HP is equal, or lesser than 0; then he dies and we go to another room in Asporia:Hidden Threat. You can use your own fight ending scripts.


else {




Display("Undead hit you"); //if you couldn't kill the enemy, it will attack you and you will lose 3 HP. }

How to die in the game:

If an enemy can attack you, then you should be able to die in the game. Type this scripts in the repeatedly_execute section:

if (game.score < 1) {





The room 28 is the "Game Over" screen. You should also use the scripts in Players Enters Screen (before fadein)

PlaySound(4); // the sound which says the game is over



And these codes in Players Enters Screen (after fadein):



So the game will be restarted.

Level Up:

You can level up in the game after you have a definite exp. points. For example in the repeatedly_execute section:

if (GetGlobalInt(4)>=60) {

Display("You leveled up and gained the magics of Cure +2, Fireball +2 and 6 mana points .");



LoseInventory(4); //losing the old Cure +1 magic

SetGlobalInt(2,GetGlobalInt(2)+6); }

The player will gain some new magics. Sure, you can use your own scripts for level up.

Different Endings:

You may also want to add different endings which is according on the player's decision in the game. For this, add this code to game_start: SetGlobalInt(12,0);

This is the role-playing score in the game. If the player does something good, (for example, helping a villager) he gets a role-playing score:


Then in the end of the game,


if (GetGlobalInt(12)>=3) {




if (GetGlobalInt(12)<3) {




The room 62 leads you to the good ending in the game. And the room 57 is to another ending which isn't good...

And....cheats :)

If you think your game may be found too hard by some players, then you can add some cheats. To on_key_press;

if (keycode==13) SetGlobalInt(2,GetGlobalInt(2)+10);

If the player presses Ctrl + M, his/her mana increases for 10 points.

I hope this tutorial is useful for whom wants to make RPG's with AGS. You can ask me if there is something you couldn't understand here. (MSN Messenger)</pre>