My spell is Death Coil that cause damage and fear effect to the enemy target. There are 33% chance that debuff will be removed if target takes damage.
It's work well on first cast, but if I cast it on the same target. It will often cause no damage and debuff. :S
It's work well on first cast, but if I cast it on the same target. It will often cause no damage and debuff. :S
JASS:
scope deathcoil initializer Deathcoil_Init
function Trig_Death_Coil_Conditions takes nothing returns boolean
return GetSpellAbilityId() == 039;A00R039;
endfunction
function Break_Fear takes nothing returns nothing
local unit c = GetTriggerUnit()
local integer i
set i = GetRandomInt(1, 100)
if i <= 33 and UnitHasBuffBJ(c, 039;B00J039;) then
call UnitRemoveBuffBJ(039;B00J039;, c)
set c = null
endif
endfunction
function Trig_Death_Coil_Actions takes nothing returns nothing
local unit c = GetSpellAbilityUnit()
local unit a = GetSpellTargetUnit()
local location r = GetUnitLoc(a)
local rect t = RectFromCenterSizeBJ(r, 1000, 1000)
local trigger trg
local real DC
local location l
local real e = 0
set DC = I2R( (GetUnitAbilityLevelSwapped(039;A00R039;, c)*50) + 50 )
loop
exitwhen UnitHasBuffBJ(a, 039;B00J039;) == true or e > 8.0
set e = e + 0.1
call TriggerSleepAction(0.1)
endloop
call UnitDamageTargetBJ( c, a, DC, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_MAGIC )
set trg = CreateTrigger()
call TriggerRegisterUnitEvent( trg, a, EVENT_UNIT_DAMAGED )
call TriggerAddAction( trg, function Break_Fear )
loop
exitwhen UnitHasBuffBJ(a, 039;B00J039;) == false
set l = GetRandomLocInRect(t)
call IssuePointOrderLoc(a, "move", l)
call TriggerSleepAction(0.27)
set l = null
endloop
set a = null
call RemoveLocation(l)
endfunction
//===========================================================================
function Deathcoil_Init takes nothing returns nothing
set gg_trg_Death_Coil = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_Death_Coil, EVENT_PLAYER_UNIT_SPELL_EFFECT )
call TriggerAddCondition( gg_trg_Death_Coil, Condition( function Trig_Death_Coil_Conditions ) )
call TriggerAddAction( gg_trg_Death_Coil, function Trig_Death_Coil_Actions )
endfunction
endscope