• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

damage calculation for rpg

Status
Not open for further replies.

Kazeon

Hosted Project: EC
Level 34
Joined
Oct 12, 2011
Messages
3,449
Anyone knows a nice damage calculation for RPG game? I have googled it around and some people said that some kind of damage calculations took about 500 lines of codes. o 0

I only use variables like damage min, damage max, and defense by the way. I hope that someone can help me :) thnks..

EDIT: I meant dont use "damage final=(random from damage min to damage max) - defense". it's bad calculation..


EDIT 2
I have a new problem here.. I have a formula like this
  • Monster Attacks
    • Events
    • Conditions
    • Actions
      • Do Multiple ActionsFor each (Integer Hostile_Integer[4]) from 1 to Hostile_TotalOnMap, do (Actions)
        • Loop - Actions
          • Multiple FunctionsIf (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Damage source) Equal to (==) Hostile_Unit[Hostile_Integer[4]]
            • Then - Actions
              • Set Global_DamageMultiplier = 1
              • Set Global_DefenseMultiplier = 1
              • Game - Display to (All players) the text: a
              • Set Hostile_Damage = (((Random integer number between Hostile_LibDamageMin[(Level of Hostile_Unit[Hostile_Integer[4]])] and Hostile_LibDamageMax[(Level of Hostile_Unit[Hostile_Integer[4]])]) x Global_DamageMultiplier) - (((Status_Defense x Global_DefenseMultiplier) x Status_Defen
              • Game - Display to (All players) the text: b
              • Set DamageEvent_Amount = Hostile_Damage
              • Game - Display to (All players) the text: c
              • Set DamageEvent_Target = MainUnit
              • Game - Display to (All players) the text: d
              • Set DamageEvent_Source = Hostile_Unit[Hostile_Integer[4]]
              • Game - Display to (All players) the text: e
              • Set DamageEvent_Type = physic
              • Game - Display to (All players) the text: f
              • Set DamageEvent_Real = 1.00
              • Game - Display to (All players) the text: g
              • Set DamageEvent_Real = 0.00
              • Game - Display to (All players) the text: h
            • Else - Actions
the event is = Main Character takes damage. Just dont think about that global multiplier variable.. The problem is when I added a little complex damage calculation, the debug message "b" wont appears, a.k.a it's not triggered. Anyone can help me with this?
here is the formula
set udg_Hostile_Damage = ( ( GetRandomInt(udg_Hostile_LibDamageMin[GetUnitLevel(udg_Hostile_Unit[udg_Hostile_Integer[4]])], udg_Hostile_LibDamageMax[GetUnitLevel(udg_Hostile_Unit[udg_Hostile_Integer[4]])]) * udg_Global_DamageMultiplier ) - ( ( ( udg_Status_Defense * udg_Global_DefenseMultiplier ) * udg_Status_DefenseGauge_Current ) / udg_Status_DefenseGauge_Max ) )

I think the problem is the formula is too long or complex. where if I use a simple calculation it works normally, or anyone knows another reason?

I had tried to separate the calculation into several variables
like
set udg_Hostile_Damage[1] = GetRandomInt(udg_Hostile_LibDamageMin[GetUnitLevel(udg_Hostile_Unit[udg_Hostile_Integer[4]])], udg_Hostile_LibDamageMax[GetUnitLevel(udg_Hostile_Unit[udg_Hostile_Integer[4]])])

set udg_Hostile_Damage[2] = udg_Hostile_Damage[1] * udg_Global_DamageMultiplier

set udg_Hostile_Damage[3] = ( (udg_Status_Defense * udg_Global_DefenseMultiplier ) * udg_Status_DefenseGauge_Current ) / udg_Status_DefenseGauge_Max

set udg_Hostile_Damage[4] = udg_Hostile_Damage[2] - udg_Hostile_Damage[3]

set udg_DamageEvent_Amount = udg_Hostile_Damage[4]

but it also wont works, sorry, I converted it to text using JNGP so that's the result..

I use unit level for unit's index at my library btw..
 
Last edited by a moderator:
Level 26
Joined
Aug 18, 2009
Messages
4,097
What kind of question is that? You decide what you want to realize, then you can plan what you need for it. In this case, this belongs in the World Editor Help Zone (Triggers/Scripts is only regarding existing triggers).

Or you ask us for some featured concepts for the map, wherefore we need vast knowledge of the existing environment. Head to the Idea Factory under Map Development then.

I meant dont use "damage final=(random from damage min to damage max) - defense". it's bad calculation..

Yes and make statements what you like and what you decline and reason it, so we can come up with something that helps you.
 

Kazeon

Hosted Project: EC
Level 34
Joined
Oct 12, 2011
Messages
3,449
what kind of question? clearly I wrote "Anyone knows a nice damage calculation for RPG game?" and I wrote "I only use variables like damage min, damage max, and defense by the way" that mean I need a help from people who knows a nice damage calculation using those variables. Isn't it clear enough for you dude? sorry if I post it in a wrong forum bcause I think this is still categorized as triggering and scripting since making damage calculation need scripting. and it's not a real problem to be said here.

I have posted some questions like this in some forums and this is the worst response I have got, "what kind of question?" :lol
 
Level 26
Joined
Aug 18, 2009
Messages
4,097
Isn't it clear enough for you dude?

No. I do not know what is wrong with

I meant dont use "damage final=(random from damage min to damage max) - defense". it's bad calculation..

I do not know your map/game. There are fantastillions of ways to make an rpg. Nor do I know what's wrong with a mere 500 lines of code or how you have trouble realizing your ideas or why you have only these three stats.

and it's not a real problem to be said here.

One reason why I replied and why I asked for the kind of question is to be able to identify the thread in order to report it and have it moved to the appropriate section. There and with proper information the chance to help you rises. Help us to help you.

Also you may link to the other threads so we can draw more information.

The standard wc3 damage calculation is this way btw:

Code:
armorFactor = 0.06

if (armor > 0)
    dmg = dmg * (1 - (armor * armorFactor) / (1 + armorFactor * armor))

if (armor < 0)
    dmg = dmg * (2 - (1 - armorFactor) ^ (-armor))
 

Kazeon

Hosted Project: EC
Level 34
Joined
Oct 12, 2011
Messages
3,449
sorry, If I get your question wrongly.
actually there are many statuses/attributes in my rpg, but I only use 3 variables to calculate the damage. they are attack minimum, attack maximum, and defense. Only that. My RPG is okay, I just need a damage calculation for my custom combat system. I mean custom damage event... so I can define the damage and defense as I like. As example my character uses a sword and the damage is 100(attack min)-125(attack max). The monster have "5" defense. then I need a formula to calculate the dealt damage.. Just that..
 

peq

peq

Level 6
Joined
May 13, 2007
Messages
171
The formula you are looking for is:
JASS:
GetRandomReal(minDamage,maxDamage) * (1 - (armor * 0.06) / (1 + 0.06 * armor))

:ogre_hurrhurr:

More serious answer:

First you should calculate the random damage which is between the min and max damage. If you want a uniform distribution you can just use something like GetRandomReal(minDamage,maxDamage). Most RPGs and Warcraft use a calculation based on throwing dices for this, which results in a nonuniform distribution of damage. If you want this you would need at least one further parameter besides min and max damage, e.g. the number of dices.

After you have calculated the raw damage, you can calculate the damage after armor reduction. You can just use the formula posted by WaterKnight for this and adjust the armorFactor variable. If you want a different kind of reduction you could give us some example values, so we can help you derive a formula.
 
Level 10
Joined
May 21, 2006
Messages
323
For my RPG Campaign I use damagedone = weapondamage* (random number between 0.90-1.10)
then armor calc : (EnemyArmor / ((EnemyLvL x 50) + EnemyArmor)) = ArmorCalc
then: ArmorCalc = 1 - ArmorCalc

DamageDone * ArmorCalc
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,259
It depends how you want your RPG to scale.

Final Fantasy does it by the following generally if I recall correctly...

Damage = max(1, (Attack-Defense))^2 * (1 + strength/255)

This is great if you want to force level/gear restrictions on areas. Until your attack is larger than monster defense in such a way that killing the monster takes a sensible time then you will be ineffective and lose. It also means that once your attack greatly exceends monster defense you will one shot them and you will probably take no damage due to your defense greatly exceeding their attack.

This is not the only way to balance a RPG and can end up in the nonsense situation where a huge tough boss early on is too weak to be a common enemy late game.

Diablo III uses a different approach. They used damage reduction for the players and monster health for the monsters.

Player damage taken = 1 / (1 + armor / (60 * monster level)) * 1 / (1 + all resistance / ( 6 * monster level )) * damage dealt
Monster damage taken = damage dealt * some constant reduction factor for damage type

You then scale the monster HP in a way to count armor in compared to player level and damage. Monster damage is scaled with items and level.

All resistances was a 50+ affix so they used high armor scaling early on followed by all resistance towards end game. They then threw in greatly increasing monster damage to push your gear into Inferno.
 
Status
Not open for further replies.
Top