RPG101: Characters, Weapons and Combat Rounds

by tsmpaul

<< All Articles | Print

Overview

In this article, you will learn how to define different types of weapons, using items and variables, including handling ammunition. You will learn to define basic player and enemy characters using variables. You will then learn how to create a turn based ‘combat round’ battle system, where the player can use weapons against the enemy, then defend against the enemy’s attacks, until one of them loses their hit points and dies. Lastly, some suggestions on how to further expand this system and customize it for your own game will be given. You can follow this article as a step-by-step tutorial, and then use the skills you learn to create your own system, if you want.

Prerequisites

Okay, it would be helpful for you if you read the following articles first, to gain an understanding of the elements in this article. However, all lines of script in this article will be explained to make things simple and refresh memories. You also need to create an Advanced Game, go to the Story Properties page, click on Editor Features, and set everything in the drop-down boxes to their highest settings.

Recommended reading: 

> Going Advanced

> Working with Variables

> The Basics of Scripting

> Intermediate Scripting

> Scripting Items

> Advanced Scripting

PART ONE: Defining Characters

Attributes and Skills

An 'Attribute' is something that sums up a quality of a character, such as how healthy they are, how tough they are, or how smart they are. A 'Skill' is a measure of something the character is able to do, such as firing a gun, swinging a sword, or picking a lock.

The combat system presented in this article will only be using basic attributes, to keep track of health. In the end of the article, suggestions for adding more attributes and skills to your RPG story will be given. Perhaps a later article will deal with aspects like accuracy, dodging, and so forth. For now, we’ll stick with the basics to keep it simple.

Defining the Player

Okay, for basic combat, all you need to know is how many hit points your hero has. If the hero reaches zero hit points, they will die, and the game will be over. Three variables are required, the first is how many hit points the player currently has, and the second is the total amount of hit points they have when they are at full health. The third variable is used during combat, to help the story engine remember how much damage the player has dealt out in battle.

> Create a Variable called PLYRHP

> Create a Variable called PLYRMAXHP

> Create a Variable called PLYRDAM

I have set the first two variables to ‘24’ for the purposes of this article, but leave PLYRDAM blank for now.

Defining Enemies

Okay, in this article's battle system, only one enemy is dealt with at a time, so these enemies can share the same variables, since only one of them needs to be defined at a time. Like the player, they will have hit points, and maximum hit points. You also need to create a variable that tells us how much damage the enemy can do to the player.

> Create a Variable called MONSTHP

> Create a Variable called MONSTMAXHP

> Create a Variable called

Don’t set these Variables to anything yet, instead, they will be set when a "monster" is encountered in the game.

Part Two: Defining Weapons

Okay, now we need some weapons. In this tutorial we will make three weapons: a sword, a bow, and an automatic rifle. This is to give an example of a standard melee weapon, a one-shot weapon that requires ammunition (in this case arrows), and a clip-based weapon that requires ammunition – but must be reloaded after using it a number of times.

 

Go to the Items section and create three items.

 

 

> Create an Item #1 called ‘Sword’

> Create an Item #2 called ‘Bow’

> Create an Item #3 called ‘Automatic Rifle’

 

 

Next, the Bow and Automatic Rifle use ammunition. Lets create a Quiver for the hero’s arrows, and an Ammo Belt to hold clips of ammunition for the rifle.

 

 

> Create an Item #4 called ‘Quiver’

> Create an Item #5 called ‘Ammo Belt’

 

 

Write down somewhere what ID number these weapons and equipment have. It will be displayed to the left of the item’s name, in brackets. For ease of reading this article, I have listed the ID numbers that each item I've listed will use in the scripts in this article.

 

 

Each weapon needs a number of variables. Firstly, each weapon deals damage when it hits the enemy – this is the number of hit points the monster will lose when it is hit.

 

 

> Create a Variable called SWORDDAM

> Create a Variable called BOWDAM

> Create a Variable called ARDAM

 

 

I have set each of these to ‘2’ as a standard amount of damage dealt in this article. Usually you would decide how much damage different weapons would inflict, and assign them to a variable for the weapons in your game.

 

 

The Quiver and Ammo Belt hold ammunition. We need to know how much ammunition they are currently holding, and what the maximum ammo is they can hold.

 

 

> Create Variables called ARROWS and MAXARROWS

> Create Variables called BULLETS and MAXBULLETS

 

 

I set ARROWS and MAXARROWS to '20', to show that you currently have 20 arrows, and can hold no more than 20 arrows – a full quiver. I set BULLETS and MAXBULLETS to 24, showing you can carry 24 bullets in your ammo belt, and your belt is currently full.

 

 

Finally, you need to place bullets in your automatic rifle. When the automatic rifle runs out of bullets, it will fill up with bullets from the ammo belt, when the player ‘reloads’ the gun. We need to know the maximum amount of bullets the rifle can hold, and start it off full.

  

 

 

 

> Create Variables called ARBULLETS and ARFULL

> Set both ARBULLETS and ARFULL to ‘6’.

 

When creating your own game and weapons, you can decide what amount of damage they do, how many arrows the player might carry in their quiver, how many bullets an ammo belt can hold, and how many bullets ranged weapons can hold when they are loaded.

 

 

 

 

 

 

 

 

 

 

 

Part Three: Status Display

Now we need a way to let the player know how much ammunition and health they have. At the bottom of each page, you can have a status display that lets the player know this information. To make things easy, we will use a 'Global Page Script' to automatically add player status information to every page in the game.

 

Go to the Scripts tab in the Advanced Editor. Edit the Global Page script.

The first line of your script will add some space between the page text and the status display area, using HTML Line Breaks ‘<br>’, which is basically, as if you had pressed the enter key in a word processor.

 

 

 

 

 

 

 

 

$PAGETEXT := $PAGETEXT + "<br><br>"

 

 

 

 

 

 

 

  

 

 

 

 

Next, we will tell the player how many hitpoints they have left. We will display both their current hit points, and their maximum hit points, so they have an idea of how badly injured they are during combat.

 

 

$PAGETEXT := $PAGETEXT + "<b>Hit Points:</b> "+%PLYRHP+" / "+%PLYRMAXHP

 

 

 

 

 

 

Next, if the player has the Quiver or the Ammo Belt, we will say how many arrows and bullets they are carrying. We need to check Itemstate for both items to see if they are held. If the player is holding the item, it will equal 1. If the player doesn’t have the item, it will equal 0. This is where we use the Item Number shown beside each item in the Items tab of the Advanced Editor. We will then display the ammo and max ammo variables we defined for both items. We will use the HTML codes '<b>' and '</b>' to mark a region of text in bold. We will also show how many bullets are loaded in the automatic rifle.

 

 

 

 

 

IF $ITEMSTATE4 = 1 THEN
BEGIN
$PAGETEXT := $PAGETEXT + "<br><b>Arrows in Quiver:</b> "+%ARROWS+" / "+%MAXARROWS
END

 

 

 

 

IF $ITEMSTATE5 = 1 THEN
BEGIN
$PAGETEXT := $PAGETEXT + "<br><b>Bullets in Ammo Belt:</b> "+%BULLETS+" / "+%MAXBULLETS
END

 

IF $ITEMSTATE3 = 1 THEN

BEGIN

$PAGETEXT := $PAGETEXT + "<br><b>Automatic Rifle ammo: "+%ARBULLETS+" / "+%ARFULL

END

 

 

 

 

 

 

 

Now, if the player has both items, and they are full, you will see something like this at the bottom of each page in the game:

 

Hit Points: 24 / 24
Arrows in Quiver: 20 / 20
Bullets in Ammo Belt: 24 / 24
Automatic Rifle ammo: 6 / 6

 

 

 

Part Four: A Basic Test Area

For the purposes of this tutorial, we will create a few areas. To begin with, edit the first page and call it “Starting Room”, then create two more pages as well, "Equipment Room" and "Battle Room".

 

 

Starting Room

 

 

 

 

 

 

You are standing in an empty room. There is a door to the west with a sign on it reading ‘Equipment Room’, and a door to the south with a sign on it reading ‘Battle Room.’

 

> Create a Link: “I head west to the Equipment Room” that goes to the Equipment Room page.

> Create a Link: “I head south to the Battle Room” that goes to the Battle Room page.

 

 

 

 

 

 

Equipment Room

You are standing in a small room with shelves, where weapons and equipment are stored. There is a door to the east with a sign on it reading ‘Starting Room.’

 

> Create a Link: “I head east to the Starting Room” that goes to the Starting Room page.

 

Battle Room

You are standing in the battle room, facing a monster! (Every time you enter this room, a fresh monster will attack you. Upon defeating the monster, you will be returned to the Starting Room.)

Monster Hit Points: %%MONSTHP%% / %%MONSTMAXHP%%

 

 

 

 

 

 

 

 

 Go to the Items tab in the Advanced Editor, and set each item to appear in the Equipment Room page.

 

Part Five: Meeting a Monster

Monsters could be encountered in different ways. For the purposes of this tutorial, a monster is loaded every time the player moves from the Starting Room and into the Battle Room. Basically, you need a link where the monsters stats are defined, before  the battle pages are shown and the fighting begins. In this case, the link where the player walks south to the Battle Room will define the monster using the monster variables.

 

  

Open the page “Starting Room” for editing. Beside the link “I head south to the Battle Room” there is an icon that looks like this, :=

Click on that icon to open script editing for the link, then enter the following script:

 

%MONSTHP := 8
%MONSTMAXHP := 8
%MONSTDAM := 2

 

This means that the monster has 8 hit points, and will deal 2 damage to the player when the monster has its turn to attack. In your own stories, you will have to decide for yourself how the player encounters the monsters they will fight. For the battle system in this article, you would make sure that the link where the player goes to fight the monster will have a script that defines the monster’s variables for that battle.

 

 

 

PART SIX: The Battle

Open up the page “Battle Room”. Someone playing the game would now see that a monster is in the battle room, with 8 / 8 hit points. If they went to the equipment room and picked up any of the items, they will be able to use them against the monster once you have completed this part of the article. To do that, we need to create a number of links. On this page, the links are actions that the player can make against the monster. You might come up with all sorts of things the payer can do during their turn in the battle.

 

The first link we create will involve generating the page where the monster has their turn, and then we will continue making all of the links for the player’s actions.

 

> Create a Link to a New Page.

> Call the page “The Monster’s Turn”

> Edit the new page

 

 

The Monster’s Turn

You attacked the monster, and dealt out %%PLYRDAM%% damage! The monster now has %%MONSTHP%% / %%MONSTMAXHP%% hit points left.

 

This new page will be explained later, but you can probably work out what the variables are doing as you read the page text. For now, close the new page, and return to the Battle Room, and we will allow the player to make actions against the monster.

 

 

(1) Fighting with the Sword

> Change the text of the first link we created to read: “I swing my sword!”

> Using the Stop Sign symbol next to the link, set it so that the link only shows when the player HAS the item SWORD.

> Clicking on the := symbol next to the link, we will add the attack script for the Sword item.

 

 

%MONSTHP := %MONSTHP - %SWORDDAM
%PLYRDAM := %SWORDDAM

 

This script subtracts the damage that the sword inflicts from the monster's hit points. It then sets PLYRDAM equal to SWORDDAM, so that on the next page, 'The Monster's Turn', it shows how much damage you inflicted on the monster. This is important, because you would probably give different weapons different amounts of damage, and players like to know how much damage they are dealing out. 

 

 

(2) Fighting with the Bow

> Create a new link, going to the page “The Monster’s Turn”, and call the link “I shoot my bow!”

> Using the Stop Sign symbol next to the link, set it so that the link only shows when the player HAS the item BOW, and the variable ARROWS is > 0. In other words, the player must have some arrows to be able to fire their bow.

> Clicking on the := symbol next to the link, we will add the attack script for the Bow item. This time, we not only deal damage to the monster, but we also lose one of our arrows.

 

 

%MONSTHP := %MONSTHP - %BOWDAM
%ARROWS := %ARROWS – 1
%PLYRDAM := %BOWDAM

 

 

(3) Fighting with the Automatic Rifle

> Create a new link, going to the page “The Monster’s Turn”, and call the link “I shoot the automatic rifle!”

> Using the Stop Sign symbol next to the link, set it so that the link only shows when the player HAS the item AUTOMATIC RIFLE, and the variable, ARBULLETS > 0. In other words, there are bullets loaded in the rifle, so it can fire.

> Clicking on the := symbol next to the link, we will add the attack script for the Automatic Rifle. Like the bow, we must lose a bullet when this weapon fires.

 

 

%MONSTHP := %MONSTHP - %ARDAM
%ARBULLETS := %ARBULLETS – 1
%PLYRDAM := %ARDAM

 

 

(4) Reloading the Automatic Rifle

Unlike the bow, the rifle can only fire a number of times before it needs to be reloaded. When the ARBULLETS variable reaches zero, there are no bullets loaded in the gun. To fill it up again, we’ll use a "Reload" link, which takes bullets out of the ammo belt, and puts them into the gun. However, this will count as the player’s turn, so they don’t get to make an attack this turn.

 

> Create a new link, going to the page “The Monster’s Turn”, and call the link “I reload the automatic rifle.”

> Using the Stop Sign symbol next to the link, set it so that the link only shows when the player HAS the item AUTOMATIC RIFLE, and the variable ARBULLETS = 0. It will only show the link when the gun is empty.

 

> Clicking on the := symbol next to the link, we will add the Reload script for the automatic rifle.

 

IF %BULLETS >0 THEN
BEGIN
%BULLETS := %BULLETS – 6
%ARBULLETS := %ARBULLETS + 6
END

 

It first checks to make sure there are bullets in the ammo belt, before removing six of them and putting them in the gun. It is important to make the number of bullets in the belt a multiple of six, so that the gun is filled each time bullets are taken, and odd numbers of bullets are not left over.

 

 

(5) Running Away

Finally, if the player didn’t pick up any weapons or ammunition, then they aren’t able to make any attacks against the monster! Also, if they are getting beat up, and think they might lose, they might want a hasty retreat. Give them a chance to run away, back to the Starting Room.

   

> Create a new link going to the page “Starting Room” and call it “I run away!”

  

 

Part Seven: The Battle, Monster’s Turn

Okay, the player can click on their choice of attack, reload or retreat. If they chose to attack or reload, they are taken to the Monster’s Turn page, where they see what damage they inflicted, and find out if the monster does anything back at them. Close and Save the page you were working on, and open the page “The Monster’s Turn” for editing.

 

As you can see from the text we typed into the page earlier, we will be told how much damage the player inflicted upon the monster, and are then told how many hit points the monster has remaining.

 

(1) Winning Link

The first link will deal with the defeat of the monster, taking you to an end of battle page. In your story, this could be a page where treasure is handed out, experience points are granted, or anything like that. The page would then let you continue the story. In this article, the end of battle page will just return you to the Starting Room.

 

> Add Link to New Page: “The Monster Is Defeated!”

> Edit the new page, and enter some text.

 

 

The Monster Is Defeated!

You have slain the monster! Congratulations!

  

> Add a Link on the new page: “Return to the Starting Room” and link it to the Starting Room page.

 

  

Save and close “The Monster Is Defeated” and go back to the page “The Monster’s Turn”. We will make sure that the link we created only shows if the monster is dead.

 

> Click on the symbol that looks like a Stop Sign, and set it so that the link only shows if the variable MONSTHP < 1, in other words, the monster’s hit points are zero or less, thus the monster is dead.

 

(2) The Monster Attacks!

The next link will show if the monster is still alive. This time, it is the monster’s turn to attack.

 

> Create a Link to a New Page, calling it “The Monster Attacks!”

> Edit the new page

 

 

 

 

 

 

The Monster Attacks!

The monster lashes out at you, doing %%MONSTDAM%% damage!

 

 

This will tell the player how much damage the monster has done to them. Save and close this new page, and return to the page “The Monster’s Turn”. We need to make sure that the monster's attacking link only shows if the monster is still alive.

 

> Click the stop sign symbol beside the link, and set it so that the link only shows if the variable MONSTHP > 0, thus it is still alive because it's hit points are above zero.

 

We will now place a script on the monster’s attack link, so that it deals out damage to the player.

 

 

> Click on the := symbol next to the attacking link, and enter this script:

 

%PLYRHP := %PLYRHP - %MONSTDAM

 

  

Now when the link is clicked, the player will lose hit points equal to the monster’s damage value. When you create monsters in your own story, you will have to decide how much damage your monsters inflict, and be sure to set that value when you Define the monster before the battle begins.

 

Now the monster’s turn is over, but there are some finishing things to do before the combat round is over.

 

(3) Death?

Bring up the page “The Monster Attacks!” again. The first link is the dreaded Death link.

 

> Create a Link to a New Page, calling it “GAME OVER”

> Edit the new page.

 

 

GAME OVER

You have been defeated! Better luck next time!

 

 

Close and save this page, and go back to “The Monster Attacks!”. We need to set a script so that this link only appears if the player died because of the monster’s attack.

 

> Click on the Stop Sign symbol next to the game over link, and set it so that it only appears if the variable PLYRHP < 1, thus, the player has zero or less hit points, and is dead.

 

 

 

(4) A New Round

Finally, if the player is still alive after suffering the monster’s attack, then a new round of combat begins, and the battle rages onward. Stay on the “The Monster Attacks!” page.

 

> Create a new link, to the “Battle Room” page, and call it, “The Player’s Next Turn”

 

This link loops back to the player’s turn, and the battle continues. However, we only want the battle to continue if the player is still alive!

 

> Click on the Stop Sign symbol beside the link, and set it so that the link only show if the variable PLYRHP > 0, thus the player still has some hit points left.

 

Part Eight: Well, that’s it!

You now have seen the basics of defining characters and monsters, making weapons using items and variables, and handling types of ammunition. You have made a turn based combat system, where player and monster take turns hitting each other. You have made it so that it checks to see if player or monster have died, and ends the game, or finishes the battle accordingly.

 

Some suggestions for further expanding this combat system:

 

Try making a PLYRACC and MONSTACC. These two variables are the Accuracy Skill, and involve dice being rolled when any attack is made. If the dice roll is equal to or less than the attacker’s accuracy skill, then they deal damage. Otherwise, they miss!

 

You could further expand it with Dodge skills. When the Accuracy roll is made, the opponent’s Dodge score is added to the dice, making it harder for the attacker to roll equal to or less than the Accuracy score.

 

Magic spells? Think of bows with arrows. Just make a Mana Reserve attribute, and when a spell is cast, instead of using ammunition, it uses points from your Mana Reserve. Add Mana to the status region at the bottom of each page, so the player can keep track of how many points they can use on casting their spells. Perhaps different spells use different amounts of Mana when cast?

 

Instead of having weapons do fixed amounts of damage to the enemy, (like 2 damage in this article) you could have them deal dice rolls of damage. For example, a Sword might deal 1 six-sided die worth of damage.

 

Armour – perhaps if the player has a piece of armour, then damage is lessened. Leather armour might take 1 point off the damage that is dealt to you.

 

I’m sure you can think of many other things to do, as you create your own custom, turn-based combat system, and write the story that goes around it. Have fun, and I hope this article helped you out, even if just to inspire you as to things scripting can accomplish!