- Joined
- Mar 10, 2009
- Messages
- 5,016
JASS:
/*
=====DamageCalculator v1.1
=====By Mckill2009
I don't know if this site has this snippet already but I'm posting it anyway
to get feedbacks, basically this is a small code that can get the random
damage from a certain unit based on what is written in the object editor.
Take note that the damage return DOES NOT mean the EXACT damage given by
the unit, therefore this does not affect the armour of the attacked unit.
The returned damage computation are based on; (see object editor)
Primary Attribute (for hero only)
Damage Base
Damage Number Of Dice
Damage Sides Per Die
API:
static method getHeroDC takes integer mainattribute, real damBase, real damDice, real damDie returns real
- local real dam = DamageCalculator.getHeroDC(1,2,3,4)
- mainattribute (the PRIMARY ATTRIBUTE of the hero)
- damBase (the DAMAGE BASE)
- damDice (the DAMAGE NUMBER OF DICE)
- damDie (the DAMAGE SIDES PER DIE)
static method getUnitDC takes real damBase, real damDice, real damDie returns real
- local real dam = DamageCalculator.getUnitDC(1,2,3)
- damBase (the DAMAGE BASE)
- damDice (the DAMAGE NUMBER OF DICE)
- damDie (the DAMAGE SIDES PER DIE)
CREDITS:
- Bribe (for name change)
- Magtheridon96 (for shortening the code even more)
- KnnO (for other suggestions)
*/
library DamageCalculator
struct DamageCalculator extends array
static method getHeroDC takes integer mainattribute, real damBase, real damDice, real damDie returns real
return GetRandomReal((mainattribute+damDice)+damBase, (mainattribute+(damDice*damDie))+damBase)
endmethod
static method getUnitDC takes real damBase, real damDice, real damDie returns real
return GetRandomReal(damBase+damDice, damBase+(damDice*damDie))
endmethod
endstruct
endlibrary
How it works?
-
DC Hero
-
Events
- Unit - A unit Is attacked
-
Conditions
- (Unit-type of (Attacking unit)) Equal to Blood Mage
-
Actions
- Custom script: local real dam = DamageCalculator.getHeroDC(GetHeroInt(GetAttacker(),false), 0, 2, 4)
- Custom script: call BJDebugMsg(R2S(dam))
-
Events
-
DC Unit
-
Events
- Unit - A unit Is attacked
-
Conditions
- (Unit-type of (Attacking unit)) Equal to Knight
-
Actions
- Custom script: local real dam = DamageCalculator.getUnitDC(25, 2, 5)
- Custom script: call BJDebugMsg(R2S(dam))
-
Events
v1.1
- Integer returned replaced by reals
- Code reduced
Last edited: