I'm working on a simple damage detection system, and I didn't want to use any caches or arrays to remove the event leaks (not even sure if this system removes the leaks)
Anyway, for a spell portion of the system, I'm using a from of life-steal, except this one drains +12% rather than just heal 12%
So I needed to use the UnitDamageTarget() function, but for some reason my WC keeps bugging out, but when I "//" that function line it works fine
Here is the full code
Anyway, for a spell portion of the system, I'm using a from of life-steal, except this one drains +12% rather than just heal 12%
So I needed to use the UnitDamageTarget() function, but for some reason my WC keeps bugging out, but when I "//" that function line it works fine
Here is the full code
JASS:
function Vampyre takes unit damager, unit target, real damage returns nothing
local real currentlife = GetUnitState(damager, UNIT_STATE_LIFE)
local real drain = damage * .12
local real newlife = currentlife + drain
local real x = GetUnitX(damager)
local real y = GetUnitY(damager)
local effect heal = AddSpecialEffect("Abilities\\Spells\\Human\\Heal\\HealTarget.mdl", x, y)
call SetUnitState(damager, UNIT_STATE_LIFE, newlife )
call UnitDamageTarget( damager, target, drain, true, false, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_NORMAL, WEAPON_TYPE_WHOKNOWS)
call TriggerSleepAction(1)
call DestroyEffect(heal)
set heal = null
endfunction
function RunDamageBasedActions takes nothing returns nothing
local unit damager = GetEventDamageSource()
local unit target = GetTriggerUnit()
local real damage = GetEventDamage()
if (GetUnitAbilityLevel( damager, 'A000') > 0) == true then
call Vampyre(damager, target, damage)
endif
set damager = null
set target = null
endfunction
function AddUnits takes nothing returns nothing
local unit u = GetTriggerUnit()
call GroupAddUnit(udg_LivingUnits, u)
call TriggerRegisterUnitEvent(udg_trgDamageDetection, u, EVENT_UNIT_DAMAGED)
set u = null
endfunction
function RemoveUnits takes nothing returns nothing
local unit u = GetTriggerUnit()
call GroupRemoveUnit(udg_LivingUnits, u)
set udg_EventLeakCounter = udg_EventLeakCounter + 1
set u = null
if udg_EventLeakCounter > 10 then
call DestroyTrigger(udg_trgDamageDetection)
set udg_trgDamageDetection = CreateTrigger()
call TriggerAddAction(udg_trgDamageDetection, function RunDamageBasedActions)
loop
set u = FirstOfGroup(udg_LivingUnits)
exitwhen u == null
call GroupRemoveUnit(udg_LivingUnits, u)
call TriggerRegisterUnitEvent(udg_trgDamageDetection, u, EVENT_UNIT_DAMAGED)
endloop
call GroupEnumUnitsInRect(udg_LivingUnits,GetWorldBounds(),null)
endif
endfunction
function InitTrig_Damage_Detection takes nothing returns nothing
local integer i = 0
local unit u
local region entiremap = CreateRegion()
local rect worldbounds = GetWorldBounds()
//Game Setup
set udg_trgAddUnits = CreateTrigger()
set udg_trgRemoveUnits = CreateTrigger()
set udg_trgDamageDetection = CreateTrigger()
call RegionAddRect(entiremap, worldbounds)
call GroupEnumUnitsInRect(udg_LivingUnits,worldbounds,null)
loop
set u = FirstOfGroup(udg_LivingUnits)
exitwhen u == null
call GroupRemoveUnit(udg_LivingUnits, u)
call TriggerRegisterUnitEvent(udg_trgDamageDetection, u, EVENT_UNIT_DAMAGED)
endloop
call GroupEnumUnitsInRect(udg_LivingUnits,worldbounds,null)
// Add Actions
call TriggerAddAction(udg_trgAddUnits, function AddUnits)
call TriggerAddAction(udg_trgRemoveUnits, function RemoveUnits)
call TriggerAddAction(udg_trgDamageDetection, function RunDamageBasedActions)
//Add Events
call TriggerRegisterEnterRegion(udg_trgAddUnits, entiremap ,null)
loop
exitwhen i > 15
call TriggerRegisterPlayerUnitEvent(udg_trgRemoveUnits,Player(i), EVENT_PLAYER_UNIT_DEATH,null)
set i = i + 1
endloop
endfunction