/***********************************************************************/
/************** Configurables **************/
/***********************************************************************/
globals
integer = SpartBRage_AbilityId = 'A000' // The Ability Id
real SpartBRage_Duration = 1.25 // This will be multiplied by ability level
real SpartBRage_Radius = 350 // Radius of effect
string SpartBRage_Effect = "Abilities\\Weapons\\LavaSpawnMissile\\LavaSpawnBirthMissile.mdl" // The model string
/***********************************************************************/
/************** From now on, don't touch if you're not **************/
/************** sure. In any case, make a backup **************/
/************** **************/
/************** Feel free to delete comments **************/
/***********************************************************************/
hashtable SpartBRage_Hash = InitHashtable()
group SpartBRage_Group = CreateGroup()
endglobals
// Trigger Conditions
function Trig_SpartBRage_Cast_Conditions takes nothing returns boolean
return GetSpellAbilityId() == SpartBRage_AbilityId
endfunction
// Timer Actions
function SpartBRage_TimerActions takes nothing returns nothing
local timer t = GetExpiredTimer()
local integer timerId = GetHandleId(t)
local hashtable h = SpartBRage_Hash
local unit u = LoadUnitHandle(h, timerId, 0)
local effect e = LoadEffectHandle(h, timerId, 1)
call DestroyEffect(e) // Destroy Effect
call GroupRemoveUnit(SpartBRage_Group, u) // Remove Unit from Group
call FlushChildHashtable(h, timerId) // Flush Timer Hash Data
call FlushChildHashtable(h, GetHandleId(u)) // Flush Unit Hash Data
// Check if group is empty
set bj_groupCountUnits = 0
call ForGroup(SpartBRage_Group, function CountUnitsInGroupEnum)
if bj_groupCountUnits == 0 then
call DisableTrigger(gg_trg_SpartBRage_Prevent) // Disable trigger
endif
// Clearing leaks
set t = null
set u = null
set e = null
endfunction
// Trigger Actions
function Trig_SpartBRage_Cast_Actions takes nothing returns nothing
local unit u = GetTriggerUnit()
local group g1 = bj_lastCreatedGroup
local timer t
local integer timerId
local integer unitId
local unit fog
local real duration = SpartBRage_Duration * GetUnitAbilityLevel(u, SpartBRage_AbilityId) // This is the duration formula.
local effect e
local hashtable h = SpartBRage_Hash
local group g2 = SpartBRage_Group
// Enum units around caster in a temp group (g1)
call GroupEnumUnitsInRange(g1, GetUnitX(u), GetUnitY(u), SpartBRage_Radius, null)
loop
set fog = FirstOfGroup(g1)
set unitId = GetHandleId(fog)
exitwhen fog == null
// Check if they're enemies and they're alive
if IsUnitEnemy(fog, GetTriggerPlayer()) == true and GetWidgetLife(fog) > 0 then
// Check if the unit is already in the group (under effect of Berserker)
if IsUnitInGroup(fog, g2) == true then
set t = LoadTimerHandle(h, unitId, 1)
set timerId = GetHandleId(t)
set e = LoadEffectHandle(h, timerId, 1)
call DestroyEffect(e) // Destroy Effect
call PauseTimer(t) // Pause timer
call DestroyTimer(t) // Destroy Timer
call GroupRemoveUnit(g2, fog) // Remove Unit from group
call FlushChildHashtable(h, timerId) // Flush Timer Hash Data
call FlushChildHashtable(h, unitId) // Flush Unit Hash Data
endif
set t = CreateTimer() // Create a timer for this unit
set timerId = GetHandleId(t)
call TimerStart(t, duration, false, function SpartBRage_TimerActions) // Start the Timer
set e = AddSpecialEffectTarget(SpartBRage_Effect, fog, "chest") // Add the Effect
call SaveUnitHandle(h, timerId, 0, fog) // Save Unit in Timer
call SaveEffectHandle(h, timerId, 1, e) // Save Effect in Timer
call SaveUnitHandle(h, unitId, 0, u) // Save Target in Unit
call SaveTimerHandle(h, unitId, 1, t) // Save Timer in Unit
call IssueTargetOrder(fog, "attack", u) // Order unit to attack
call GroupAddUnit(g2, fog) // Add the unit to the group of units under berserk effect
endif
call GroupRemoveUnit(g1, fog) // Remove the unit from the temp group (g1)
endloop
call EnableTrigger(gg_trg_SpartBRage_Prevent) // Turn on the Trigger that prevents the unit from doing other stuff
// Clearing leaks
set u = null
set g1 = null
set g2 = null
set t = null
set fog = null
set e = null
set h = null
endfunction
//===========================================================================
function InitTrig_SpartBRage_Cast takes nothing returns nothing
set gg_trg_SpartBRage_Cast = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_SpartBRage_Cast, EVENT_PLAYER_UNIT_SPELL_EFFECT )
call TriggerAddCondition( gg_trg_SpartBRage_Cast, Condition( function Trig_SpartBRage_Cast_Conditions ) )
call TriggerAddAction( gg_trg_SpartBRage_Cast, function Trig_SpartBRage_Cast_Actions )
endfunction