This Event happens between "A unit is attacked" and "A unit is damaged" - when the unit launches a projectile.
It can't be abused by spamming stop.
It can be used if you want an event to run before the unit deals damage to the target (for example: you have some unit that has 'special' attacks, and you want to pause the targets of the attack, until the shot reaches them, or you want to create a special effect on them, or you want to launche more than one attack, ect)
You need a configuarations trigger too.. Just set the Animation Damage Point value into the unit-type, that is going to use this event, into its hashtable.
- If the unit has some kind of attack speed bonus, or attack speed reduction - the event doesn't run when it should.
~May be fixed in future versions~
UPDATED:
1) Fixed the bug with the event not runing the 1-st time.
2) Made the event run only for units, that have been configured.
3) Instead of creating new timers for every attack - I'm just re-using 1 timer for each unit.
4) Removed leaks - started clearing the unit's hashtable upon its death. (I am clearing the unit's timer hashtable upon the unit's death too. I am doing this, so people may load the last attacked unit at any point)
It can't be abused by spamming stop.
It can be used if you want an event to run before the unit deals damage to the target (for example: you have some unit that has 'special' attacks, and you want to pause the targets of the attack, until the shot reaches them, or you want to create a special effect on them, or you want to launche more than one attack, ect)
JASS:
function EventReg takes nothing returns nothing
local timer t = GetExpiredTimer()
local integer id = GetHandleId(t)
set udg_Attacked = LoadUnitHandle(udg_Attack_Table, id, 'atkd')
set udg_Attacker = LoadUnitHandle(udg_Attack_Table, id, 'atkr')
set udg_Attack_Launched = 1.00
set udg_Attack_Launched = 0.00
set t = null
endfunction
function Delay takes nothing returns boolean
local integer tid = GetUnitTypeId(GetAttacker())
local integer uid = GetHandleId(GetAttacker())
local boolean configured = LoadBoolean(udg_Attack_Table, tid, 'conf')
local real del_time
local boolean b
local timer t
if configured then
set del_time = LoadReal(udg_Attack_Table, tid , 'dely')
set b = LoadBoolean(udg_Attack_Table, uid , 'bull')
if b then
set t = LoadTimerHandle(udg_Attack_Table, uid , 'time')
call TimerStart(t, del_time, false, function EventReg)
call SaveUnitHandle(udg_Attack_Table, GetHandleId(t), 'atkd', GetTriggerUnit())
else
set t = CreateTimer()
call TimerStart(t, del_time, false, function EventReg)
call SaveTimerHandle(udg_Attack_Table, uid, 'time', t)
call SaveBoolean(udg_Attack_Table, uid, 'bull', true)
call SaveUnitHandle(udg_Attack_Table, GetHandleId(t), 'atkr', GetAttacker())
call SaveUnitHandle(udg_Attack_Table, GetHandleId(t), 'atkd', GetTriggerUnit())
endif
set t = null
endif
return false
endfunction
function AttCancel takes nothing returns boolean
local boolean event_runs = LoadBoolean(udg_Attack_Table, GetUnitTypeId(GetTriggerUnit()), 'conf')
local boolean b
local timer t
if event_runs then
set b = LoadBoolean(udg_Attack_Table, GetHandleId(GetTriggerUnit()), 'bull')
if b then
set t = LoadTimerHandle(udg_Attack_Table, GetHandleId(GetTriggerUnit()), 'time')
call TimerStart(t , 0.00, false, null)
set t = null
call SaveBoolean(udg_Attack_Table, GetHandleId(GetTriggerUnit()), 'bull', false)
endif
endif
return false
endfunction
function UnitDied takes nothing returns boolean
local boolean ev_runs = LoadBoolean(udg_Attack_Table, GetUnitTypeId(GetTriggerUnit()), 'conf')
local boolean b
local timer t
if ev_runs then
set b = LoadBoolean(udg_Attack_Table, GetHandleId(GetTriggerUnit()), 'bull')
if b then
set t = LoadTimerHandle(udg_Attack_Table, GetHandleId(GetTriggerUnit()), 'time')
call FlushChildHashtable(udg_Attack_Table, GetHandleId(t))
call DestroyTimer(t)
set t = null
call FlushChildHashtable(udg_Attack_Table, GetHandleId(GetTriggerUnit()))
endif
endif
return false
endfunction
//===========================================================================
function InitTrig_Damage_Delay takes nothing returns nothing
local trigger t = CreateTrigger()
local trigger r = CreateTrigger()
set gg_trg_Damage_Delay = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_Damage_Delay, EVENT_PLAYER_UNIT_ATTACKED )
call TriggerAddCondition( gg_trg_Damage_Delay, Condition( function Delay ) )
call TriggerRegisterAnyUnitEventBJ( t, EVENT_PLAYER_UNIT_ISSUED_TARGET_ORDER )
call TriggerRegisterAnyUnitEventBJ( t, EVENT_PLAYER_UNIT_ISSUED_POINT_ORDER )
call TriggerRegisterAnyUnitEventBJ( t, EVENT_PLAYER_UNIT_ISSUED_ORDER )
call TriggerAddCondition( t, Condition( function AttCancel ))
call TriggerRegisterAnyUnitEventBJ( r , EVENT_PLAYER_UNIT_DEATH )
call TriggerAddCondition( r, Condition( function UnitDied ))
set t = null
set r = null
endfunction
-
Configurations
-
Events
- Map initialization
- Conditions
-
Actions
- Hashtable - Create a hashtable
- Set Attack_Table = (Last created hashtable)
- Set U_Type = Archer
- Custom script: call SaveReal(udg_Attack_Table, udg_U_Type, 'dely' , 0.720)
- Custom script: call SaveBoolean(udg_Attack_Table, udg_U_Type, 'conf' , true)
- Set U_Type = Rifleman
- Custom script: call SaveReal(udg_Attack_Table, udg_U_Type, 'dely' , 0.170)
- Custom script: call SaveBoolean(udg_Attack_Table, udg_U_Type, 'conf' , true)
-
Events
- If the unit has some kind of attack speed bonus, or attack speed reduction - the event doesn't run when it should.
~May be fixed in future versions~
UPDATED:
1) Fixed the bug with the event not runing the 1-st time.
2) Made the event run only for units, that have been configured.
3) Instead of creating new timers for every attack - I'm just re-using 1 timer for each unit.
4) Removed leaks - started clearing the unit's hashtable upon its death. (I am clearing the unit's timer hashtable upon the unit's death too. I am doing this, so people may load the last attacked unit at any point)
Last edited: