I'm trying to modify my spell slighty so that every time the caster is attacked the remaining duration of the spell is reduced by 1.00 second while the attacker is damaged and stunned for a short duration.
I initially planned to do this by adding TriggerRegisterAnyUnitEventBJ(trig, EVENT_PLAYER_UNIT_ATTACKED) to the SH_OL_periodic function and then do something like:
However using RegisterAnyUnitEvent with a dynamic trigger is apparently "crazy" (read: http://www.wc3c.net/showthread.php?t=103738)
How should I approach this?
This is the entire code in its current state:
I initially planned to do this by adding TriggerRegisterAnyUnitEventBJ(trig, EVENT_PLAYER_UNIT_ATTACKED) to the SH_OL_periodic function and then do something like:
JASS:
if GetAttacker() != null then
set durationcur = durationcur + 0.8
// stun and damage here
endif
How should I approach this?
This is the entire code in its current state:
JASS:
//===========================================================================
//CONSTANTS:
//===========================================================================
constant function SH_OL_spellid takes nothing returns integer
return 'A005'
endfunction
//===========================================================================
//CONFIGURABLES:
//===========================================================================
function SH_OL_duration takes nothing returns real
return 12.
endfunction
function SH_OL_stats takes integer level returns integer
return level * 10
endfunction
//===========================================================================
//ACTIONS:
//===========================================================================
function SH_OL_getlevel takes unit caster returns integer
return GetUnitAbilityLevel(caster, SH_OL_spellid())
endfunction
function SH_OL_periodic takes nothing returns nothing
local trigger trig = GetTriggeringTrigger()
local integer trigid = GetHandleId(trig)
local unit caster = LoadUnitHandle(udg_SH_hashtable, trigid, 1)
local real durationcur = LoadReal(udg_SH_hashtable, trigid, 2)
local real durationmax = LoadReal(udg_SH_hashtable, trigid, 3)
local integer stats
if durationcur < durationmax and IsUnitType(caster, UNIT_TYPE_DEAD) == false then
set durationcur = durationcur + 0.2
call SaveReal(udg_SH_hashtable, trigid, 2, durationcur)
else
set stats = LoadInteger(udg_SH_hashtable, trigid, 4)
call SetHeroInt(caster, (GetHeroInt(caster, false)) - stats, true)
call SetHeroAgi(caster, (GetHeroAgi(caster, false)) - stats, true)
call DestroyEffect(LoadEffectHandle(udg_SH_hashtable, trigid, 5))
call FlushChildHashtable(udg_SH_hashtable, trigid)
call DisableTrigger(trig)
call TriggerRemoveAction(trig, LoadTriggerActionHandle(udg_SH_hashtable, trigid, 0))
call DestroyTrigger(GetTriggeringTrigger())
endif
set trig = null
set caster = null
endfunction
function SH_OL_conditions takes nothing returns nothing
local trigger trig
local integer trigid
local unit caster
local integer stats
local effect sfx
if GetSpellAbilityId() == SH_OL_spellid() then
set caster = GetTriggerUnit()
set stats = SH_OL_stats(SH_OL_getlevel(caster))
set sfx = AddSpecialEffectTarget("Abilities\\Spells\\Orc\\Purge\\PurgeBuffTarget.mdl", caster, "origin")
call SetHeroInt(caster, (GetHeroInt(caster, false)) + stats, true)
call SetHeroAgi(caster, (GetHeroAgi(caster, false)) + stats, true)
set trig = CreateTrigger()
set trigid = GetHandleId (trig)
call TriggerRegisterTimerEvent(trig, 0.2, true)
call SaveTriggerActionHandle(udg_SH_hashtable , trigid, 0, TriggerAddAction(trig, function SH_OL_periodic))
call SaveUnitHandle(udg_SH_hashtable, trigid, 1, caster)
call SaveReal(udg_SH_hashtable, trigid, 2, 0.)
call SaveReal(udg_SH_hashtable, trigid, 3, SH_OL_duration())
call SaveInteger(udg_SH_hashtable, trigid, 4, stats)
call SaveEffectHandle(udg_SH_hashtable, trigid, 5, sfx)
set trig = null
set caster = null
set sfx = null
endif
endfunction
//===========================================================================
function InitTrig_Overload takes nothing returns nothing
local trigger SH_OL = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(SH_OL, EVENT_PLAYER_UNIT_SPELL_EFFECT)
call TriggerAddCondition(SH_OL, Condition(function SH_OL_conditions))
set SH_OL = null
endfunction