function UnitDeadCheck takes unit loc_unit01 returns boolean
return GetUnitTypeId(udg_Caster)<1 or IsUnitType(loc_unit01,UNIT_TYPE_DEAD)==true
endfunction
function PeriodicEventAction takes nothing returns boolean
local trigger this_trigger=GetTriggeringTrigger()
local integer trigger_id=GetHandleId(this_trigger)
call SaveInteger(udg_hashtable001,(GetHandleId(((LoadUnitHandle(udg_hashtable001,(trigger_id),(14)))))),(((LoadInteger(udg_hashtable001,(trigger_id),(33))))),(2))
call FlushChildHashtable(udg_hashtable001,(trigger_id))
call DisableTrigger(this_trigger)
set this_trigger=null
return false
endfunction
function CreatePeriodicEvent takes group heal_units,integer number,real duration returns nothing
local trigger periodic_trigger=CreateTrigger()
call TriggerAddCondition(periodic_trigger,Condition(function PeriodicEventAction))
call TriggerRegisterTimerEvent(periodic_trigger,duration,true)
call SaveInteger(udg_hashtable001,(GetHandleId(heal_units)),(number),(1))
call SaveInteger(udg_hashtable001,(GetHandleId(periodic_trigger)),(33),(number))
set periodic_trigger=null
endfunction
function funcdrain_setup takes nothing returns boolean
set udg_Heal_amount[0] = 0 // was wondering if i can set this to null
set udg_Heal_amount[1] = 19.00
set udg_Heal_amount[2] = 30.00
set udg_Heal_amount[3] = 41.00
set udg_Heal_amount[4] = 52.00
return true
endfunction
function Spirit_Drain_Con takes nothing returns boolean
if ( GetUnitTypeId(GetSummonedUnit()) == 'o001') then // ward lvl 1
set udg_Unit_pres01 = 1
elseif ( GetUnitTypeId(GetSummonedUnit()) == 'o002' ) then // ward lvl 2
set udg_Unit_pres01 = 2
elseif ( GetUnitTypeId(GetSummonedUnit()) == 'o003' ) then // ward lvl 3
set udg_Unit_pres01 = 3
elseif ( GetUnitTypeId(GetSummonedUnit()) == 'o000' ) then // ward lvl 4
set udg_Unit_pres01 = 4
else
set udg_Unit_pres01 = 0
endif
return false
endfunction
function funcally_drain takes nothing returns boolean
return ( IsUnitAlly(GetFilterUnit(), GetOwningPlayer(udg_Caster)) == true ) and (IsUnitType(GetFilterUnit(),UNIT_TYPE_STRUCTURE)==false ) and (UnitDeadCheck(GetFilterUnit())==false )//finds allies of caster
endfunction
function funcEnum_drain takes nothing returns nothing
local unit loun01x
call GroupRemoveUnitSimple( udg_Caster, udg_heal_units ) // removes caster from unit group
call GroupRemoveUnitSimple( udg_Summon, udg_heal_units )
call CreateUnit(ForcePickRandomPlayer(GetPlayersEnemies(GetOwningPlayer(udg_Caster))),'u000',0,0,0)
set loun01x = GetLastCreatedUnit()
loop
exitwhen RectContainsUnit(GetPlayableMapRect(), udg_Dummy_4) == false
call SetUnitState(GetEnumUnit(),UNIT_STATE_LIFE,( GetUnitStateSwap(UNIT_STATE_LIFE, GetEnumUnit()) + udg_Heal_amount[udg_Unit_pres01] ))
call SetUnitState(udg_Caster ,UNIT_STATE_LIFE,( GetUnitStateSwap(UNIT_STATE_LIFE, udg_Caster ) - udg_Heal_amount[udg_Unit_pres01] ))
if GetUnitState(udg_Caster,UNIT_STATE_LIFE)<2 then
call UnitRemoveBuffs (udg_Caster,true,true)
call UnitDamageTargetBJ( loun01x, udg_Caster, 1000000000.00, ATTACK_TYPE_HERO, DAMAGE_TYPE_UNKNOWN )
endif //deals magical damage
call CreatePeriodicEvent(udg_heal_units,4258,8)
endloop
endfunction
function spirit_drain_act takes nothing returns nothing
local integer loc_integer01=1
local unit summon=GetSummonedUnit()
local group heal_units = CreateGroup()
set udg_Summon = GetSummonedUnit()
// beginning of code for animation
call CreateNUnitsAtLocFacingLocBJ( 1, 'H001', GetOwningPlayer(udg_Caster), GetUnitLoc(udg_Caster), GetUnitLoc(summon) )
set udg_Dummy_4 = GetLastCreatedUnit()
call ConditionalTriggerExecute( gg_trg_Drain_Visual_Animation ) // conjures the animation (in another script)
call UnitApplyTimedLifeBJ( 8.00, 'BTLF', udg_Dummy_4 ) // kills the dummy unit
call GroupEnumUnitsInRange(udg_heal_units,GetUnitX(summon),GetUnitY(summon),775,Condition(function funcally_drain))
call ForGroup( udg_heal_units, function funcEnum_drain )
call DestroyGroup(heal_units)
set summon=null
set heal_units=null
endfunction
function InitTrig_Drain_lvl_1 takes nothing returns nothing
set gg_trg_Drain_lvl_1 = CreateTrigger( )
set udg_Caster = GetSummoningUnit()
call TriggerAddCondition( gg_trg_Drain_lvl_1, Condition( function Spirit_Drain_Con ) )
call TriggerRegisterPlayerUnitEventSimple( gg_trg_Drain_lvl_1, GetOwningPlayer(udg_Caster), EVENT_PLAYER_UNIT_SUMMON )
call funcdrain_setup()
call TriggerRegisterTimerExpireEventBJ( gg_trg_Drain_lvl_1, udg_Duration01 )
call TriggerAddAction( gg_trg_Drain_lvl_1, function spirit_drain_act )
endfunction