native UnitAlive takes unit u returns boolean
scope Mystic initializer InitTrig_Mystic_Wolf
private constant function Conditions takes nothing returns boolean
return GetSpellAbilityId() == 'A000' // ID of your spell
endfunction
private function Actions takes nothing returns nothing
// Don't change these
local unit x = GetTriggerUnit()
local location l = GetSpellTargetLoc()
local player xo = GetOwningPlayer(x)
local unit y
local integer lvl = GetUnitAbilityLevel(x, 'A000')
local real rnd = GetRandomReal(1 , 100)
local integer array d
// End
// Config variables bellow.
local boolean txt = true //displays debug messeges if set to true.
local boolean order = true // if the caster should get Ordered to stop after cast.
local boolean special = true // if set to true, you will have a chance (set bellow) to summon a special wolf.
local real mps = 4. - lvl // mana per second drained.
local real mps_rnd = 4. - lvl
local real t = 1. // the delay in which the caster looses mana.
local real chance = 25. // The chance to summon a special wolf.
// Dummy Units
set d[1]='n001' // This one will be created if level==1 (as you see in [])
set d[2]='n000' // This one will be created if level==2 (as you see in [])
set d[3]='n002' // This one will be created if level==3 (as you see in [])
set d[4]='n003' // This is the RawCode of special
// End of Dummy Units
// End of Config variables.
if GetUnitState(x , UNIT_STATE_MANA) < 1 then
call Error(GetOwningPlayer(x), "Not enough mana")
call RemoveLocation(l)
set x = null
set y = null
return
else
if rnd <= chance and special == true then
set mps = mps + mps_rnd
set y = CreateUnitAtLoc (xo, d[4], l, 0.) // We have a chance of 25% to summon a special Wolf.
else
set y = CreateUnitAtLoc (xo, d[lvl], l, 0.)
endif
endif
if order == true then
call IssueImmediateOrder(x , "stop") // if order is set to true, it will order the caster to stop.
endif
loop
exitwhen UnitAlive(y) == false or GetUnitState(x , UNIT_STATE_MANA) < 1 or UnitAlive(x) == false
call SetUnitState(x , UNIT_STATE_MANA , GetUnitState(x, UNIT_STATE_MANA) - mps) // we set the mana of the caster to his mana - variable mps.
call TriggerSleepAction(t) // delay action, deafult 1.
endloop
if txt == true then
if UnitAlive(y) == false then
call DisplayTimedTextToPlayer(Player(0), 0, 0, 2.5 , "Wolf has died.")
elseif UnitAlive(x) == false then
call DisplayTimedTextToPlayer(Player(0), 0, 0, 2.5 ,"The caster has died, therefore the wolf dies.")
elseif GetUnitState(x , UNIT_STATE_MANA) < 1 then
call DisplayTimedTextToPlayer(Player(0), 0, 0, 2.5 ,"The caster's mana has reached 0, the wolf dies.")
endif
endif
call KillUnit(y) // we kill our unit.
// we remove leaks
call RemoveLocation(l)
set x = null
set y = null
endfunction
//===========================================================================
private function InitTrig_Mystic_Wolf takes nothing returns nothing
local trigger t = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( t, EVENT_PLAYER_UNIT_SPELL_EFFECT )
call TriggerAddCondition( t, Condition( function Conditions ) )
call TriggerAddAction( t, function Actions )
endfunction
endscope