function WillOfTheBodyguard_Guardfilter takes nothing returns boolean
return GetUnitTypeId(GetFilterUnit()) == <- BodyguardId -> and GetUnitOwner(GetFilterUnit()) == GetUnitOwner(GetTriggerUnit())
endfunction
function WillOfTheBodyguard_Actions takes nothing returns nothing
local filterfunc guardfilter = Filter(function WillOfTheBodyguard_Guardfilter)
local unit bodyguard
local unit hero = GetTriggerUnit()
local real heroX = GetUnitX(hero)
local real heroY = GetUnitY(hero)
local rect minDistance = Rect(heroX - 100,heroY - 100,heroX + 100,heroY + 100)
local group bodyguards = CreateGroup()
call GroupEnumUnitsInRect(bodyguards,minDistance,guardfilter)
set bodyguard = GroupPickRandomUnit(bodyguards)
if bodyguard != null then
if GetRandomInt(0,100) <= 30 then
call SetUnitState(bodyguard,UNIT_STATE_LIFE,RMaxBJ(0,GetUnitState(bodyguard,UNIT_STATE_LIFE) - GetEventDamage()))
call SetUnitState(hero,UNIT_STATE_LIFE,GetUnitState(hero,UNIT_STATE_LIFE) + GetEventDamage())
endif
endif
call DestroyFilter(guardfilter)
call RemoveRect(minDistance)
set guardfilter = null
set bodyguard = null
set hero = null
set minDistance = null
endfunction
function InitTrig_WillOfTheBodyguard takes nothing returns nothing
set gg_trg_WillOfTheBodyguard = CreateTrigger()
call TriggerRegisterUnitEvent(gg_trg_WillOfTheBodyguard, <- Hero Unit -> ,EVENT_UNIT_DAMAGED)
call TriggerAddAction(gg_trg_WillOfTheBodyguard,function WillOfTheBodyguard_Actions)
endfunction