struct shielddata
trigger t = CreateTrigger()
triggeraction taction
real shieldmaxlife = 100.00
real shieldlife = 100.00
method onDestroy takes nothing returns nothing
call TriggerRemoveAction( .t, .taction )
call DestroyTrigger( .t )
endmethod
endstruct
globals
group shieldgroup = CreateGroup()
endglobals
function Shield_Damage takes nothing returns nothing
local unit target = GetTriggerUnit()
local shielddata data = GetUnitUserData( target )
local real damage = GetEventDamage()
local real life = GetWidgetLife( target )
local real maxlife = GetUnitState( target, UNIT_STATE_MAX_LIFE )
local real lifeback
if ( life < 0.405 ) then
//unit is dead, we destroy shield and trigger and don't worry about it anymore
call data.destroy()
call GroupRemoveUnit( shieldgroup, target )
return
endif
if ( data.shieldlife - damage <= 0.00 ) then
//shield is dead because it took too much damage, we manipulate life given back to match shield's remaining life before it "died"
set lifeback = data.shieldlife
call data.destroy()
call GroupRemoveUnit( shieldgroup, target )
else
//shield is still alive, so all damage is blocked
set lifeback = damage
endif
if ( life + lifeback >= maxlife ) then
call SetWidgetLife( target, maxlife )
else
call SetWidgetLife( target, life + lifeback )
endif
set target = null
endfunction
function Trig_Shield_Spell_Conditions takes nothing returns boolean
return ( GetSpellAbilityId == 'A000' ) //change rawcode to match one in your map
endfunction
function Trig_Shield_Spell_Actions takes nothing returns nothing
//this is your trigger action for the trigger that detects spell cast
local shielddata data
local unit target = GetSpellTargetUnit()
if ( IsUnitInGroup( target, shieldgroup ) ) then
//unit already has shield, so we simply add to shield's life and max life
set data = GetUnitUserData( target )
set data.shieldmaxlife = data.shieldmaxlife + 100.00
set data.shieldlife = data.shieldlife + 100.00
else
//unit doesn't have shield, so we create one
set data = shielddata.create()
call TriggerRegisterUnitEvent( data.t, target, EVENT_UNIT_DAMAGED )
call TriggerRegisterUnitEvent( data.t, target, EVENT_UNIT_DEATH )
set data.taction = TriggerAddAction( data.t, function Shield_Damage )
call SetUnitUserData( target, data )
call GroupAddUnit( shieldgroup, target )
endif
set target = null
endfunction
function InitTrig_Shield_Spell takes nothing returns nothing
local integer i = 0
set gg_trg_Shield_Spell = CreateTrigger()
loop
exitwhen( i > 11 )
call TriggerRegisterPlayerUnitEvent( gg_trg_Shield_Spell, Player(i), EVENT_UNIT_SPELL_EFFECT, null )
set i = i + 1
endloop
call TriggerAddCondition( gg_trg_Shield_Spell, Condition ( function Trig_Shield_Spell_Conditions ) )
call TriggerAddAction( gg_trg_Shield_Spell, function Trig_Shield_Spell_Actions )
endfunction