![]() |
|
RPG stats & math! |
aybabtu
Member #2,891
November 2002
|
I need some help with formulas for figuring damage in my RPG. Not only the formulas, but ideas on how stats change at level up. I'm using a real-time combat system, where a level 1 monster should take about 4 hits to kill. I just have simple stats like strength & vitality for both the player and the monsters. |
kazzmir
Member #1,786
December 2001
![]() |
your question is incredibly vague, so heres a very generic answer: int getDamage( thing * p ){ return p->power + p->weapon_power; } int takeDamage( thing * p, int damage ){ p->life -= damage / p->armor_rating; } Or you could describe the sort of formulas you need and maybe youll get a better answer. |
Ultio
Member #1,336
April 2001
|
Like kazzmir said, it all depends on what kind of system you are using. Will enemies have armor? Or simply just a health attribute? I think a very simple way to do it if your ONLY two attributes are strength and vitality is this. The player has a set "core" strength for each level he is on. IE, level 1 starts at say, 10str. Then there is additional strength that's added on. For instance, a sword or something. So you could just create a random number from the core strength up to the core strentgh + the sword strength. As for making the enemies the right difficutly. Find out what general equipment the player will have at said level in said area, and determine how much hp it should have if you multiply the total damage the player should do by 4. Simple. I would think there will be more stuff like weapons, armor, and other things that will play a role. I guess it depends on how you want to do things. Maybe you could elaborate a little more? --- |
spellcaster
Member #1,493
September 2001
![]() |
You have a lot of choices here. In some systems, damage is based on the weapon. In D20 your weapon determines the damage. For melee weapons you get a strength modifier. Say you have a sword with 1d6 damage (which is a range of 1..6 inclusive). int rollDice(int dice, int number, int mod) { int sum = 0; for (int a=0; a < number; a++) { sum += (rand() % dice) +1; } sum += mod; return sum; } int calcMeleeDamage(Weapon weapon, Character wielder) { int dam = rollDice(weapon.diceType, weapon.diceType, weapon.modifier); dam += (wielder.strength -10) /2; return dam; } It really depends on your system. In a very simple system you could do struct Character { int attack; int defense; int hp; }; void attack(Character *attacker, Character *defender) { defender->hp = MAX(attacker->attack - defender->defense, 0); }
It's your choice -- |
aybabtu
Member #2,891
November 2002
|
I'm sorry if my question was vague... The strength is added to by the equipped weapon's power, which is mostly between 1 & 15 (15 are the strongest weapons). The defense is added to by shields and armour. I run into the problem that enemies the same level and above the player will usually take <=0 damage from my attacks! The same works for the player when he's getting attacked! It's all very confusing to me... |
spellcaster
Member #1,493
September 2001
![]() |
Um... we don't know the game... how should we answer such a question, if even you, as the creator can't answer it? If your game has 100 levels, and the character should be around lvl 80 to have a chance against the endboss, you should check the attributes needed at lvl 80, compare them with those at lvl1 and use this to define the increase in stats... How you want to deal the leveling is your choice. If you allow the player to distribute points, he can do stuff wrong. On the other hand, it's fun to skill a character. But these are pretty basic questions... in fact, you should have sorted them out before you start coding even a single line -- |
Karadoc ~~
Member #2,749
September 2002
![]() |
Quote: The strength is added to by the equipped weapon's power, which is mostly between 1 & 15 (15 are the strongest weapons). The defense is added to by shields and armour.
they are added? That's not a very good way of doing things if you ask me. Don't be afraid to experiment with numbers and formulas. Think to yourself, "if I increase the weapon power by X, what do I want the effect to be for all the different characters?". My favoriting function for game balance is arctan ----------- |
23yrold3yrold
Member #1,134
March 2001
![]() |
Just direct him to some online AD&D rulebook to plagerize -- |
Derezo
Member #1,666
April 2001
![]() |
Here's how I do it in my MUD. obj = HasWeapon(agg); if(obj) { dmg += (int)(agg->att.att_str * 1.25); } else dmg += (int)(agg->att.att_str * 0.75); dmg += rand()%(agg->level+agg->att.att_lck); dmg = CalcDamage(agg,tgt,dmg,DMG_WEAPON); Some irrelevant code removed. Then CalcDamage looks like this: int CalcDamage(CHARACTER *agg, CHARACTER *tgt, int dmg, int type) { int ret = dmg; int acc = tgt->att.att_agi - agg->att.att_agi; if(acc > 0) { if((rand()%acc)>>4 > 0) ret = 0; } if(ret < 0) ret = 0; return ret; }
Obviously incomplete. What also needs to be added is the damage type specific stuff. So if you attack ice with fire, it would hit for more [edit: not defend better you idiot, derezo!]. This gets extremely confusing with my setup, and is why I haven't done it yet I also have a 'damage' function which actually handles taking away the hp, killing the target, and everything else involved in that. It also handles spells that may be affecting the target or caster, and adjusts the damage according to that. I didn't read many of the posts, but there's a way I do it for now For magic and skills, I do something completely different.. but it's a lot more code and I wont bother posting it because it probably wont make any sense "He who controls the stuffing controls the Universe" |
james_lohr
Member #1,947
February 2002
|
In one word: exponentials!! Here is a sample: (Used this for almost everything in my RPG eg spell damage, damage reduction from AC etc) A detailed explanation will follow. //x=input variable,lim=max limit,xx= x value at y= (3/4 of lim) Ok here's how it works: The value lim is the max limit of the returned value. This is what the function will return as x tends to infinity. Now the clever bit is xx. xx is the value of x when the returned value is equal to 3/4 of lim. So really lim and xx defines a specific exponential curve: a|---------------------------------------- | x | x (3/4)a| . . . . . . . x | x . | x . | x . |x______________.__________ xx ---> x (lol I don't often do text-graph')
Here is an example of how to use it: You have a stat, AC, which will reduce the amount of damage you recieve. You want AC to be able to take any value but say 100 would be considered to be quite high. So now you want to work out the exact % the damage should be reduced by. Firstly you don't want lim (max value) to be equal to 100 because then it will be possible to reach (or get near to) the point where you don't recieve any damage. So set lim to 80. Secondly you want 100 to be pretty high so set xx to 100. so: damage_received_reduced_by=e_value(your_ac,80,100); simple This means that if your armour class is 100, damage will be reduced by (80*3/4)=60%. Even if your armour class is something ridiculous like 1000, you will always recieve at least 20% of the enemies damage.
|
Karadoc ~~
Member #2,749
September 2002
![]() |
A little bit of work on paper yielded that this was the same as: float e_value(float x,float lim,float xx){ return lim*(1-pow(4, -x/xx));
So if that's what you're using, you might want to check my maths with a short test program, and if I'm right, switch to what I said (would be faster). Aside from all that, your graph reminds me of arctan... * ----------- |
james_lohr
Member #1,947
February 2002
|
That looks much better too! (like the equation for charging a capacitor). Thanks for simplifying it. Just tried it myself, was actually quite messy to do I used 4 because I preferred it's curve. If you plot the graph of both you'll see what I mean. Maybe it would have been a good idea to include the base (ie 4 in this case) as part of the definition of the curve. I'm not sure if it's really necessary though.
|
aybabtu
Member #2,891
November 2002
|
23 said: Just direct him to some online AD&D rulebook to plagerize Yeah! |
spellcaster
Member #1,493
September 2001
![]() |
Just use google. Just use google... -- |
|