scope Sample initializer GetStarted
globals
private constant rect TriggerRect = gg_rct_Enter
private constant string Effect = "Abilities\\Weapons\\AncientProtectorMissile\\AncientProtectorMissile.mdl"
private constant real Offset = 300
private constant real Speed = 5
endglobals
//*****************End of the Settings*********************
globals
private integer i = 0
private real x
private real y
private region TriggerRegion = CreateRegion()
endglobals
//!***********************************
// Polar Projection Function
// call PolarProjection (x, y, distance, angle)
private function PolarProjection takes real rx, real ry, real dist, real angle returns nothing
set x = rx + dist * Cos(angle * bj_DEGTORAD)
set y = ry + dist * Sin(angle * bj_DEGTORAD)
endfunction
//!***********************************
// Get Angle Function
// call GetAngle (x1,y1,x2,y2)
private function GetAngle takes real x1, real y1, real x2, real y2 returns real
return bj_RADTODEG*Atan2(y2-y1,x2-x1)
endfunction
//!***********************************
// Main Part
private struct Spell
private unit u
private real ReachedDistance
private static Spell array indx
private static integer counter = 0
private static timer time = CreateTimer()
static method Execution takes nothing returns nothing
local Spell d
set i = 0
loop
exitwhen i >= Spell.counter
set d = Spell.indx[i]
if d.ReachedDistance < Offset then
call PolarProjection(GetUnitX(d.u),GetUnitY(d.u),Speed,GetAngle(GetRectCenterX(TriggerRect),GetRectCenterY(TriggerRect),GetUnitX(d.u),GetUnitY(d.u)))
call SetUnitX(d.u,x)
call SetUnitY(d.u,y)
call DestroyEffect(AddSpecialEffect(Effect,x,y))
set d.ReachedDistance = d.ReachedDistance + Speed
else
set d.u = null
call d.destroy()
set Spell.counter = Spell.counter - 1
set Spell.indx[i] = d.indx[Spell.counter]
set i = i - 1
endif
set i = i + 1
endloop
set i = 0
if Spell.counter == 0 then
call PauseTimer(Spell.time)
endif
endmethod
static method GetValues takes unit u returns nothing
local Spell d = Spell.allocate()
set d.u = u
set d.ReachedDistance = 0
if Spell.counter == 0 then
call TimerStart(Spell.time,0.01,true, function Spell.Execution)
endif
set Spell.indx[Spell.counter] = d
set Spell.counter = Spell.counter + 1
endmethod
endstruct
private function Input takes nothing returns nothing
call Spell.GetValues(GetTriggerUnit())
endfunction
private function GetStarted takes nothing returns nothing
local trigger Trig = CreateTrigger()
call RegionAddRect(TriggerRegion,TriggerRect)
call TriggerRegisterEnterRegion(Trig,TriggerRegion,null)
call TriggerAddAction(Trig, function Input)
call Preload(Effect)
call PreloadStart()
endfunction
endscope