function Trig_Improved_Mana_drain_Conditions takes nothing returns boolean
return GetSpellAbilityId() == 'A000' //if casted spell is 'A000' then whole spell will work
endfunction
function firstft takes nothing returns boolean
return GetHeroInt(GetTriggerUnit(), true) > GetHeroInt(GetSpellTargetUnit(), true)// if hero's int bigger then spell target's int then he will drain mana
endfunction
function secondft takes nothing returns boolean
return ( GetUnitState(GetSpellTargetUnit(), UNIT_STATE_MANA) <= I2R(( ( 2 + GetUnitAbilityLevel(GetTriggerUnit(), GetSpellAbilityId()) ) * GetHeroInt(GetTriggerUnit(), true) - GetHeroInt(GetSpellTargetUnit(), true) ) ))//this condition is to prevent over damaging target or setting his mana to negative value and crashing Wc3
endfunction
function Trig_Improved_Mana_drain_Actions takes nothing returns nothing
local integer int1 = ( 2 + GetUnitAbilityLevel(GetTriggerUnit(), GetSpellAbilityId()) )//this is multiplier of int(caster) - int(target)
local location loc1 = GetUnitLoc(GetTriggerUnit())//set locations
local location loc2 = GetUnitLoc(GetSpellTargetUnit())
local integer int2 = ( int1 * ( GetHeroInt(GetTriggerUnit(), true) - GetHeroInt(GetSpellTargetUnit(), true) ) )// this is int(caster) - int(target) (Change GetHero/Int/ to /Str/ or /Agi/ if u need)
local real Dmg = 32.00 + ( 32.00 * I2R(GetUnitAbilityLevel(GetTriggerUnit(), GetSpellAbilityId())) )//this is DMG if firstft is false and hero TP to target
local lightning liEf
//setting locals for Lightning effect
local real x1 = GetLocationX(loc1)
local real y1 = GetLocationY(loc1)
local real z1 = (GetLocationZ(loc1) + 50)
local real x2 = GetUnitX(GetSpellTargetUnit())
local real y2 = GetUnitY(GetSpellTargetUnit())
local real z2 = (GetLocationZ(loc2) + 50)
//end setting locals
set liEf = AddLightningEx( "MBUR" , false , x1 , y1 , z1 , x2 , y2 , z2)//creating lighning effect
call DestroyEffect( AddSpecialEffectTarget( "Abilities\\Spells\\Undead\\Possession\\PossessionMissile.mdl", GetSpellTargetUnit(), "origin" ) )//eye candy
if ( secondft() ) then
call UnitDamageTarget( GetTriggerUnit(), GetSpellTargetUnit(), (GetUnitState(GetSpellTargetUnit(), UNIT_STATE_MANA) + 100),true,false, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_NORMAL,WEAPON_TYPE_WHOKNOWS )//damage target
call SetWidgetLife( GetTriggerUnit(), ( GetUnitState(GetTriggerUnit(), UNIT_STATE_LIFE) + ( GetUnitState(GetSpellTargetUnit(), UNIT_STATE_MANA) / 3.00 ) ) )//heal caster
call SetUnitState( GetTriggerUnit(),UNIT_STATE_MANA, ( GetUnitState(GetTriggerUnit(), UNIT_STATE_MANA) + ( GetUnitState(GetSpellTargetUnit(), UNIT_STATE_MANA) / 3.00 ) ) )//adding mana to caster
call SetUnitState( GetSpellTargetUnit(),UNIT_STATE_MANA, 0 )//removing mana
call CastStun(2,GetSpellTargetUnit(),GetTriggerUnit())//stuning target for 2 sec
else
if ( firstft() ) then
call UnitDamageTarget( GetTriggerUnit(), GetSpellTargetUnit(), I2R(int2), true, false, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_NORMAL,WEAPON_TYPE_WHOKNOWS )//damaging target
call SetUnitState( GetSpellTargetUnit(),UNIT_STATE_MANA, ( GetUnitState(GetSpellTargetUnit(), UNIT_STATE_MANA) - I2R(int2) ))//taking of his mana
call SetUnitState( GetTriggerUnit(),UNIT_STATE_MANA, ( GetUnitState(GetTriggerUnit(), UNIT_STATE_MANA) + (I2R(int2) /3 )))//give mana to caster
call SetWidgetLife( GetTriggerUnit(), ( GetUnitState(GetTriggerUnit(), UNIT_STATE_LIFE) + (I2R(int2) / 3.00 ) ))//heal caster
else
call SetUnitPosition( GetTriggerUnit(), x2,y2 )//TP unit
call DestroyEffect(AddSpecialEffectTarget( "Abilities\\Spells\\NightElf\\Blink\\BlinkCaster.mdl", GetTriggerUnit(), "origin" ))//eye candy
call SetUnitState( GetSpellTargetUnit(), UNIT_STATE_MANA ,( GetUnitState(GetSpellTargetUnit(), UNIT_STATE_MANA) - Dmg))//taking of mana
call UnitDamageTarget( GetTriggerUnit(), GetSpellTargetUnit(), Dmg,true,false, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_NORMAL,WEAPON_TYPE_WHOKNOWS )//damaging target
endif
endif
//clearing locals to remove leaks
call RemoveLocation(loc1)
call RemoveLocation(loc2)
call PolledWait2(0.34)//waiting
call DestroyLightning(liEf)//destroing lightning
set loc1 = null
set loc2 = null
set liEf = null
endfunction
//===========================================================================
function InitTrig_Improved_Mana_drain takes nothing returns nothing
local trigger gg_trg_Improved_Mana_drain = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_Improved_Mana_drain, EVENT_PLAYER_UNIT_SPELL_EFFECT )
call TriggerAddCondition( gg_trg_Improved_Mana_drain, Condition( function Trig_Improved_Mana_drain_Conditions ) )
call TriggerAddAction( gg_trg_Improved_Mana_drain, function Trig_Improved_Mana_drain_Actions )
set gg_trg_Improved_Mana_drain = null
endfunction