xNS
X
xNS
I need an ability or trigger to make all units or even just heroes receive 50% damage from friendly units.
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
50% Damage from Allies

Events


Unit - A unit is attacked

Conditions


(Attacked unit = ally of attacking unit)

Actions


Unit - Heal (Attacked unit) for (0.5 x (Damage Taken)) hit points.
Map Initialization

Events


Map initialization

Conditions

Actions


Set DD_Sys_Group = (Units in (Playable map area))


Unit Group - Pick every unit in DD_Sys_Group and do (Actions)



Loop - Actions




Trigger - Add to Ally Damage Reduction <gen> the event (Unit - (Picked unit) Takes damage)


Custom script: call DestroyGroup (udg_DD_Sys_Group)
Damage Detection Add Unit

Events


Unit - A unit enters (Playable map area)

Conditions

Actions


Trigger - Add to Ally Damage Reduction <gen> the event (Unit - (Triggering unit) Takes damage)
Ally Damage Reduction

Events

Conditions

Actions


If (All Conditions are True) then do (Then Actions) else do (Else Actions)



If - Conditions




((Damage source) belongs to an ally of (Owner of (Triggering unit))) Equal to True



Then - Actions




Unit - Set life of (Triggering unit) to ((Life of (Triggering unit)) + ((Damage taken) x 0.50))



Else - Actions
Ally Damage Reduction

Events

Conditions

Actions


If (All Conditions are True) then do (Then Actions) else do (Else Actions)



If - Conditions




((Damage source) belongs to an ally of (Owner of (Triggering unit))) Equal to True



Then - Actions




Wait 0.01 seconds




Unit - Set life of (Triggering unit) to ((Life of (Triggering unit)) + ((Damage taken) x 0.50))



Else - Actions
function Dmg_Reset takes nothing returns nothing
call UnitRemoveAbility(udg_Dmg_Target, 'AIl2')//+300 Hp Greater Life Bonus
call SetUnitState(udg_Dmg_Target, UNIT_STATE_LIFE, udg_Dmg_Life)
set udg_Dmg_Taken = 0.00//Set Dmg Taken to 0 so the trigger knows that unit got healed already
endfunction
function DmgEvent_Actions takes nothing returns nothing
if udg_Dmg_Taken != 0.00 then//If timer did not run yet the unit will be healed
call UnitRemoveAbility(udg_Dmg_Target, 'AIl2')
call SetUnitState(udg_Dmg_Target, UNIT_STATE_LIFE, udg_Dmg_Life)
endif
set udg_Dmg_Target = GetTriggerUnit()
set udg_Dmg_Source = GetEventDamageSource()
set udg_Dmg_Taken = GetEventDamage()
set udg_Dmg_Life = GetUnitState(udg_Dmg_Target, UNIT_STATE_LIFE)
call UnitAddAbility(udg_Dmg_Target, 'AIl2')
call SetUnitState(udg_Dmg_Target, UNIT_STATE_LIFE, udg_Dmg_Life+300.00)
call TimerStart(udg_Dmg_Timer, 0.00, false, function Dmg_Reset)//Start timer to heal
endfunction
//Might be even better with a condition to check if the timer and ability is really necessary
//And there might be a bug but I didn't test yet:
//1. Unit is healed before timer is over
//2. Unit takes damage again
//3. Unit is healed again
//If this is possible to happen it would only matter for x times damage absorption and could be prevented with another if anyway
//However the advantage of all this stuff is that one does not need a hashtable to check things
//Create events (only leaks once per unit, if you got enough units to notice the leak you got bigger problems)
function AddEnter_Actions takes nothing returns nothing
call TriggerRegisterUnitEvent(gg_trg_DmgEvent, GetTriggerUnit(), EVENT_UNIT_DAMAGED)
endfunction
function DmgEvent_Add takes nothing returns nothing
call TriggerRegisterUnitEvent(gg_trg_DmgEvent, GetEnumUnit(), EVENT_UNIT_DAMAGED)
endfunction
function InitTrig_DmgEvent takes nothing returns nothing
local trigger AddEnter = CreateTrigger()
set gg_trg_DmgEvent = CreateTrigger()
call TriggerAddAction(AddEnter, function AddEnter_Actions)
call TriggerAddAction(gg_trg_DmgEvent, function DmgEvent_Actions)
call TriggerRegisterEnterRectSimple(AddEnter, bj_mapInitialPlayableArea)
call GroupEnumUnitsInRect(udg_g, bj_mapInitialPlayableArea, null)
call ForGroup(udg_g, function DmgEvent_Add)
endfunction
Yes, I meant something like cboy123, but, that trigger will not work properly. If you have full hp and you receive damage, the healing part won't be done. Your life will never go full, if you get attacked. This is why you need a timer that will expire in 0.00 seconds.
