library Pull initializer OnInit
globals
private constant real spellDamage = 150
private constant boolean multiplyDamage = true // if true, it will use this math:
// damage * level of ability = damage dealt.
// if false, damage will stay as it is.
private constant real kbSpeed = 17
private constant boolean changeSpeed = false // if true, it will use this math:
private constant real speedChanged = 4.5
// distance + (level of ability * speedchanged) = distance traveled by the target.
private constant boolean multiplySpeed = true // if true, it will use this math:
// distance * level of ability = distance traveled by the target.
private unit array caster
private unit array target
private real array damage
private real array distance
private integer maxCount = 0
private integer newCount = 0
private integer lc = 0
endglobals
private function OnLoop takes nothing returns nothing
local unit u = null
local unit t = null
local real x = 0
local real y = 0
local real x2 = 0
local real y2 = 0
local real x3 = 0
local real y3 = 0
local real dis = 0
local real dam = 0
local real ang = 0
if maxCount > 0 then
set lc = 0
loop
set lc = lc + 1
set u = caster[lc]
set t = target[lc]
set x = GetUnitX(u)
set y = GetUnitY(u)
set x2 = GetUnitX(t)
set y2 = GetUnitY(t)
set dis = distance[lc]
set dam = damage[lc]
if DistanceBetweenPoints(Location(x2, y2), Location(x, y)) > 30 then
set ang = Atan2(y - y2, x - x2)
set x3 = x2 + dis * Cos (ang)
set y3 = y2 + dis * Sin (ang)
call SetUnitX(t, x3)
call SetUnitY(t, y3)
else
call PauseUnit(t, false)
call UnitDamageTarget(u, t, dam, false, false, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_NORMAL, WEAPON_TYPE_WHOKNOWS)
set distance[lc] = 0
set damage[lc] = 0
set caster[lc] = null
set target[lc] = null
set newCount = newCount - 1
if newCount == 0 then
set maxCount = 0
set newCount = 0
set lc = 0
endif
endif
exitwhen lc == maxCount
endloop
endif
endfunction
private function OnCast takes nothing returns nothing
set maxCount = maxCount + 1
set newCount = newCount + 1
set caster[maxCount] = GetTriggerUnit()
set target[maxCount] = GetSpellTargetUnit()
call PauseUnit(target[maxCount], true)
if multiplyDamage == true then
set damage[maxCount] = spellDamage * GetUnitAbilityLevel(caster[maxCount], 'A005')
else
set damage[maxCount] = spellDamage
endif
if changeSpeed == true and multiplySpeed == true then
call BJDebugMsg("|c00FF0000[Error]|r |c0000FF00 you must NOT put both changeSpeed, and multipleSpeed to true, cuz its impossible!|r")
elseif changeSpeed == true then
set distance[maxCount] = kbSpeed + (GetUnitAbilityLevel(caster[maxCount], 'A000') * speedChanged)
elseif multiplySpeed == true then
set distance[maxCount] = kbSpeed * GetUnitAbilityLevel(caster[maxCount], 'A000')
elseif multiplySpeed == false and changeSpeed == false then
set distance[maxCount] = kbSpeed
endif
endfunction
private function OnCond takes nothing returns boolean
return GetSpellAbilityId() == 'A000'
endfunction
private function OnInit takes nothing returns nothing
local trigger DM = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(DM, EVENT_PLAYER_UNIT_SPELL_EFFECT)
call TriggerAddCondition(DM, Condition(function OnCond))
call TriggerAddAction(DM, function OnCast)
call TimerStart(CreateTimer(), 0.032, true, function OnLoop)
set DM = null
endfunction
endlibrary