#### Archived

This topic is now archived and is closed to further replies.

# I need help making a damage equation for my RPG

This topic is 5710 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I am making an RPG in VB. Don''t laugh. My problem is mathematical, not lingual. I need a good damage equation based on Attack and Defense. The maximum values for each are 100. I am going nuts trying to figure out a good equation. Any help is appreciated.

##### Share on other sites
i''m not exactly sure by what you mean by a damage equation, from what it sounds like you''re saying though you want to calculate the new life of a player after it has been attacked based on the defenses it has. if this is the case then this may work.

Defense = DefenseItem1 + DefenseItem2 + etc. this gives you the total defense you have.

Damage = value for weapon

newLife = life - (Damage - Defense)

##### Share on other sites
Maybe something like:

Damage = YourAttack / EnemysDefence + YourAttack / 10

This ensures that the enemy''s defence has a large impact on the damage, but a good attacker can''t be stopped cold.

Just an idea, do what you feel is best.

##### Share on other sites
These look like good ideas. I''ll need to test them, but they look good. For clarity I''ll define "damage equation". The equation should tell me how much HP to subtract from the defender based on the attacker''s attack and the defender''s defense. I hope this makes things clear. BTW equipment adds to the total attack/defense of a player. Your idea looks good gamechampionx. I''ll give it a try.

##### Share on other sites
If those other damage equations don't work well, you could try and Google the D&D rules. They probably have a very good damage system.

_______________ ___ ___ ____ ____ ____ ____
| | | | | | \ \ / / \ \ / /
| | | | | | \ \ / / \ \ / /
----- -----| | | | | \ \ / / \ \ / /
| | | | | | \ \ / / \ \ / /
| | | | | | \ V / \ V /
| | | | | | \ / \ /
| | | | | | / \ / | | | | | | / ^ \ / ^ | | | \__/ | / / \ \ / / \ | | \ / / / \ \ / / \ | | \ / / / \ \ / / \ --- ------- ---- ---- ---- ----

[edited by - tuxx on June 30, 2002 1:19:40 PM]

##### Share on other sites
abd = attackers base damage
ap = attackers +''s (include magic items/weapons etc +''s to damage - a long sword may have +10 to damage, a ring of power may have a +5 to damage)

dbd = defenders base defence
dp = defenders +''s (include armour/magic rings etc +''s to defence - plate mail may have + 15 to defence, magic ring of defence + 8 to defence)

the attacker has a base damage of 20, a long sword (+10) and a magic ring of hurting (+5)
the defender has a base defence of 8, magic armour of the gods (+15) and a cursed ring of defence (-5)

td = (abd + ap) - (dbd + dp)
(+20 +10 +5) - (+8 +15 -5)

td = 35 - 18
td = 17

u might as well throw some random element in there as well
td = random(td/2, td)

##### Share on other sites
Theres some documents by Ben Siron on the mathematics of console rpgs like Final Fantasy and Breath Of Fire. These can give you an idea of what to do. Though whats important is that you direct the numbers where you want them to go. For example,

Character = Strength, Vitality.
Equipment = Attack Power, Defense Power.

And, lets just say that with a 100/100 in STR and ATP, it should do the most damage possible, which is 999. Theres one important detail to decide here. Do we want damage cummulative or multiplicative? For example, does the 100/100 mean you do 200 raw or 10000 raw? In the first, you''d need an after multiplier of 5 to make near 999, the second needs a divisor of 10.

However, if you just want something simple, try this.

Raw = Actor.STR + Actor.ATP - Target.VIT - Target.DFP
Raw = Raw * Random(Raw - (Raw/16), Raw + (Raw/16))
Target.Life = Target.Life - Raw
IF Taget.Life <= 0, TARGET IS DEAD.

Play with the idea, add in elemental multipliers or weapon class modifiers, or whatever little thing you want to make your RPG stand out.

-> Will Bubel
-> Machine wash cold, tumble dry.

##### Share on other sites
Real RPGs attack damage specifiers are usually complicated. Overloading operators can really shine here and make clean looking code(I dunno what it''ll do for speed - but you shouldn''t be calculating damage multiple times per frame).

Only considering attack and defense - you could make things easy and use:

Damage = Attack - defense;
and check if damage is negative(if you use an unsigned it will wrap around to a huge positive number) or zero.

Of course if you do that, when you attack the same monster you''ll always do the same damage, and any attack becomes static. Most RPGs have a randomness to the attack damange.

First, every now and then a critcal hit comes up based on luck usually, and 2 or 3 times the damage is dealt on that hit.

Continuing, dexterity is sometimes used to determine the range of attack damage. The higher the dexterity, the higher chance you will actually do your max damage in battle.

So using dexterity and critical hit rate, you''d get an expression like so...

  maxattack = attack - defenseDamage = Random( maxattack - (100 - dexterity), maxattack) //Make it a range between your max attack, and your max attack minus some number that is inversely affected by your dexterityif( random(100) < luck)  //if you hit a number less than the luck stat(a higher number means more luck)    damage = damage * 2;   //(damage *= 2) this is a critical hit

Of course, after you calculate your normal damage, you can start crunching your elemental properties/weapon modifiers and what not.

Note: Generally RPGs use 999, or 999 to cap numbers. For stats there usually isn''t a cap - rather they just give a character a certain stat value at the character''s highest level.

Also, there is a difference between attack and Strength in RPGs. Generall Str will go towards your physical defense too. Attack is usually the end number when combining a characters strength and weapon power.

IF you are making this a complicated RPG, I also recommend using many number for attack and defense. You''d probably need more variables than you think.

Like what I said about strength and attack being two different things. And also the fact that attack is dependant on the weapon being held too. An actual attack number should be generated everytime there is a hit, not predetermined by the character''s stat(unelss he/she wont ever use another weapon).

"Ogun''s Laughter Is No Joke!!!" - Ogun Kills On The Right, A Nigerian Poem.

##### Share on other sites

toTit=enemyDefense-yourAttack
clamp toHit to range (0-100)
attackvalue=random between (0-100)
if (attackvalue>toHit) do the damage the weapon has.

You might want to give an attackvalue of 0-5 = always miss and 95-100 is always hit.

Here''s something to make it more realistic: Don''t include the enemy''s armor in the defense stat. Base the defense purely on the enemies speed, skill and weapon (some weapons can be used for defense really well, like sword, while others, like spears, cannot).

After getting a hit: Say the enemies armour is between 0-100. the damage inflicted is weaponDamage*(enemyArmor/100). The higher/better the armor, the less damage inflicted. This is more realistic than adding the armor to defense. In reality armor stops you from getting wounded/killed. Armor does not stop you from getting hit (exeption: shield. DO add the shields armor value to enemyDefense).

Hope this helpes,

Sander Maréchal
[Lone Wolves Production][Articles][E-mail]

##### Share on other sites
Hm, guys - sorry - I consider most stuff said here so far to be pretty crappy. Frankly, would anyone of you want to play a "pen and paper" RPG with this type of rules? There is no need to
(a) use decimals and
(b) use a linear random number generator.

Lots of good games and rulesets do better with a lot of simplier rules based around dice, and they are well proven - the games must be so simple that you can easily check them out with pen and paper before programmning them in.

That said, I consider MOST of the RPG rulesets out there to be crap, at least from my experience of pen and paper RPG''s years ago. The leveling system often is total crap - be carefull not to make this mistake. My best shot here is DAOC where you CAN realistically fight an enemy only within a VERY narrow level range. My complain here is not that I loose when I choose an enemy too strong (lets say one for lvl 12 when I am lvl 10) but that the system is SO unbalanced that (a) I die with one of two hits and (b) I will NOT hit him and IF I hit iim seldomly not make any significant damage. Means, not even 3 Lvl 10 players can take out the enemy for lvl 12.

Check out the Alternity Warship rules for some nifty ideas. They had, which I like as an idea:
(a) armor value defined by dice and random factors. The old story: you roll fo a hit, then the damage is substracted by the armor value, just that the armor value is random for every hit. That brings in the point that armor is sort of random - do you hit straight on the shileding or do you somehow slide through some sort of binding element. This way a lot of luck (great damage with a dagger) can still do SOME small damage to a knight (who is very unlucky determining the armor rating for this hit), though statistically there is no damage.
(b) they had - but this is for spaceships - different fire strength and resistance levels. When you ship is too small for the weapon hitting it, the damage is upgraded to critical damage etc. I forst did not like it, then I realised what it is for: to keep the numbers lower :-) So big battleships dont run into hundreds of thousands of hitoooints and need hundred dice for the damage. A battleship weapon normally is way stronger than a normal small cruiser, and it''s weapons are designed with batttleships as targets, so all damage to the small cruiser gets "upgraded". They also had different damage types (like wound, critical etc.) and the damage would be upgraded - the wound roll would suddenly be critical :-) Was a nice move.

In general, my main advice is:
(a) get some money
(b) go out and buy roleplaying books.

Avoid the typical mistakes done by most computer designers. For example morrowind has one:
- it is skill based and successfull use based. Means: hit with a sword and you gain skill points. Have enough skill points, you to hit value goes up.
Problem: The higher your skill the more often you hit. As a result, you gain skill levels iwith a sowrd FASTER when you are better. Sure you need more hits (tehy tried to balance this), but they failed - you accelerate your skill gains later on simply due to (a) tougher monsters = longer battles = more successfull hits and (b) higher skill = more hits for the same number of attempts.

SAD :-) I pretend they would NOT have had this if they would have a system they can plan and play and balance on paper first.

Regards

Thomas Tomiczek
THONA Consulting Ltd.
(Microsoft MVP C#/.NET)

##### Share on other sites
Sorry,

"I consider MOST of the RPG rulesets out there to be crap"

I consider MOST of the computer RPG rulesets out there to be crap"

I tried to compare computer stuff with "traditional" sets which is where I got my first contacts with.

Regards

Thomas

##### Share on other sites
Without a whole load of details on your system Ill refrain from making much in the way of suggestions but a few things to remember are:

1. You should never always be able to hit and hurt something. This will haunt you if you allow it and then introduce magic or a focus period for higher hit rates/damage.

2. Your system should be simple. There is no reason for complex damage calculations.

3. It should help build your game, not control how people fight. In other words characters should be able to develop styles and skills that allow them to fight and not have to use tricks such as, if you are always hit dont bother with dodging buy the best armour you can!

Im happy to talk about some of the options you have if you want to IM me, but I need more info and a forums not the place for it

Good luck.

BaelWrath

If it is not nailed down it's mine,
and if I can prise it loose,
it's not nailed down!

[edited by - baelwrath on July 1, 2002 8:35:10 AM]

##### Share on other sites
While it may complicate the system, something I would recommend including as well are modifiers based on what the target is doing. Like, if it''s a mage preparing a spell, make damage 3/2 of what it would normally be since they''re too busy with their spell to defend. Or if it''s a counterattack, change the damage or success rate based on the speed of the counter-attacker (like, if they''re slow, the target will have more time to return to a defensive stance and hence take less damage or dodge better).

I also recommend having damage formulae rely on other stats than just physical strength. For example, if you''re using a gun or a bow to attack, it''s pretty silly to say that if you''re stronger, then you should do more damage (unless of course you''re pistol-whipping the enemy ). Maybe use speed to determine how many times you can fire in one attack and base the damage of the attack on the power of the weapon times how many shots you get in.

I''m getting some of my ideas on Final Fantasy Tactics here, just so you know. The thing I''m not sure I like about that game is the use of speed in calculations of attacks with knives, etc. It seems arbitrary to say that if you''re faster then you''ll hit harder with a knife.

It''ll take some creativity to come up with some good equations that will use other stats in a justifiable way.

What I really dislike though is equations based largely on random numbers. Beyond what Inmate2993 suggested, where damage only varies by about 5%, it''s just annoying. While I don''t like to try to calculate exactly how much damage I''ll do, it''s good to have at least a reliable expectation of damage done and not to be surprised when my attack does 10 damage when attacking an enemy and 250 the next time I attack the same enemy.

-Auron

##### Share on other sites
heres a pretty simple system with:
Attack, Defense,
Weapon-Types, Armor-Types,
Damage, Armor
Magical Bonuses

(i just wrote this off the top of my head, so some stuff may be off)

some of these calculations cound be precalculated.

//(p1 attacks p2)//
AtkBonusA = p1.attack / ( p2.defense + 1) + p1.MagicAtkBonus;
ChanceToHit = (( 100 * AtkBonusA) - ( p2.ChanceToEvade() )) * rand() + 15;

if( ChanceToHit > 50 )
{//struck
DmgRange = (p1.MaxDmg - p1.MinDmg) * p1.MagicDmgBonus;
if( 100*rnd < p1.ChanceToCrit) DmgRange*= p1.CritMod;

DmgBonusA = p1.attack / (p2.defense * 2 * p1.weaponModVsArmor( p2) + 1);
Dmg = 1 + (DmgRange * DmgBonusA - p2.armor * p1.weaponModVsArmor(p2)) * rand() + p1.MinDmg * p1.MagicAtkBonus;
if( Dmg < 0) Dmg = 0;

p2.takeDmg( Dmg);
}

##### Share on other sites
To begin with, I have seen some useful stuff here. Some of you though are thinking of stuff outside the rules. I''m trying to think of something simple. The only reason I only need attack and defense in the equation is because every attack is assigned an element, for this purpose "physical" is an element. Also the attack and defense are already the player''s naked stats with the weapons and armor added in. Skill is the critical hit factor. So all I need is something simple. I origionally used:

Damage = (((Attack * 2) - Defense)/2) * (5 + int(rnd * 3))
If int(rnd * 100) <= Skill then Damage = Damage * 2

Where Attack and Skill were the attacker''s attack and skill in that element and Defense was the defender''s defense in that element. I thought it was pretty good but occassionally my friends said that they got odd numbers so I came here looking for ideas. Please remember that this is Visual Basic code. I am learning C but I find it difficult and am only marginally good at translation.

##### Share on other sites
Find some code to replace the rnd element and I think it will be more stable. The rand can be from 0 to 8 which means your damage can be zero to 8 times the stats calculation.

Maybe move the random numbers into the basic equation.

Oh, and you never really learn C++ just get to a point you can pretend well until they add more to it! (MC++, C# etc)

Have fun.

Regards

BaelWrath

If it is not nailed down it''s mine,
and if I can prise it loose,
it''s not nailed down!

##### Share on other sites
it all depends on what scale and gameplay you have. if you are making a fps or diablo, it might be good to have random ranges, but if your making a rts, then ranges wont be noticed, and you can stick with hard values.

##### Share on other sites
why not run some tests on these equations you are working on?
create a "test form", with some buttons and textboxen where you can enter the stats of two characters, and click a button that simulates them beating the crap out of each other. have it do this a thousand times and spit out some statistics for you. use these statistics to decide if it is balanced or if you need to tweak something.
if you find that something is way off wack, you can just change your code a bit and hit F5 to run it again.
stop doing this when you are satisfied with the balance.

--- krez (krezisback@aol.com)

##### Share on other sites
LLGames:

If you really don''t like rule sets that are similar to Dungeons and Dragons, I reccommend you take a look at Warhammer 40.000 rules by Games Workshop. They have a totally different approach to stats and combat resolution. The 3rd edition rules are pretty good. IMHO the 2nd edition hand-to-hand combat were a little bit better. I''ll explain em here to you since they cannot be found easily any more:

Models stats:
M Move
WS Weapon Skill
BS Ballistic skill
S Strenght
T Toughness
I Initiative (reaction speed)
A Attacks
W Wounds

All stats are on a scale of 1 to 10, but for true RPG you might want to raise the W a lot since combat is real deadly! Anyway, The combat system:

Each player rolls as many dice as the A stat,
Pick the highest dice,
Add +1 for every 6 rolled after the first one,
substract -1 for every 1 rolled after the first one,
Add +1 for if 2 weapons are wielded,
Add special weapon and special ability bonuses (usually between 0-2).
This is the combat score.

Say Player has a combat score of 11 and Enemy a combat score of 15. 15-11=4 so enemy hits Player 4 times. If the combat scores are equal, Player with higher I stat scores 1 hit. If even I is equal, combat is stand-off. After this, work out the 4 hits scored by enemy (still the same in 3rd edition so you can look it up).

This is a VERY powerfull system. It makes combat extremely deadly (as it should be IMHO). One advantage: No need to calculate a damage equation every time the player presses attack. This system will resolve the entire combat for you. In this example player makes 11 swings at enemy. enemy takes 15 swings at player. So you get 11 of those nice "cling Clang" sword hits and then 4 direct swings at player.

Sander Maréchal
[Lone Wolves Production][Articles][E-mail]

##### Share on other sites

POffense // Offense Skill, including all modifiers
PPower // Weapon Power, "
TDefense // Target Defense, "
TArmor // Target Armor, "

POffense + rand > TDefense = target is hit
PPower + rand > TArmor = target is damaged