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.
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.
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?
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).
You then add a STR modifier which is calculated by (STR-10)/2. A character with STR 10 would get no bonus, a char with STR 14 would get a +2, a char with 8 would get a -1.
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
I'm sorry if my question was vague...
I meant how should I balance the stats and stuff? How much should your stats raise each level? Should I have a choice like in Diablo? How much should the exp requirement change per level? Do any of you have documentation or anything on this? My basic stats are as follows:
HP (max 1000)
Strength (max 100)
Vitality (max 100)
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...
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.
I created a couple of characters in Diablo2 that are more or less unplayable in Hell difficulty, while they rock in nightmare.
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
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.
So if I have 'the all powerful sword of wacking' (15) and my str is 70, I do just as well as my brother with 'the useless sword of wanking' (1) who has str 84.
He's str isn't that much better than mine, I should be doing more damage with my cool sword.
I guess what I'm saying is that you should multiply some stuff.
I think what Diablo uses is
total_damage = weapon_damage*(1+str/100)
for simple cases.
ie. each point of strength adds 1% damage.
With your kind of numbers though, you might want to try something like 5%
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
that sexy little curve is useful for so many things...
Just direct him to some online AD&D rulebook to plagerize It's a start ...
Here's how I do it in my MUD.
(This code is for regular attacks)
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.
I need to change 1.25 in the first part of the code to a value which is given by the weapon (obj), rather than a static value. I prefer using a float like that to calculate the strength of a weapon. That way you have a much wider variation.
Some swords might be 1.25, but raise your strength by 5.. and another sword might be 2.0, but lower your strength because it's so fricken heavy.
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
The code is available on my site if you really want it. heh..
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.
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).
Also, it would be a fair bit faster to calculate exp(-x/xx) than pow(4, -x/xx). I'm not sure about this from a computing point of view (haven't tested it), but from a mathimatics point of view it is*. I'd test it now, but I'm not on my own computer...
Is there some special reason you are using base 4 instead of the natural base (e)?
Aside from all that, your graph reminds me of arctan...
*
pow(4, x) is defined as exp(x*log(4))
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.
Just direct him to some online AD&D rulebook to plagerize
Yeah!
Just use google.
There're more free RPG systems than you might believe.
You can also download d20 (the d&d rule base) and gurps.
Just use google...