scope RaiseDead initializer Init
globals
private constant integer RAISE_DEAD = 'A000' //rawcode of your raise dead ability
private constant integer VAMPIRE = 'H000' //rawcode of the vampire
private group g = CreateGroup()
private unit cast
endglobals
private function IsDeadFilter takes nothing returns boolean
return GetWidgetLife(GetFilterUnit())<=0.405 //check if they are dead
endfunction
private function onCast takes nothing returns boolean
local unit fog
local unit dum
local integer level
local integer i = 0
if GetSpellAbilityId()==RAISE_DEAD then //check if it is the raise dead spell
set level = GetHeroInt(GetTriggerUnit(),true)/40 //this will be the level of the unit created
call GroupEnumUnitsInRange(g,GetUnitX(GetTriggerUnit()),GetUnitY(GetTriggerUnit()),300,Condition(function IsDeadFilter))
loop
exitwhen i == 2 //we only need two units
set fog = FirstOfGroup(g)
if fog != null then
set dum = CreateUnit(GetTriggerPlayer(),VAMPIRE,GetUnitX(fog),GetUnitY(fog),GetUnitFacing(fog)) //create the vampire
call UnitApplyTimedLife(dum,'BTLF',GetRandomReal(1,30)) //random lifetime between 1 and 30
call SetHeroLevel(dum,level,false)
call ShowUnit(fog,false) //remove the old corpse
call GroupRemoveUnit(g,fog)
endif
set i = i + 1
endloop
set fog = null
set dum = null
endif
return false
endfunction
private function Init takes nothing returns nothing
local trigger t = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(t,EVENT_PLAYER_UNIT_SPELL_EFFECT)
call TriggerAddCondition(t,Condition(function onCast))
endfunction
endscope