I would like to make a passive ability that similar to vampiric ability but make the hero gain some mp when hits the enemy
In the CandyWar map, Blizzard gives the warriors such an ability. However, it has a small bug that you can still gain mp when stop the action before hits, though there's a 0.9 second cooldown
I use a unit damage event to eliminate this bug, but I thought it is wasteful to register every unit a damage event. And then I write a new method (maybe just new for me)
So I just dynamically create trigger for the target unit. But I don't know the cost of creating new triggers and destroying them after. Does my method really save computational resource or just do the reverse
In the CandyWar map, Blizzard gives the warriors such an ability. However, it has a small bug that you can still gain mp when stop the action before hits, though there's a 0.9 second cooldown
I use a unit damage event to eliminate this bug, but I thought it is wasteful to register every unit a damage event. And then I write a new method (maybe just new for me)
JASS:
//condition for attack event
function Trig_Battlesoul_Conditions takes nothing returns boolean
return (GetUnitAbilityLevel(GetAttacker(), 'A60A')>0) and (not IsUnitType(GetTriggerUnit(), UNIT_TYPE_MECHANICAL)) and (not IsUnitType(GetTriggerUnit(), UNIT_TYPE_STRUCTURE)) and (IsUnitEnemy(GetTriggerUnit(), GetOwningPlayer(GetAttacker())))
endfunction
//condition for damage event
function Trig_Battlesoul_Hit_Conditions takes nothing returns boolean
return (GetUnitAbilityLevel(GetEventDamageSource(), 'A60A') > 0)
endfunction
//action for damage event that grants the attacker some mp
function Trig_Battlesoul_Hit_Actions takes nothing returns nothing
call SetUnitManaBJ(GetEventDamageSource(), ( GetUnitState( GetEventDamageSource(), UNIT_STATE_MANA) + ( 45.00 + ( 10.00 * I2R(GetUnitAbilityLevelSwapped('A60A', GetEventDamageSource())) ) ) ) )
call DisableTrigger(GetTriggeringTrigger())
call DestroyTrigger(GetTriggeringTrigger())
endfunction
//action for attack event, which dynamically creates a temporate damage event trigger
function Trig_Battlesoul_Actions takes nothing returns nothing
local trigger udg_trg = CreateTrigger()
local unit udg_target = GetTriggerUnit()
call TriggerRegisterUnitEvent(udg_trg, udg_target, EVENT_UNIT_DAMAGED)
call TriggerAddCondition(udg_trg, Condition(function Trig_Battlesoul_Hit_Conditions))
call TriggerAddAction(udg_trg, function Trig_Battlesoul_Hit_Actions)
call EnableTrigger(udg_trg)
call TriggerSleepAction(5)
call DisableTrigger(udg_trg)
call DestroyTrigger(udg_trg)
set udg_trg = null
endfunction
//===========================================================================
function InitTrig_Battlesoul takes nothing returns nothing
set gg_trg_Battlesoul = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ( gg_trg_Battlesoul, EVENT_PLAYER_UNIT_ATTACKED)
call TriggerAddCondition(gg_trg_Battlesoul, Condition(function Trig_Battlesoul_Conditions))
call TriggerAddAction(gg_trg_Battlesoul, function Trig_Battlesoul_Actions)
endfunction
So I just dynamically create trigger for the target unit. But I don't know the cost of creating new triggers and destroying them after. Does my method really save computational resource or just do the reverse