The Forums Are Now Closed!

The content will remain as a historical reference, thank you.

Improving abilities damage

By on May 5, 2012 6:45:05 AM from Demigod Forums Demigod Forums

W0jtek0123

Join Date 05/2012
0

Hello 

Can anyone explain me how to add bonus damage to abilitie. Like DamageAmt = 400 + here weapon damage of your hero (full damage or percentage). Im trying to combine hero damage and damage of abilties

For example:

AbilityBlueprint {
Name = 'HDemonSpineAttack01',
DisplayName = '<LOC ABILITY_DA_0008>Spine Attack I',
Description = '<LOC ABILITY_DA_0009>Demon Assassin throws a deadly barb from his tail, dealing [GetDamage] damage.',
AbilityType = 'TargetedUnit',
TargetAlliance = 'Enemy',
TargetCategory = 'ALLUNITS - UNTARGETABLE',
TargetingMethod = 'HOSTILETARGETED',
EnergyCost = 300,
RangeMax = 20,
Cooldown = 15,
DamageAmt = 400 + (What should I type in here to get bounus damage from hero dmg) ,
DamageType = 'Spell',
UISlot = 2,
HotKey = '2',
CastingTime = 0.3,
CastAction = 'SpineAttack',
FollowThroughTime = 0.1,
GetDamage = function(self) return math.floor( self.DamageAmt ) end,
OnStartAbility = function(self, unit, params)
ForkThread(SpineAttack, self, unit, params)
end,
Icon = '/DGDemonAssassin/DA_SpineAttack',

Locked Post 1 Reply
Search this post
Subscription Options


Reason for Karma (Optional)
Successfully updated karma reason!
May 24, 2012 4:33:17 PM from Demigod Forums Demigod Forums

There is no direct way to do what you're trying to do, as the ability blueprints are not meant to be modified mid-game (as that would affect every demigod using that ability regardless of which team they're on, and would not be reflected in the UI).

There are several workarounds you can use, from directly overriding the function that the ability calls in OnStartAbility, or non-destructively by hooking OnStartAbility and passing the original call a copy of the ability blueprint with a modified damage value, e.g.:

Code: c++
  1. --Non-destructive ability damage hook--Save a copy of the existing OnStartAbility
  2. local prevOnStartAbility = Ability.HDemonSpineAttack01.OnStartAbility
  3. Ability.HDemonSpineAttack01.OnStartAbility = function(self, unit, params)
  4.     --Make a copy of the ability blueprint table that's passed to the function when the ability is used
  5.     local bpCopy = table.copy(self)
  6.     --Modify damage amount in this blueprint copy, for example, adding the unit's DamageRating
  7.     bpCopy.DamageAmt = bpCopy.DamageAmt + unit.Sync.DamageRating
  8.     --Call the original OnStartAbility with the copied blueprint instead of the original ability blueprint
  9.     prevOnStartAbility(bpCopy, unit, params)
  10. end

Note that this will add a tiny bit of overhead due to the table copy operation - this is completely negligible in this case, since this will only happen any time an ability is called (not that often in sim terms), and there are already dozens of table copies happening per tick, but it's worth mentioning that you'd want to use a more efficient method for something other than an ability hook.

This also won't be reflected in the UI, since it does nothing to the original blueprint table (nevermind each player's UI copy, which is separate and untouchable by the sim code).  There is a hack that you can use to change the UI display, but you need to make sure whatever value you're adding/multiplying the damage by is available in the unit's Sync on the sim side:

Code: c++
  1. --Modify the GetDamage function on the UI side to snag updated damage info from Synclocal Spine01DamageAdd = 0
  2. Ability.HDemonSpineAttack01.GetDamage = function(self)
  3.     --Try to fetch damage bonus from sync
  4.     local focusHero, syncData = import('/lua/ui/game/ingameui.lua').GetFocusArmyHero()
  5.     if focusHero and not focusHero:IsDead() then
  6.         syncData = import('/lua/common/commonutils.lua').GetSyncData(focusHero)
  7.     end
  8.     --Add the value from the sync (or a cached value, if the demigod is currently dead)
  9.     if syncData and syncData.DamageRating then
  10.         Spine01DamageAdd = syncData.DamageRating
  11.     end
  12.     return math.floor(self.DamageAmt + Spine01DamageAdd)
  13. end

This creates a cached upvalue (Spine01DamageAdd) that the UI can add to the original ability damage even if the sync data is unavailable (e.g. currently dead).

 

If it isn't clear, you'd need to do both of these things for every single ability you want to affect - there is no catch-all method for applying something like this to every ability, although if you'd like I can show you how to use a loop to quickly apply it to a series of abilities (e.g. spine attack I through IV).

Also, for the record, I would highly question the balance impact of adding DamageRating to ability damage, and would suggest you find a better way to increase damage (making sure you set that amount as a Sync value on the unit, so both UI and sim can access it).

 

If you want to use these code snippets, make sure you quote the post and copy the contents of the [ code ][ /code ] tags, otherwise you'll get a bunch of extra junk in it and it won't work (this forum's code tags are terrible).

Reason for Karma (Optional)
Successfully updated karma reason!
Stardock Forums v1.0.0.0    #101114  walnut1   Server Load Time: 00:00:00.0000078   Page Render Time: