globals
hashtable MissileHash = InitHashtable()
real MissileSpeed = 6 // This is 200 * 0.03
real MissileAcceleration = 0.15 // This is 5 * 0.03
integer MissileAbilityId = 'AUan' // Place the ID Of the Missile Cast Ability
integer MissileId = 'hfoo' // Place the ID of the Missile Unit
endglobals
// No need to touch this. This is to clear the Missile data when target dies or missile reaches target
function ClearMissile takes unit missile, integer missileId, timer t returns nothing
call KillUnit(missile)
call PauseTimer(t)
call DestroyTimer(t)
call FlushChildHashtable(MissileHash, missileId)
endfunction
// These is basically the Missile Movement every 0.03 checking distance between missile and target.
// No damage nor stun has been added. There are comments where Damage and Stun should be, add them yourself.
function MissileTimerFunc takes nothing returns nothing
local timer t = GetExpiredTimer() // Timer
local integer i = GetHandleId(t) // Timer ID
local unit tg = LoadUnitHandle(MissileHash, i, 1) // Target
local real counter = LoadReal(MissileHash, i, 2)
local unit u // Missile
local real facing // Missile Facing
local real ux // Missile X
local real uy // Missile Y
local real tx // Target X
local real ty // Target Y
local real x // Offset Required
local real y // offset Required
local real dx // Distance Required
local real dy // Distance Required
local real accel // Acceleration
local real angle // Offset Angle
local real speed // Missile Speed
local real distance // Distance
if GetWidgetLife(tg) > 0 then // If Target is alive
set u = LoadUnitHandle(MissileHash, i, 0)
set tx = GetUnitX(tg)
set ty = GetUnitY(tg)
set ux = GetUnitX(u)
set uy = GetUnitY(u)
set facing = 57.29 * Atan2(ty-uy, tx-ux)
call SetUnitFacing(u, facing) // Make Missile Face Target
if counter > 2 then // After 2 seconds
set accel = LoadReal(MissileHash, i, 3) + MissileAcceleration // Increase Acceleration by 0.15 every 0.03 secs.
call SaveReal(MissileHash, i, 3, accel)
set speed = MissileSpeed+accel // Speed + Acceleration
set angle = facing * 0.01745
set x = ux + speed * Cos(angle)
set y = uy + speed * Sin(angle)
call SetUnitX(u, x) // Move Missile Towards Target
call SetUnitY(u, y) // Move Missile Towards Target
set dx = tx-x
set dy = ty-y
set distance = SquareRoot(dx*dx + dy*dy)
if distance <= 16 then
// Stun the Target
// Deal Damage
call ClearMissile(u, i, t)
endif
else
call SaveReal(MissileHash, i, 2, counter + 0.03) // Increase Counter if it's lower than 2
endif
else
call ClearMissile(u, i, t)
endif
endfunction
// This happens when you cast the ability.
function Trig_MissileCast_Actions takes nothing returns boolean
local unit u
local unit m
local timer t
local integer i
local unit tg
if GetSpellAbilityId() == MissileAbilityId then
set u = GetTriggerUnit()
set tg = GetSpellTargetUnit()
set m = CreateUnit(GetTriggerPlayer(), MissileId, GetUnitX(u), GetUnitY(u), 57.29 * Atan2(GetUnitY(tg)-GetUnitY(u), GetUnitX(tg)-GetUnitX(u))) // Missile Creation
set t = CreateTimer()
set i = GetHandleId(t)
call SaveUnitHandle(MissileHash, i, 0, m)
call SaveUnitHandle(MissileHash, i, 1, tg)
call TimerStart(t, 0.03, true, function MissileTimerFunc)
set t = null
set u = null
set m = null
endif
return FALSE
endfunction
//===========================================================================
function InitTrig_Missile_Cast takes nothing returns nothing
set gg_trg_Missile_Cast = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_Missile_Cast, EVENT_PLAYER_UNIT_SPELL_EFFECT )
call TriggerAddCondition( gg_trg_Missile_Cast, Condition( function Trig_MissileCast_Actions ) )
endfunction