Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function DeathPact( event )
- local caster = event.caster
- local ability = event.ability
- local duration = ability:GetSpecialValueFor( "duration")
- local radius = ability:GetSpecialValueFor("rallying_cry_aura_radius")
- -- Find Units Around Caster
- local unitsAround = FindUnitsInRadius(caster:GetTeam(), caster:GetAbsOrigin(), nil, radius, DOTA_UNIT_TARGET_TEAM_FRIENDLY, DOTA_UNIT_TARGET_HERO + DOTA_UNIT_TARGET_BASIC, DOTA_UNIT_TARGET_FLAG_NONE, FIND_ANY_ORDER, false)
- --Find every unit and apply the modifier to it
- for i, unit in ipairs(unitsAround) do
- if not unit:HasModifier("modifier_death_pact_health") then
- -- Health Gain
- local lifegain = ability:GetSpecialValueFor("lifegain") * 0.01
- local unit_health = unit:GetHealth()
- local unit_maxhealth = unit:GetMaxHealth()
- local health_gain = math.floor(unit_health * lifegain) --current health * .15 = 15%
- local health_gain_percent = health_gain + unit_health -- current health + 15%
- local health_max_percent = math.floor(unit_maxhealth * lifegain) --maxhp * 0.15
- local health_max = math.floor(health_max_percent + unit_maxhealth) --maxhp + 15%
- unit.OldHealth = unit:GetHealth() --Save current health for timer
- unit.OldMaxHealth = unit:GetMaxHealth()--Save current max health for timer
- unit.OldBaseMaxHealth = unit:GetBaseMaxHealth()--Save current max health for timer
- local health_modifier = "modifier_death_pact_health" --Modifier to apply buff
- ability:ApplyDataDrivenModifier(caster, unit, health_modifier, { duration = duration })
- local health_modifier2 = "modifier_ally_health" --Modifier to display buff to both caster and allies
- ability:ApplyDataDrivenModifier(caster, unit, health_modifier2, { duration = duration })
- unit:SetModifierStackCount( health_modifier, ability, health_max_percent )
- caster:RemoveModifierByName(health_modifier2) --Remove second modifier from caster to avoid double icons
- print(unit_health)
- unit:SetBaseMaxHealth(health_max)
- unit:SetMaxHealth(health_gain_percent)
- unit:SetHealth(health_gain_percent)
- local BuffedHP = unit:GetHealth()
- print(BuffedHP)
- print(unit)
- Timers:CreateTimer(duration, function() --After the buff's duration do the following:
- local damagetaken = unit:GetHealth()
- local lifelost = BuffedHP - damagetaken -- Subtract damage taken from buffed HP
- unit:SetMaxHealth(unit.OldMaxHealth) --Set max health to what it normally was
- unit:SetBaseMaxHealth(unit.OldBaseMaxHealth) --Set max health to what it normally was
- if lifelost <= 0 then --Check if there was any damage taken
- unit:SetHealth(unit.OldHealth) -- Apply health back to normal
- print("You did not lose health")
- else
- unit:SetHealth(unit.OldHealth - lifelost) -- Subtract damage taken from normal HP and apply.
- print("You lost: "..lifelost)
- end
- end)
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement