Table of Contents:

4. Character attributes introduction & Item bonuses
a.) Introduction to basic character attributes like: strenght, dexterity and similar including editor and database setup
b.) Add items to contain various bonuses to increase character statistics


Article 4



4.a. Character attributes introduction


Make sure you have read my last articles so you understand the basics. Also this time I will include no code snippets and will do more work on the explanation. The code changes are minor it just takes a lot of object adding and adjusting to the current program which I will cover with screenshots only. My goal will be to make this more an article then a step by step instruction. The previous articles should have covered what you need for this one. When you download the work in progress version all groups that have been added or changed are marked in the event editor so you dan't have to search around. No comments so far, I plan to release a full commented version once all articles are out.

So what we created so far is the pure inventory and a virtual body we can equip various items. Next we want is a character behind the body.

First we need to define basic attribute values for our character. In our example we want to stay simple. So we define four main attributes:

Strenght (STR), Stamina (STA), Dexterity (DEX) and Intelligence (INT).

Before I go into detail about those main attributes let's create a few additional values first:

Hitpoints (HP), Manapoints (MP), Armor (AR), Damage (DMG), Character Level (Lvl), Class, Experience (XP) and Skill Points (SP).

I won't go that much into detail for all of these, I suggest you google some of AD&D Roleplay sheets and similar stuff. There are also good free roleplay papers and Amazon & Co. for sure have books regarding RPG character design.

We start with Class first. For the moment we do not cover more classes, but we will later in another article. Let's just assume it is value 1 which means Knight.

Our Knight now needs a Level and Experience. We start from scratch so our hero will start with level 1 and 0 experience. We also need an XP table for leveling up our character. This could looke like this:


[XPTable]
1=500
2=950
3=1710
4=3078
5=5540
6=554000


The formula for this is (XP * 2) - 10%

I suggest to also check out: http://en.wikipedia.org/wiki/Experience_point and also google on xp curves to adjust the formular for your needs. Every time our hero now gains experience points he will increase his knowledge and at a certain value he will level up.

Hitpoints and Manapoints should be clear also. However those are not hardcoded values these are Ratings. A Rating is based on a attibute value. As I said earlier we want to keep it simple that why we assume the following:

1 STA = 10 HP, so increasing our main stamina attribute grants our character additional hitpoints.
1 INT = 10 MP, thats obvious will grant the character 10 manapoints.
1 STR = 5 points of Damage
1 DEX = 10 Armor rating

For example:

Knight Lvl:1 XP:0
STR:5
STA:6
DEX:3
INT:2

will resolve into:
60 Hitpoints
20 Manapoints

25 Damage Rating
30 Armor Rating

That is very basic: our hero can do damage, can take damage, and got HP & MP points so he will evenetually run out of mana and also die when running out of hitpoints.

Also we want to reward our player and every time he level up he get some skill points to spend on his four main attributes. Again this does not require to be hardcoded, it could look like this:


[SkillPoints]
1=3
2=3
3=3
4=3
5=4
; on LVL up = SP reward


When we create our hero in the first place we can spend 5 points initially (this will be hardcoded in our example). Then when we reach level 2 we get another 3 points to spend and so on. On level 5 we already earn 4 additional points.

We will not force the player to decide on level up when to spent his skill points so we just add them to the current SP value.
This is actually a very smart idea and puts part of the gameplay balance into the players hands. At any time in the game when the player gets the feeling he is doing not enough damage or does receive to much damage he then can decide how to spend those additional attribute points.

We now covered the basics so let's start coding. As stated earlier, no step by step this time. I provide a build from time to time so you can download and check the code for yourself.

On our first frame we now build some sort of character editor, expanding the one we already have for the equipment. We save into the same Char.db array on the Z=1 table and our XP and SP curves go into our Itemnames.ini so we can reference them at runtime. Very simple and looks like this:

Image

As you notice we expanded the screensize to 800*600 so we have more space! On our second frame we mostly copy over from frame 1 and read the stats from the database. We do not want our player to modify any of the character information at runtime so we set everything to read only! We also added a routine to randomly grant XP on button click and level up including value distribution.

Image

Check it out below!

Download: http://www.mediafire.com/?2k4mmzo20tm


4.b. Item bonuses

Now that we have our character sheet ready we want to include item bonuses on items. For this we need to extend our item editor. I explain our easy solution first then explain how a professional solution could look like.

What we do is we add additional rows to our database and give them names like bSTR, bHP, bMP etc. b stands für bonus. Now we have the possibility to add bonuses to our items by just changing the value in those fields. Our Armor item could have 50 Armor Rating as a first bonus and maybe also a STR bonus of 2.

Would we equip this item to our character our base strenght would be raised by 2. The crucial part here is to not alter any of the base values. When we swap items we do simple math by just adding the base value with the item bonus value. In our example this would mean a base of 5 STR + 2 STR from our bonus resulting in 7 STR in total. The Armor increase would occur also.

For our Tooltip we would parse all those fields and if they contain a value higher then 0 we would add it as a string + value reference to let the player know the actual bonus.

That is the quick and easy solution we are doing later in this article.

A professional solution however will be like this:

We would have a row for the total amount of bonuses and additional rows named like this: bID1,bID2,bID3,... etc. We then add a new Z1 to our item database and create our own bonus database!

Bonus IDs are referenced to our items. The important part with that solution is that you can seperate the actual item from the bonus and bonuses could have unique names and contain also additional attributes in one bonus, like +1STR & +1STA could be adressed as Str$(item)+ of the monkey. But the most important part is balancing! Ever tried to balance 20000 items with our basic solution? It would take hours or days to scroll through all those items and adjust their values while in our professional solution you just change the bonus and it affects all items that contain this specific bonus.

This would of course require a solid item database in the back. For example:

Our Database could hold 10 of the same armor with the same name but different IDs. The first one in the database would have a required character level of 1 and a rating of 50 AR. You could equip it right from start. Our second item could have a level requirement of 5 and a rating of 75 Armor. And so on until lets say level 50. All of those 10 could now be combined with all sorts of bonuses.

Lets say we have two bonuses, VigorI and VigorII resulting in +10 and +20 HP.

Our level 1 armor could have a VigorI bonus while our level 2 armor has VigorII. This is not limited to armor only, it could also be assigned on a helmet or ring.

The point is getting item fleshed out is really fast. Just decide what item you want, what base level it should have and the bonus and you got your final item.

This is also how random items are generated. Put everything together from a sort of construction kit and save it as a new itemID into a new Z layer in the item database. In fact this item has not existed before! Having a wide set of items and bonuses resulting in thousands if not millions of possible item and bonus combinations.

Imagine Item sets like in Diablo, Titan Quest or Sacred? No problem here, add a new row SetID and reference it! Z4 could be our Set layer and could look like this:

ID, Name, BonusIf2, BonusIf3, BonusIf4, BonusIf5, BonusIfComplete
1, Yves Bugslayer, 34, 23, 56, 454, 555

Those numbers again would be IDs in our Bonus Database: 454 could be +2STR +5STA +100HP

The only limitation in this solution is your imagination!

I know this sounds complicated! It is, thrust me I did it in the past, but once you have it ready and setup in place it saves you a lot of time!

I might cover this in another article later, but for the moment we go with our basic solution. In fact the above solution would be for a real action RPG with tons of random items, we might look into a smaller scale solution and our basic one mentions first will fit here nicely.

So what we do for the coding is that we first need to gather our base attributes and combine them with the bonus attributes. For bonus attributes we would read through all the items our character has currently equipped and add them to our base attributes. This way we make sure we do not alter any of the character information at any time. What we present the player in the end is of course both base and bonus stats combined.

For this we add alterante values to our edit boxes that contain the four main attributes. We already have a group that reads our equipment from our char.db database. We modify it to also add all item bonuses to our alternate values we defined earlier. So when the group is activated and create the equipment on our screen it will also add all the bonus values to our edit boxes. In the end we have all bonus values combined in those alternate values.

We now just add the main attributes and the bonues attributes and then calculate the rating. E.g:

5 base STR + 2 bonus STR = 7 STR resulting in 7*5 = 35 DMG + our bonus damage

We do this for all attributes and ratings.

We do the same of our inventory. there is also a group and we just read the bonues into the new created ap_item alternate values.

However this is limited by the amount of alt values we have. I know there is an extension that add infinite values so we do not hit a limit at all but this would of course complicate our code.

We also need to adapt our Tooltip to show the item bonuses!

This it how it looks from the editor side:

Image

And also from the gameplay side:

Image

I added some items to the database and also included more item names and made a second set of bitmaps for those so you can see the difference. Check it out below:

Download Link: http://www.mediafire.com/?hixmyefynmm

(This includes all graphics, source and compiled exe as well this text and pictures, 1.1mb in total)


That's it! Stay tuned for the next part when we cover consumables like potions and dig more into character classes!

Comments are welcome as always, PM me if you have questions!


This will be the end of the fourth article. I hope you had the same fun recreating stuff like I did writing this for you! Again comments are welcome.

Krystian


Continue to Article 5 - http://www.create-games.com/article.asp?id=2009