- Joined
- May 4, 2007
- Messages
- 2,260
And, for good coding, I am using it on the Init function, where all triggers should be set.
However I have a problem ... this event takes a unit !!!
I don't see a way to fix this without using dynamic triggers, but I know they are evil !
Please some one help me find a solution !
[jass=full code]
//Uses TimerUtils so far
scope LightShield initializer Init
globals
private constant integer AID = 'A001'
endglobals
private constant function Duration takes integer level returns real
return level * 20.
endfunction
private constant function DamageAbsorbed takes integer level returns real
return level * 100.
endfunction
//===========================================================================
private struct MyStruct
unit caster
unit target
integer level
timer dur
static method create takes unit caster, unit target, integer level returns MyStruct
local MyStruct data = MyStruct.allocate()
set data.caster = caster
set data.level = level
set data.target = target
set data.dur = NewTimer()
return data
endmethod
method onDestroy takes nothing returns nothing
call ReleaseTimer(.dur)
endmethod
endstruct
//===========================================================================
private function onDamage takes nothing returns boolean
return true
endfunction
//===========================================================================
private function PreventDamage takes nothing returns nothing
endfunction
//===========================================================================
private function Conditions takes nothing returns boolean
return GetSpellAbilityId() == AID
endfunction
//===========================================================================
private function Actions takes nothing returns nothing
local MyStruct data = MyStruct.create(GetTriggerUnit(), GetSpellTargetUnit(), GetUnitAbilityLevel(GetTriggerUnit(), AID))
endfunction
//===========================================================================
private function Init takes nothing returns nothing
//when the hero casts the spell
local trigger LightShieldTrg = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( LightShieldTrg, EVENT_PLAYER_UNIT_SPELL_EFFECT )
call TriggerAddCondition(LightShieldTrg, Condition(function Conditions))
call TriggerAddAction(LightShieldTrg, function Actions)
//when the hero takes damage
set LightShieldTrg = CreateTrigger( )
//PROBLEM !!! This takes a unit !! how do I make this without a dinamic trigger ?
// call TriggerRegisterUnitEvent (LightShieldTrg, targ, EVENT_UNIT_DAMAGED )
call TriggerAddCondition(LightShieldTrg, Condition(function onDamage))
call TriggerAddAction(LightShieldTrg, function PreventDamage)
set LightShieldTrg = null
endfunction
endscope[/code]
However I have a problem ... this event takes a unit !!!
I don't see a way to fix this without using dynamic triggers, but I know they are evil !
Please some one help me find a solution !
[jass=full code]
//Uses TimerUtils so far
scope LightShield initializer Init
globals
private constant integer AID = 'A001'
endglobals
private constant function Duration takes integer level returns real
return level * 20.
endfunction
private constant function DamageAbsorbed takes integer level returns real
return level * 100.
endfunction
//===========================================================================
private struct MyStruct
unit caster
unit target
integer level
timer dur
static method create takes unit caster, unit target, integer level returns MyStruct
local MyStruct data = MyStruct.allocate()
set data.caster = caster
set data.level = level
set data.target = target
set data.dur = NewTimer()
return data
endmethod
method onDestroy takes nothing returns nothing
call ReleaseTimer(.dur)
endmethod
endstruct
//===========================================================================
private function onDamage takes nothing returns boolean
return true
endfunction
//===========================================================================
private function PreventDamage takes nothing returns nothing
endfunction
//===========================================================================
private function Conditions takes nothing returns boolean
return GetSpellAbilityId() == AID
endfunction
//===========================================================================
private function Actions takes nothing returns nothing
local MyStruct data = MyStruct.create(GetTriggerUnit(), GetSpellTargetUnit(), GetUnitAbilityLevel(GetTriggerUnit(), AID))
endfunction
//===========================================================================
private function Init takes nothing returns nothing
//when the hero casts the spell
local trigger LightShieldTrg = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( LightShieldTrg, EVENT_PLAYER_UNIT_SPELL_EFFECT )
call TriggerAddCondition(LightShieldTrg, Condition(function Conditions))
call TriggerAddAction(LightShieldTrg, function Actions)
//when the hero takes damage
set LightShieldTrg = CreateTrigger( )
//PROBLEM !!! This takes a unit !! how do I make this without a dinamic trigger ?
// call TriggerRegisterUnitEvent (LightShieldTrg, targ, EVENT_UNIT_DAMAGED )
call TriggerAddCondition(LightShieldTrg, Condition(function onDamage))
call TriggerAddAction(LightShieldTrg, function PreventDamage)
set LightShieldTrg = null
endfunction
endscope[/code]