• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Question: Stats handling for a RPG

T

TheBlindG

Guest
Hello fellow makers!


I am in the stage where I am implementing level up and stat increase per level, I don't want the stats to increase with a formula of sorts, I want them to increase sometimes by 1, and sometimes by 2 etc.. I was thinkingf of making a big script which checks for the characters class and in a CASE statement check for the characters level and set the stats in that CASE statement. Is this a good idea?

Are there any better sugestions?

Thanks in advance!
 
T

TheBlindG

Guest
Is it possible to make a function/formula to calculate this if I know my base and max values? At level 1 i want 6 atk, and at lvl 50, 53 atk. Would appriciate if some1 could help! :)
 
N

Noyemi K

Guest
No, setting RPG progression in a switch() statement is not a good idea at all. It sounds to me like you're looking at roughly a linear progression, so there's no reason you can't just have the stats increase by 1 or 2 when a levelup event of some kind is called, and then simply reset the stat to max if it maxes out.
 
C

CedSharp

Guest
If you're game has say 100 levels, then you can just add them in an array.
Code:
level_info = ds_grid_create( 100, 3 ); // 100 levels, 3 info per level

// Level 1
level_info[# 0,0] = 50; // The xp needed to level up
level_info[# 0,1] = 5; // The max hp to add when level up
level_info[# 0,2] = 5; // The max man to add when level up

// Level 2
level_info[# 1,0] = 120; // the xp needed to level up
level_info[# 1,1] = 6; // The max hp to add when level up
level_info[# 1,2] = 3; // The max mana to add when level up

// Level 3
level_info[# 2,0] = 137; // the xp needed to level up
level_info[# 2,1] = 2; // The max hp to add when level up
level_info[# 2,2] = 7; // The max mana to add when level up

{...}
It's then super easy to track. When you add xp, you can just check:
Code:
if( xp > level_info[# current_level, 0] ) {
    maxhp += level_info[# current_level,1];
    maxmana += level_info[# current_level,2];
    current_level += 1;
}
etc
 
C

CedSharp

Guest
Because I don't like working with numbers ( they don't mean anything ) I always create enums to help me.
Code:
enum Level {
    xp = 0,
    maxhp = 1,
    maxmana = 2
}


// Level 1
level_info[# 0,Level.xp] = 50;
level_info[# 0,Level.maxhp] = 5;
level_info[# 0,Level.maxmana] = 5;

// Level 2
level_info[# 1,Level.xp] = 120; 
level_info[# 1,Level.maxhp] = 6;
level_info[# 1,Level.maxmana] = 3;

// Level 3
level_info[# 2,Level.xp] = 137;
level_info[# 2,Level.maxhp] = 2;
level_info[# 2,Level.maxmana] = 7;
No need for comments anymore, it's more clear and easy to understand :D
 

Hyomoto

Member
As long as you achieve the desired result, there's absolutely no reason to not use the method that works for you. A lot of people get caught up in programming asking the question, "What's the best way to do this." The general answer to that is, "The way that works." That said, I think @CedSharp's answer should work for you. However a giant switch statement is completely fine if it works.
 
A

anomalous

Guest
Values like this are typically determined one of two ways.

1. an algorithm/calculation
2. a lookup table

A clean algorithm is often the most elegant. However you say you do not want that. In this case, use a lookup table.
Create an array that has stats in the X columns, and level# in the Y. Like global.astate[4,20] for example.
Visually that table is like this:
..str, dex, int, con
0
1
2
3
4
...
20

note: if you include row 0 (leave it empty or with null values), your level is equal to the row #.
Use enumerators for x position,l like e_stat.str, e_stat.dex, etc.

To find strength at any level its one line:
str = global.astat[e_stat.str, level]
 
C

CedSharp

Guest
Values like this are typically determined one of two ways.

1. an algorithm/calculation
2. a lookup table

A clean algorithm is often the most elegant. However you say you do not want that. In this case, use a lookup table.
Create an array that has stats in the X columns, and level# in the Y. Like global.astate[4,20] for example.
Visually that table is like this:
..str, dex, int, con
0
1
2
3
4
...
20

note: if you include row 0 (leave it empty or with null values), your level is equal to the row #.
Use enumerators for x position,l like e_stat.str, e_stat.dex, etc.

To find strength at any level its one line:
str = global.astat[e_stat.str, level]
You basically said exactly the same thing as what I said lol.
 

Yal

🐧 *penguin noises*
GMC Elder
In my old RPGs, I did this by having a levelup script that's called when you level up, which adds points using choose() or irandom_range() to each stat - HP would rise more than attack or defense, and so on. This approach isn't the best from a game balancing standpoint (some people might get unlucky and get really bad stats) but it's really easy to implement and easy on processing as well (only called when levelling up).

Another approach is to do like Pokémon - you have your stats at max level known (and stored somewhere) and also the stats at the lowest possible level, and use linear interpolation between the Lv.0 and Lv.100 stats based on your level. Since you round these to integer values, you will sometimes get 2 points in HP, other times 3, depending on how the rounding of an 2.45 point increase goes. Pokémon's formulas are more complicated since you also have stat points gained from your IVs and EVs on top of the points gained from levelling up, but the gist of it is that your stats are constantly computed in real-time each time you need them for calculations, they're not stored anywhere.
 

Yal

🐧 *penguin noises*
GMC Elder
Heh, none of them really got close to being finished... Chronicles of Calthra II: The Princess' Brother, and the example games in my old GM6 RPG engine and the SisterEngine RPG engine. AFAIK the former only ever was uploaded to the YYG Sandbox, and I'm pretty sure I backed it up, but it's nothing I'd recommend playing :p Final Columbus and Gun-Princess 1 both had much better storytelling AND gameplay.
 
T

TheBlindG

Guest
Another approach is to do like Pokémon - you have your stats at max level known (and stored somewhere) and also the stats at the lowest possible level, and use linear interpolation between the Lv.0 and Lv.100 stats based on your level. Since you round these to integer values, you will sometimes get 2 points in HP, other times 3, depending on how the rounding of an 2.45 point increase goes. Pokémon's formulas are more complicated since you also have stat points gained from your IVs and EVs on top of the points gained from levelling up, but the gist of it is that your stats are constantly computed in real-time each time you need them for calculations, they're not stored anywhere.
This is how I want it I guess, because at level one the stat is 6 and at max level, 50, the stats should be 53. So I guess that's how I do it?
 
T

TheBlindG

Guest
This might work right? stat_increase = base_stat + (current_level - min_level) * [(max_stat - base_stat)/(max_level - min_level)]
 
Top