- Joined
- Sep 21, 2007

- Messages
- 517

JASS:

```
library KBSystem initializer Init
globals
private constant real KBSpeed = 10 //every interval
private constant real interval = .03
private constant real distance = 333
private constant real ParabolaHeight = 150
private constant string SFX = "Objects\\Spawnmodels\\Undead\\ImpaleTargetDust\\ImpaleTargetDust.mdl"
private timer KBTimer = CreateTimer()
// for struct
private KB array KBContainer
private KB dat
private integer KBLoop = 0
private integer KBTotal = 0
// Z
private location ZLoc = Location(0,0)
private real LocZ = 0
endglobals
struct KB
unit u = null
real x = 0.
real y = 0.
real dx = 0.
real dy = 0.
real CurDist = 0.
real z1 = 0.
method onDestroy takes nothing returns nothing
set .u = null
if KBTotal == 0 then
call PauseTimer(KBTimer)
endif
endmethod
static method LocZ takes nothing returns real
call MoveLocation(ZLoc, dat.x, dat.y)
return GetLocationZ(ZLoc)
endmethod
static method ParabolaZ takes nothing returns real
return (4 * ParabolaHeight / distance) * (distance - dat.CurDist) * (dat.CurDist / distance)
endmethod
static method MoveX takes real a returns real
return Cos(a)*KBSpeed
endmethod
static method FlyZ takes nothing returns real
return GetUnitFlyHeight(dat.u)
endmethod
static method MoveY takes real a returns real
return Sin(a)*KBSpeed
endmethod
//***** Finish Movement Methods *************************************
static method KnockingBackUnits takes nothing returns nothing
set KBLoop = 0
loop
exitwhen KBLoop >= KBTotal
set dat = KBContainer[KBLoop]
set dat.x = dat.x + dat.dx
set dat.y = dat.y + dat.dy
set dat.CurDist = dat.CurDist + KBSpeed
call SetUnitFlyHeight(dat.u, (KB.ParabolaZ()+dat.z1) - KB.LocZ(), 0)
if not( IsTerrainPathable(dat.x, dat.y, PATHING_TYPE_FLYABILITY) ) or KB.FlyZ() < 1 then
call SetUnitPosition(dat.u, dat.x, dat.y)
else
call SetUnitFlyHeight(dat.u, 0, 0)
call SetUnitPathing(dat.u, true)
set KBTotal = KBTotal - 1
set KBContainer[KBLoop] = KBContainer[KBTotal]
set udg_KBOn[GetUnitUserData(dat.u)] = false
call dat.destroy()
endif
set KBLoop = KBLoop + 1
endloop
endmethod
static method SetUp2 takes unit KBUnit, real angle returns KB
set dat = KB.allocate()
set KBContainer[KBTotal] = dat
set dat.u = KBUnit
set dat.x = GetUnitX(dat.u)
set dat.y = GetUnitY(dat.u)
call DestroyEffect( AddSpecialEffectTarget(SFX, dat.u, "origin") )
set dat.dx = KB.MoveX(angle)
set dat.dy = KB.MoveY(angle)
set dat.z1 = KB.LocZ()
call UnitAddAbility(dat.u, 'Amrf')
call UnitRemoveAbility(dat.u, 'Amrf')
call SetUnitPathing(dat.u, false)
call TimerStart(KBTimer, interval, true, function KB.KnockingBackUnits)
set KBTotal = KBTotal + 1
return dat
endmethod
static method SetUp takes unit KUnit, real Angle returns nothing
if udg_KBOn[GetUnitUserData(KUnit)] != true then
call KB.SetUp2(KUnit, Angle)
set udg_KBOn[GetUnitUserData(KUnit)] = true
endif
endmethod
endstruct
//-------------------------------------------------
private function Init takes nothing returns nothing
call Preload(SFX)
endfunction
endlibrary
```