For a change, this tutorial is not a direct response to a query or request. This one is purely my own, but something I got quite excited about when I thought it up. I often have visions of neat systems that are completely useless to my games, as this one is, but it may be very handy for you. This is a dynamic Hero title system.
What do I mean by that? Well, I'm sure you're aware of the Hero Title field in the database, next to Hero Name. The title is displayed in the menu and is purely aesthetic, but describes the character's job. There are a range of uses people have found for this, but in this tutorial we'll be using it as it was intended, to describe the hero's job, based on their stats.
This tutorial is aimed at projects where the player has control over their stat points, particularly when they can choose to specialise upon levelling up, so it won't be too useful to most people. Yet it is a delightful addition, in my opinion, and is feedback for where the stat points are spent. If a hero has specialized in attack, his Hero Title will become Warrior, if it is Intelligence his title is Mage. But these are just the first steps - later in the tutorial we will take secondary stats into consideration; a defense specialist with high intelligence becomes a Paladin, for instance. Sound fun?
We're going to start as simply as possible, although we will have to write the code in such a way that we can add in the new features without much hassle. We will need 4 common events as to avoid repetition and to streamline the process. I have called mine "Custom Title", "Title Type", "Sort Stats" and "Stat Check". Custom Title is the main routine, activated by parallel trigger. This will do the renaming of the heroes. We're going to structure this so it is a trivial matter to apply the name changes to other heroes, but as usually, this tutorial only goes into depth for the one. Custom Title calls Title Type, a call trigger, which calculates the titles based on the importance of each stat. Sort Stats is the routine that actually checks the order in which the stats are ranked, from lowest to highest. Finally, Stat Check is a simple function that adds 1 to the position when the stat is higher than the one it is being compared with. Understand that? If so, great, if not it doesn't matter. Things will become apparent soon.
We're going to start with Custom Title. Set its trigger to be parallel. Custom title constantly runs to see if the heroes' stats have been changed, and if so, alters the title accordingly.
In that version of Custom Title, we've got 4 possible titles and a default one. We'll expand on this later, but the first task is to get the simple version finished and working, you can't walk before you can crawl. I've picked titles that would be befitting of a low level hero, as these are going to be the most basic of titles. We'll now move on to Title Type. Make a new common event, call triggered.
We move next to Sort Stats, which is called at the beginning of Title Type. This is the most complicated of the events, and is awfully repetitive, but we can remove some of this excess code with Stat Check. Understanding this isn't actually important to this tutorial, as all the customisation will take place in the first two common events, but I've tried to explain how it works as best I can for those that want to know. Remember, Stat Check will add 1 to Position if Stat 1 is greater than Stat 2
- you might want to consider this when entering the code as it will help to understand the process.
*Phew* That was terrible! But it should have been easy enough to understand, I hope - we were just determining which attribute was the highest in value and which was second, then storing that data into two variables, Primary Stat and Secondary Stat, along with the difference between them and the next nearest attribute below. Primary Stat variable holds a number from 1 to 4, where 1 represents Attack, 2 Defense, 3 Intelligence and 4 Agility, just like in Secondary Stat. It's helpful to remember this, as we'll be deriving titles from these. Primary Value and Primary Total will be defined and used later.
The latest routine needs finishing off, now, with Stat Check, which will fill in the blanks. This one is nice and short. Again, this is a Call triggered common event. And again, understanding this isn't important, but might be handy.
You're all done now. Try it out, swap and change equipment and you'll see your title change. For a simple title change, you're done, you can stop here. However, I'm going to carry on to new and better things. This is actually simpler than the original code.
We're heading back to Title Type now. You can consider Stat Check and Sort Stats as completed. Stat Check and Sort Stats will never have to be editted - you can add your own titles based on a range of factors without needing to go back to these again.
So let us recap. So far, the system checks which stat the hero excels in, then names his title accordingly. There is a lot of excess code in this for what it does - what we have done so far can be achieved so much easier without all the baggage. However, it has been necessary to code it as we have for these next steps. We're now going to introduce titles dependent on how much stronger one attribute is over the rest, based on percentages. We will say that the Brawler tag that we've added for the Attack specialist only applies when Attack is less than 20% larger than its nearest neighbour. When Attack is between 20-40% bigger than the next attribute in the list, he will be a Berserker. If Attack is over 40% larger, he will be a Titan.
For this step I'll be adding a new common event. It isn't necessary, but makes things look tidier to do so. This will take the Primary Value and Secondary Value variables and the Primary Max variable and perform mathematical operations on them to determine how much larger the Primary is to the Secondary. The difference between the Primary and Secondary Values is the amount that Primary is larger than Secondary. If we divide this by the total value of the Secondary attribute, then multiply by 100, we're left with the percentage increase from Secondary to Primary. Clear? No, I thought not. It looks like this:
( ( Primary Value - Secondary Value ) * 100 ) / Secondary Total
We must multiply by 100 before we divide in RPG Maker as the program doesn't handle fractions. We also don't have a value for Secondary Total, although this is simple Primary Total (which we do have have) subtract Primary Value - Secondary Value. To save some mess, all these percentage calculations will take place in "Percentage to 2nd " common event, initiated by Call.
We'll now call this from Title Type, just after the line where we called Sort Stats. We'll rearrange Title Type to look like this:
We now go back to Custom Title to add in the names for these 8 additions.
Wow! That wasn't too painful, was it? Adding new titles now is a delight! So here's how it looks so far:
|
< 20% |
20 < 40% |
> 40% |
Attack |
Brawler |
Warrior |
Titan |
Defense |
Squire |
Guard |
Knight |
Intelligence |
Scholar |
Mage |
Sorceror |
Agility |
Pick Pocket |
Thief |
Athlete |
Well, now you see a distinct difference in specialisation. However, what if a level 30 hero is good in both Defense and Intelligence, whilst his other skills lack behind? Why, he'd still be called a Scholar or Squire, but he's spent a lot of points to get to this stage. The Titles are derived by calculations based on the two largest attributes, but the way we've coded it, it looks like he's a novice.
Why don't we make a new class for Defense/Intelligence experts, a Paladin? The tree can go Priest->Cleric->Paladin. We'll define the Paladin tree to have the two primary classes within 5% of each other, with the primary stat 10% above the third place attribute to get onto the tree.
Add another new common event, "Percentage to 3rd". It has the same concept as "Percentage to 2nd", except we base it off the third ranked attribute rather than the second.
Couple this now with a check to see if the secondary stat is 90% or more of the primary stat. "10% 1st and 2nd" Call common event.
Finally, edit Title Type to accomodate these next additions. You can cut and paste the Basic Class information (between dashed lines) into its new place.
Now just add hero type 13 to Custom Title. This will, of course, only give you one of the Paladin tree, but by now I hope you can easily add the rest of the tree, along with any other classes you decide up. This was a long slog, but we got there in the end.