Advertisement
Guest User

Untitled

a guest
Aug 30th, 2015
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.87 KB | None | 0 0
  1. function DeathPact( event )
  2.     local caster = event.caster
  3.     local ability = event.ability
  4.     local duration = ability:GetSpecialValueFor( "duration")
  5.     local radius = ability:GetSpecialValueFor("rallying_cry_aura_radius")
  6.  
  7.     -- Find Units Around Caster
  8.     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)
  9.  
  10.  
  11.     --Find every unit and apply the modifier to it
  12.     for i, unit in ipairs(unitsAround) do
  13.         if not unit:HasModifier("modifier_death_pact_health") then
  14.             -- Health Gain
  15.             local lifegain = ability:GetSpecialValueFor("lifegain") * 0.01
  16.             local unit_health = unit:GetHealth()
  17.             local unit_maxhealth = unit:GetMaxHealth()
  18.  
  19.  
  20.             local health_gain = math.floor(unit_health * lifegain) --current health * .15 = 15%
  21.             local health_gain_percent = health_gain + unit_health -- current health + 15%
  22.  
  23.             local health_max_percent  = math.floor(unit_maxhealth * lifegain) --maxhp * 0.15
  24.             local health_max = math.floor(health_max_percent + unit_maxhealth) --maxhp + 15%
  25.  
  26.             unit.OldHealth = unit:GetHealth() --Save current health for timer
  27.             unit.OldMaxHealth = unit:GetMaxHealth()--Save current max health for timer
  28.             unit.OldBaseMaxHealth = unit:GetBaseMaxHealth()--Save current max health for timer
  29.  
  30.             local health_modifier = "modifier_death_pact_health" --Modifier to apply buff
  31.             ability:ApplyDataDrivenModifier(caster, unit, health_modifier, { duration = duration })
  32.  
  33.             local health_modifier2 = "modifier_ally_health" --Modifier to display buff to both caster and allies
  34.             ability:ApplyDataDrivenModifier(caster, unit, health_modifier2, { duration = duration })
  35.             unit:SetModifierStackCount( health_modifier, ability, health_max_percent )
  36.  
  37.             caster:RemoveModifierByName(health_modifier2) --Remove second modifier from caster to avoid double icons
  38.  
  39.             print(unit_health)
  40.  
  41.             unit:SetBaseMaxHealth(health_max)
  42.             unit:SetMaxHealth(health_gain_percent)
  43.             unit:SetHealth(health_gain_percent)
  44.  
  45.             local BuffedHP = unit:GetHealth()
  46.             print(BuffedHP)
  47.             print(unit)
  48.  
  49.  
  50.             Timers:CreateTimer(duration, function() --After the buff's duration do the following:
  51.                 local damagetaken = unit:GetHealth()
  52.                 local lifelost = BuffedHP - damagetaken -- Subtract damage taken from buffed HP
  53.                 unit:SetMaxHealth(unit.OldMaxHealth) --Set max health to what it normally was
  54.                 unit:SetBaseMaxHealth(unit.OldBaseMaxHealth) --Set max health to what it normally was
  55.                     if lifelost <= 0 then   --Check if there was any damage taken
  56.                     unit:SetHealth(unit.OldHealth) -- Apply health back to normal
  57.                     print("You did not lose health")
  58.                     else
  59.                     unit:SetHealth(unit.OldHealth - lifelost) -- Subtract damage taken from normal HP and apply.
  60.                     print("You lost: "..lifelost)
  61.                     end
  62.             end)
  63.         end
  64.     end
  65. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement