- Joined
- Jun 21, 2012
- Messages
- 431
JASS:
library LifeSteal/*
*******************************************************************************************************
*
* ***************************************************************************************************
* */ uses /*
* */ ANY DamageEvent /*
* */ ANY UnitIndexer /*
* ***************************************************************************************************
*
* LifeSteal
* ¯¯¯¯¯¯¯¯¯
* v0.1.1.1
* by Trigger edge
*
* Add custom life steal for all attack types.
*
* API:
* ¯¯¯
* struct LifeSteal extends array
* public string positiveFx
* public string negativeFx
* public boolean block
*
* static method operator [] takes unit u returns thistype
* method operator percent takes nothing returns real
* method operator percent= takes real r returns nothing
*
*******************************************************************************************************/
//CONFIGURATION
//=================================================================================
globals
private constant string DEFAULT_FX = "Abilities\\Spells\\Undead\\VampiricAura\\VampiricAuraTarget.mdl"
endglobals
//=================================================================================
globals
private timer delayTimer=CreateTimer()
private group stack=CreateGroup()
endglobals
struct LifeSteal extends array
private real unitPercent
private real amount
public string positiveFx
public string negativeFx
public boolean block
static method operator [] takes unit u returns thistype
return GetUnitId(u)
endmethod
method operator percent takes nothing returns real
return .unitPercent
endmethod
method operator percent= takes real r returns nothing
set .unitPercent=.unitPercent+r
endmethod
private static method beforeDmg takes nothing returns nothing
local thistype this=0
local unit u=null
loop
set u=FirstOfGroup(stack)
exitwhen(null==u)
call GroupRemoveUnit(stack,u)
set this=GetUnitId(u)
if(not .block)then
if(0<.amount)then
if(null==.positiveFx)then
set .positiveFx=DEFAULT_FX
endif
call DestroyEffect(AddSpecialEffectTarget(.positiveFx,u,"chest"))
else
if(null==.negativeFx)then
set .negativeFx=DEFAULT_FX
endif
call DestroyEffect(AddSpecialEffectTarget(.negativeFx,u,"chest"))
endif
call SetWidgetLife(u,.amount+GetWidgetLife(u))
set .amount=0
else
set .block=false
endif
endloop
endmethod
private static method onHit takes nothing returns nothing
local thistype this=Damage.sourceId
if(0!=.percent)then
set .amount=.amount+(Damage.amount*.percent/100)
call GroupAddUnit(stack,Damage.source)
call TimerStart(delayTimer,0,false,function thistype.beforeDmg)
endif
endmethod
private static method onInit takes nothing returns nothing
call RegisterDamageEvent(function thistype.onHit)
endmethod
endstruct
endlibrary
You need config the onInit method for your Damage Event snippet:
JASS:
private static method onInit takes nothing returns nothing
call RegisterDamageEvent(function thistype.onHit)
endmethod